Esempio n. 1
0
bool Nzbs::parse(QIODevice& io, std::vector<MediaItem>& rss)
{
    QDomDocument dom;
    QString error_string;
    int error_line   = 0;
    int error_column = 0;
    if (!dom.setContent(&io, false, &error_string, &error_line, &error_column))
    {
        DEBUG("XML parse error '%1' on line %2", error_string, error_line);
        return false;
    }
     
    const auto& root  = dom.firstChildElement();
    const auto& items = root.elementsByTagName("item");
    for (int i=0; i<items.size(); ++i)
    {
        const auto& elem = items.at(i).toElement();

        MediaItem item {};
        item.title   = elem.firstChildElement("title").text();
        item.guid    = elem.firstChildElement("guid").text();
        item.nzblink = elem.firstChildElement("link").text();
        item.pubdate = parseRssDate(elem.firstChildElement("pubDate").text());

        const auto& attrs = elem.elementsByTagName("newznab:attr");
        for (int x=0; x<attrs.size(); ++x)
        {
            const auto& attr = attrs.at(x).toElement();
            const auto& name = attr.attribute("name");
            if (name == "size")
                item.size = attr.attribute("value").toLongLong();
            else if (name == "password")
                item.password = attr.attribute("value").toInt();
        }

        // looks like there's a problem with the RSS feed from nzbs.org. The link contains a link to a
        // HTML info page about the the NZB not an actual link to get the NZB. adding &dl=1 to the 
        // query params doesn't change this.
        // we have a simple hack here to change the feed link to get link
        // http://nzbs.org/index.php?action=view&nzbid=334012
        // http://nzbs.org/index.php?action=getnzb&nzbid=334012
        if (item.nzblink.contains("action=view&"))
            item.nzblink.replace("action=view&", "action=getnzb&");

        rss.push_back(std::move(item));
    }
    return true;
}
Esempio n. 2
0
void FeedFetcher::handleRssXml(QDomNode node) {
	QList<Tweet*> tweets;
	QDomNodeList children = node.firstChild().childNodes();
	QDateTime startDate = QDateTime::currentDateTime();
	for (int x=0;x<children.count();x++) {
		QDomNode item = children.at(x);
//			QMessageBox::information(0,"Bleugh",item.nodeName());
		if (nodeName(item)=="title") {
			emit feedTitle(item.firstChild().nodeValue());
		} else if (nodeName(item)=="item") {
			FeedItem *tweet = new FeedItem();
			tweet->created_at=startDate.addSecs(-x);
			tweet->feed_item_date="";//tweet->created_at.toString();
			tweet->sourceUrl=url;
			QDomNodeList children2 = item.childNodes();
			for (int y=0;y<children2.count();y++) {
				QDomNode childItem = children2.at(y);
				if (nodeName(childItem)=="title") {
					tweet->message=childItem.firstChild().nodeValue();
				} else if (nodeName(childItem)=="guid") {
					tweet->id=childItem.firstChild().nodeValue();
				} else if (nodeName(childItem)=="description") {
					tweet->content=childItem.firstChild().nodeValue();
				} else if (nodeName(childItem)=="link") {
					tweet->url=childItem.firstChild().nodeValue();
					if (tweet->id=="")
						tweet->id=tweet->url;
				} else if (nodeName(childItem)=="pubDate") {
					//Thu Feb 19 00:20:20 +0000 2009
					QString date = childItem.firstChild().nodeValue();
//					tweet->feed_item_date = childItem.firstChild().nodeValue().left(26);
//						QString hour = dateStr.mid(20,5);
//						dateStr=dateStr.left(20)+dateStr.right(4);
//					tweet->created_at=QDateTime::fromString(dateStr,"ddd MMM dd HH:mm:ss +0000 yyyy");
					// Sat, 05 Sep 2009 14:51:00 GMT
					tweet->created_at=parseRssDate(date);
				}
			}
			tweets.append(tweet);
		}
	}
	emit haveTweets(tweets);
}