Item* RSS091Parser::ParseItem (const QDomElement& item, const IDType_t& channelId) const { Item *result = new Item (channelId); result->Title_ = UnescapeHTML (item.firstChildElement ("title").text ()); if (result->Title_.isEmpty ()) result->Title_ = "<>"; result->Link_ = item.firstChildElement ("link").text (); result->Description_ = item.firstChildElement ("description").text (); GetDescription (item, result->Description_); result->PubDate_ = RFC822TimeToQDateTime (item.firstChildElement ("pubDate").text ()); if (!result->PubDate_.isValid () || result->PubDate_.isNull ()) { qWarning () << "Aggregator RSS 0.91: Can't parse item pubDate: " << item.firstChildElement ("pubDate").text (); result->PubDate_ = QDateTime::currentDateTime (); } result->Guid_ = item.firstChildElement ("guid").text (); if (result->Guid_.isEmpty ()) result->Guid_ = "empty"; result->Categories_ = GetAllCategories (item); result->Unread_ = true; result->Author_ = GetAuthor (item); result->NumComments_ = GetNumComments (item); result->CommentsLink_ = GetCommentsRSS (item); result->CommentsPageLink_ = GetCommentsLink (item); result->Enclosures_ = GetEnclosures (item, result->ItemID_); result->Enclosures_ += GetEncEnclosures (item, result->ItemID_); QPair<double, double> point = GetGeoPoint (item); result->Latitude_ = point.first; result->Longitude_ = point.second; return result; }
Item* RSS20Parser::ParseItem (const QDomElement& item, const IDType_t& channelId) const { Item *result = new Item (channelId); result->Title_ = UnescapeHTML (item.firstChildElement ("title").text ()); if (result->Title_.isEmpty ()) result->Title_ = "<>"; result->Link_ = item.firstChildElement ("link").text (); result->Description_ = item.firstChildElement ("description").text (); GetDescription (item, result->Description_); QDomNodeList duration = item.elementsByTagNameNS (ITunes_, "duration"); if (duration.size ()) { if (!result->Description_.isEmpty ()) result->Description_ += "<br /><br />"; result->Description_ += QObject::tr ("Duration: %1") .arg (duration.at (0).toElement ().text ()); } QString pubDateText = item.firstChildElement ("pubDate").text (); if (pubDateText.size ()) { result->PubDate_ = RFC822TimeToQDateTime (pubDateText); if (!result->PubDate_.isValid () || result->PubDate_.isNull ()) result->PubDate_ = QDateTime::currentDateTime (); } result->Guid_ = item.firstChildElement ("guid").text (); if (result->Guid_.isEmpty ()) result->Guid_ = "empty"; result->Categories_ = GetAllCategories (item); result->Unread_ = true; result->Author_ = GetAuthor (item); result->NumComments_ = GetNumComments (item); result->CommentsLink_ = GetCommentsRSS (item); result->CommentsPageLink_ = GetCommentsLink (item); result->Enclosures_ = GetEnclosures (item, result->ItemID_); result->Enclosures_ += GetEncEnclosures (item, result->ItemID_); QPair<double, double> point = GetGeoPoint (item); result->Latitude_ = point.first; result->Longitude_ = point.second; result->MRSSEntries_ = GetMediaRSS (item, result->ItemID_); return result; }
channels_container_t RSS20Parser::Parse (const QDomDocument& doc, const IDType_t& feedId) const { channels_container_t channels; QDomElement root = doc.documentElement (); QDomElement channel = root.firstChildElement ("channel"); while (!channel.isNull ()) { Channel_ptr chan (new Channel (feedId)); chan->Title_ = channel.firstChildElement ("title").text ().trimmed (); chan->Description_ = channel.firstChildElement ("description").text (); chan->Link_ = GetLink (channel); chan->LastBuild_ = RFC822TimeToQDateTime (channel.firstChildElement ("lastBuildDate").text ()); chan->Language_ = channel.firstChildElement ("language").text (); chan->Author_ = GetAuthor (channel); if (chan->Author_.isEmpty ()) chan->Author_ = channel.firstChildElement ("managingEditor").text (); if (chan->Author_.isEmpty ()) chan->Author_ = channel.firstChildElement ("webMaster").text (); chan->PixmapURL_ = channel.firstChildElement ("image").attribute ("url"); QDomElement item = channel.firstChildElement ("item"); while (!item.isNull ()) { chan->Items_.push_back (Item_ptr (ParseItem (item, chan->ChannelID_))); item = item.nextSiblingElement ("item"); } if (!chan->LastBuild_.isValid () || chan->LastBuild_.isNull ()) { if (chan->Items_.size ()) chan->LastBuild_ = chan->Items_.at (0)->PubDate_; else chan->LastBuild_ = QDateTime::currentDateTime (); } channels.push_back (chan); channel = channel.nextSiblingElement ("channel"); } return channels; }
MetadataLookup* ParseMetadataItem(const QDomElement& item, MetadataLookup *lookup, bool passseas) { if (!lookup) return new MetadataLookup(); uint season = 0, episode = 0, chanid = 0, programflags = 0, audioproperties = 0, videoproperties = 0, subtitletype = 0, tracknum = 0, popularity = 0, budget = 0, revenue = 0, year = 0, runtime = 0, runtimesecs = 0, ratingcount = 0; QString title, network, status, subtitle, tagline, description, certification, channum, chansign, channame, chanplaybackfilters, recgroup, playgroup, seriesid, programid, storagegroup, album, system, inetref, collectionref, tmsref, imdb, homepage, trailerURL, language; QStringList categories, countries, studios; float userrating = 0; QDate releasedate; QDateTime lastupdated, startts, endts, recstartts, recendts; PeopleMap people; ArtworkMap artwork; // Get the easy parses language = item.firstChildElement("language").text(); title = Parse::UnescapeHTML(item.firstChildElement("title").text()); network = Parse::UnescapeHTML(item.firstChildElement("network").text()); status = Parse::UnescapeHTML(item.firstChildElement("status").text()); subtitle = Parse::UnescapeHTML(item.firstChildElement("subtitle").text()); tagline = Parse::UnescapeHTML(item.firstChildElement("tagline").text()); description = Parse::UnescapeHTML(item.firstChildElement("description").text()); album = Parse::UnescapeHTML(item.firstChildElement("albumname").text()); inetref = item.firstChildElement("inetref").text(); collectionref = item.firstChildElement("collectionref").text(); tmsref = item.firstChildElement("tmsref").text(); imdb = item.firstChildElement("imdb").text(); homepage = item.firstChildElement("homepage").text(); trailerURL = item.firstChildElement("trailer").text(); // ProgramInfo specific parsing chanid = item.firstChildElement("chanid").text().toUInt(); channum = item.firstChildElement("channum").text(); chansign = item.firstChildElement("chansign").text(); channame = item.firstChildElement("channame").text(); chanplaybackfilters = item.firstChildElement("chanplaybackfilters").text(); recgroup = item.firstChildElement("recgroup").text(); playgroup = item.firstChildElement("playgroup").text(); seriesid = item.firstChildElement("seriesid").text(); programid = item.firstChildElement("programid").text(); storagegroup = item.firstChildElement("storagegroup").text(); startts = RFC822TimeToQDateTime(item. firstChildElement("startts").text()); endts = RFC822TimeToQDateTime(item. firstChildElement("endts").text()); recstartts = RFC822TimeToQDateTime(item. firstChildElement("recstartts").text()); recendts = RFC822TimeToQDateTime(item. firstChildElement("recendts").text()); programflags = item.firstChildElement("programflags").text().toUInt(); audioproperties = item.firstChildElement("audioproperties").text().toUInt(); videoproperties = item.firstChildElement("videoproperties").text().toUInt(); subtitletype = item.firstChildElement("subtitletype").text().toUInt(); QString tmpDate = item.firstChildElement("releasedate").text(); if (!tmpDate.isEmpty()) releasedate = QDate::fromString(tmpDate, "yyyy-MM-dd"); lastupdated = RFC822TimeToQDateTime(item. firstChildElement("lastupdated").text()); userrating = item.firstChildElement("userrating").text().toFloat(); ratingcount = item.firstChildElement("ratingcount").text().toUInt(); tracknum = item.firstChildElement("tracknum").text().toUInt(); popularity = item.firstChildElement("popularity").text().toUInt(); budget = item.firstChildElement("budget").text().toUInt(); revenue = item.firstChildElement("revenue").text().toUInt(); year = item.firstChildElement("year").text().toUInt(); if (!year && !releasedate.isNull()) year = releasedate.toString("yyyy").toUInt(); runtime = item.firstChildElement("runtime").text().toUInt(); runtimesecs = item.firstChildElement("runtimesecs").text().toUInt(); QDomElement systems = item.firstChildElement("systems"); if (!systems.isNull()) { QDomElement firstSystem = systems.firstChildElement("system"); if (!firstSystem.isNull()) system = firstSystem.text(); } // TODO: Once TMDB supports certification per-locale, come back and match // locale of myth to certification locale. QDomElement certifications = item.firstChildElement("certifications"); QList< QPair<QString,QString> > ratinglist; if (!certifications.isNull()) { QDomElement cert = certifications.firstChildElement("certification"); if (!cert.isNull()) { while (!cert.isNull()) { if (cert.hasAttribute("locale") && cert.hasAttribute("name")) { QPair<QString,QString> newcert(cert.attribute("locale"), cert.attribute("name")); ratinglist.append(newcert); } cert = cert.nextSiblingElement("certification"); } } } // HACK: To go away when someone supports ratings by locale. if (!ratinglist.isEmpty()) certification = ratinglist.takeFirst().second; // Categories QDomElement categoriesxml = item.firstChildElement("categories"); if (!categoriesxml.isNull()) { QDomElement cat = categoriesxml.firstChildElement("category"); if (!cat.isNull()) { while (!cat.isNull()) { if (cat.hasAttribute("name")) categories.append(cat.attribute("name")); cat = cat.nextSiblingElement("category"); } } } // Countries QDomElement countriesxml = item.firstChildElement("countries"); if (!countriesxml.isNull()) { QDomElement cntry = countriesxml.firstChildElement("country"); if (!cntry.isNull()) { while (!cntry.isNull()) { if (cntry.hasAttribute("name")) countries.append(cntry.attribute("name")); cntry = cntry.nextSiblingElement("country"); } } } // Studios QDomElement studiosxml = item.firstChildElement("studios"); if (!studiosxml.isNull()) { QDomElement studio = studiosxml.firstChildElement("studio"); if (!studio.isNull()) { while (!studio.isNull()) { if (studio.hasAttribute("name")) studios.append(studio.attribute("name")); studio = studio.nextSiblingElement("studio"); } } } // People QDomElement peoplexml = item.firstChildElement("people"); if (!peoplexml.isNull()) { people = ParsePeople(peoplexml); } // Artwork QDomElement artworkxml = item.firstChildElement("images"); if (!artworkxml.isNull()) { artwork = ParseArtwork(artworkxml); } // Have to handle season and episode a little differently. // If the query object comes in with a season or episode number, // we want to pass that through. However, if we are doing a title/subtitle // lookup, we need to parse for season and episode. if (passseas) { season = lookup->GetSeason(); episode = lookup->GetEpisode(); } else { if (lookup->GetPreferDVDOrdering()) { season = item.firstChildElement("dvdseason").text().toUInt(); episode = item.firstChildElement("dvdepisode").text().toUInt(); } if ((season == 0) && (episode == 0)) { season = item.firstChildElement("season").text().toUInt(); episode = item.firstChildElement("episode").text().toUInt(); } LOG(VB_GENERAL, LOG_INFO, QString("Result Found, Season %1 Episode %2") .arg(season).arg(episode)); } return new MetadataLookup(lookup->GetType(), lookup->GetSubtype(), lookup->GetData(), lookup->GetStep(), lookup->GetAutomatic(), lookup->GetHandleImages(), lookup->GetAllowOverwrites(), lookup->GetAllowGeneric(), lookup->GetPreferDVDOrdering(), lookup->GetHost(), lookup->GetFilename(), title, network, status, categories, userrating, ratingcount, language, subtitle, tagline, description, season, episode, chanid, channum, chansign, channame, chanplaybackfilters, recgroup, playgroup, seriesid, programid, storagegroup, startts, endts, recstartts, recendts, programflags, audioproperties, videoproperties, subtitletype, certification, countries, popularity, budget, revenue, album, tracknum, system, year, releasedate, lastupdated, runtime, runtimesecs, inetref, collectionref, tmsref, imdb, people, studios, homepage, trailerURL, artwork, DownloadMap()); }