00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00032
00033 #ifdef HAVE_CONFIG_H
00034 #include "autoconfig.h"
00035 #endif
00036
00037 #if defined(ATRAILERS)
00038
00039 #include "atrailers_content_handler.h"
00040 #include "online_service.h"
00041 #include "tools.h"
00042 #include "metadata_handler.h"
00043 #include "cds_objects.h"
00044 #include "config_manager.h"
00045
00046 using namespace zmm;
00047 using namespace mxml;
00048
00049 bool ATrailersContentHandler::setServiceContent(zmm::Ref<mxml::Element> service)
00050 {
00051 String temp;
00052
00053 if (service->getName() != "records")
00054 throw _Exception(_("Recieved invalid XML for Apple Trailers service"));
00055
00056 this->service_xml = service;
00057
00058 trailer_count = service_xml->childCount();
00059
00060 if (trailer_count == 0)
00061 return false;
00062
00063 current_trailer_index = 0;
00064
00065 Ref<Dictionary> mappings = ConfigManager::getInstance()->getDictionaryOption(CFG_IMPORT_MAPPINGS_EXTENSION_TO_MIMETYPE_LIST);
00066 trailer_mimetype = mappings->get(_("mov"));
00067 if (!string_ok(trailer_mimetype))
00068 trailer_mimetype = _("video/quicktime");
00069
00070 return true;
00071 }
00072
00073 Ref<CdsObject> ATrailersContentHandler::getNextObject()
00074 {
00075 String temp;
00076 struct timespec ts;
00077
00078 while (current_trailer_index < trailer_count)
00079 {
00080 Ref<Node> n = service_xml->getChild(current_trailer_index);
00081
00082 current_trailer_index++;
00083
00084 if (n == nil)
00085 return nil;
00086
00087 if (n->getType() != mxml_node_element)
00088 continue;
00089
00090 Ref<Element> trailer = RefCast(n, Element);
00091 if (trailer->getName() != "movieinfo")
00092 continue;
00093
00094
00095 Ref<CdsItemExternalURL> item(new CdsItemExternalURL());
00096 Ref<CdsResource> resource(new CdsResource(CH_DEFAULT));
00097 item->addResource(resource);
00098
00099 Ref<Element> info = trailer->getChildByName(_("info"));
00100 if (info == nil)
00101 continue;
00102
00103 temp = info->getChildText(_("title"));
00104 if (!string_ok(temp))
00105 item->setTitle(_("Unknown"));
00106 else
00107 item->setTitle(temp);
00108
00109 item->setMimeType(trailer_mimetype);
00110 resource->addAttribute(MetadataHandler::getResAttrName(R_PROTOCOLINFO), renderProtocolInfo(trailer_mimetype));
00111
00112 item->setAuxData(_(ONLINE_SERVICE_AUX_ID), String::from(OS_ATrailers));
00113
00114 temp = trailer->getAttribute(_("id"));
00115 if (!string_ok(temp))
00116 {
00117 log_warning("Failed to retrieve Trailer ID for \"%s\", "
00118 "skipping...\n", item->getTitle().c_str());
00119 continue;
00120 }
00121
00122 temp = String(OnlineService::getStoragePrefix(OS_ATrailers)) + temp;
00123 item->setServiceID(temp);
00124
00125 Ref<Element> preview = trailer->getChildByName(_("preview"));
00126 if (preview == nil)
00127 {
00128 log_warning("Failed to retrieve Trailer location for \"%s\", "
00129 "skipping...\n", item->getTitle().c_str());
00130 continue;
00131 }
00132
00133 temp = preview->getChildText(_("large"));
00134 if (string_ok(temp))
00135 {
00136
00137
00138
00139
00140
00141
00142
00143 temp = temp.replace(_("movies"), _("www"));
00144 item->setURL(temp);
00145 }
00146 else
00147 {
00148 log_error("Could not get location for Trailers item %s, "
00149 "skipping.\n", item->getTitle().c_str());
00150 continue;
00151 }
00152
00153 item->setClass(_("object.item.videoItem"));
00154
00155 temp = info->getChildText(_("rating"));
00156 if (string_ok(temp))
00157 item->setMetadata(MetadataHandler::getMetaFieldName(M_RATING),
00158 temp);
00159
00160 temp = info->getChildText(_("studio"));
00161 if (string_ok(temp))
00162 item->setMetadata(MetadataHandler::getMetaFieldName(M_PRODUCER),
00163 temp);
00164
00165 temp = info->getChildText(_("director"));
00166 if (string_ok(temp))
00167 item->setMetadata(MetadataHandler::getMetaFieldName(M_DIRECTOR),
00168 temp);
00169
00170 temp = info->getChildText(_("postdate"));
00171 if (string_ok(temp))
00172 item->setAuxData(_(ATRAILERS_AUXDATA_POST_DATE), temp);
00173
00174 temp = info->getChildText(_("releasedate"));
00175 if (string_ok(temp))
00176 item->setMetadata(MetadataHandler::getMetaFieldName(M_DATE),
00177 temp);
00178
00179 temp = info->getChildText(_("description"));
00180 if (string_ok(temp))
00181 {
00183 item->setMetadata(MetadataHandler::getMetaFieldName(M_LONGDESCRIPTION), temp);
00184 }
00185
00186 Ref<Element> cast = trailer->getChildByName(_("cast"));
00187 if (cast != nil)
00188 {
00189 String actors;
00190 for (int i = 0; i < cast->childCount(); i++)
00191 {
00192 Ref<Node> cn = cast->getChild(i);
00193 if (cn->getType() != mxml_node_element)
00194 continue;
00195
00196 Ref<Element> actor = RefCast(cn, Element);
00197 if (actor->getName() != "name")
00198 continue;
00199
00200 temp = actor->getText();
00201 if (string_ok(temp))
00202 {
00203 if (string_ok(actors))
00204 actors = actors + _(", ");
00205
00206 actors = actors + temp;
00207 }
00208 }
00209
00210 if (string_ok(actors))
00211 item->setMetadata(MetadataHandler::getMetaFieldName(M_GENRE),
00212 temp);
00213 }
00214
00215 Ref<Element> genre = trailer->getChildByName(_("genre"));
00216 if (genre != nil)
00217 {
00218 String genres;
00219 for (int i = 0; i < genre->childCount(); i++)
00220 {
00221 Ref<Node> gn = genre->getChild(i);
00222 if (gn->getType() != mxml_node_element)
00223 continue;
00224
00225 Ref<Element> genre = RefCast(gn, Element);
00226 if (genre->getName() != "name")
00227 continue;
00228
00229 temp = genre->getText();
00230 if (string_ok(temp))
00231 {
00232 if (string_ok(genres))
00233 genres = genres + _(", ");
00234
00235 genres = genres + temp;
00236 }
00237 }
00238
00239 if (string_ok(genres))
00240 item->setMetadata(MetadataHandler::getMetaFieldName(M_GENRE),
00241 temp);
00242 }
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256 getTimespecNow(&ts);
00257 item->setAuxData(_(ONLINE_SERVICE_LAST_UPDATE),
00258 String::from(ts.tv_sec));
00259
00260 item->setFlag(OBJECT_FLAG_ONLINE_SERVICE);
00261 try
00262 {
00263 item->validate();
00264 return RefCast(item, CdsObject);
00265 }
00266 catch (Exception ex)
00267 {
00268 log_warning("Failed to validate newly created Trailer item: %s\n",
00269 ex.getMessage().c_str());
00270 continue;
00271 }
00272 }
00273 return nil;
00274 }
00275
00276 #endif//ATRAILERS