15 #define LOC QString("NewsSite: ")
16 #define LOC_WARN QString("NewsSite, Warning: ")
17 #define LOC_ERR QString("NewsSite, Error: ")
20 QDateTime updated,
const bool podcast) :
22 m_updated(std::move(updated)),
32 QMutexLocker locker(&
m_lock);
36 QObject::deleteLater();
41 QMutexLocker locker(&
m_lock);
48 QMutexLocker locker(&
m_lock);
54 QMutexLocker locker(&
m_lock);
60 QMutexLocker locker(&
m_lock);
73 QMutexLocker locker(&
m_lock);
80 QMutexLocker locker(&
m_lock);
86 QMutexLocker locker(&
m_lock);
92 QMutexLocker locker(&
m_lock);
98 QMutexLocker locker(&
m_lock);
104 QMutexLocker locker(&
m_lock);
110 QMutexLocker locker(&
m_lock);
116 QMutexLocker locker(&
m_lock);
130 QMutexLocker locker(&
m_lock);
136 QMutexLocker locker(&
m_lock);
142 QMutexLocker locker(&
m_lock);
148 QMutexLocker locker(&
m_lock);
151 auto secs = std::chrono::seconds(
m_updated.secsTo(curTime));
152 return duration_cast<std::chrono::minutes>(secs);
159 auto *me =
dynamic_cast<MythEvent *
>(event);
162 QStringList tokens = me->
Message().split(
" ", Qt::SkipEmptyParts);
164 if (tokens.isEmpty())
167 if (tokens[0] ==
"DOWNLOAD_FILE")
169 QStringList
args = me->ExtraDataList();
171 if (tokens[1] ==
"UPDATE")
175 else if (tokens[1] ==
"FINISHED")
179 int fileSize =
args[2].toInt();
180 const QString& errorStr =
args[3];
181 int errorCode =
args[4].toInt();
183 if ((errorCode != 0) || (fileSize == 0))
185 LOG(VB_GENERAL, LOG_ERR,
LOC +
"HTTP Connection Error - " +
186 QString(
"%1\n\t\t\tExplanation: %2: %3, filesize: %4, filename: %5")
187 .arg(
url).arg(errorCode).arg(errorStr).arg(fileSize).arg(
filename));
223 QMutexLocker locker(&
m_lock);
234 if (!xmlFile.exists())
243 if (!xmlFile.open(QIODevice::ReadOnly))
246 LOG(VB_GENERAL, LOG_ERR,
LOC +
"Failed to open xmlfile");
252 if (!domDoc.setContent(&xmlFile))
255 LOG(VB_GENERAL, LOG_ERR,
LOC +
"Failed to set content from xmlfile");
270 QString rootName = domDoc.documentElement().nodeName();
271 if (rootName ==
"rss" || rootName ==
"rdf:RDF")
277 if (rootName ==
"feed")
283 LOG(VB_GENERAL, LOG_ERR,
LOC +
"XML-file is not valid RSS-feed");
289 return mimeType ==
"image/png" || mimeType ==
"image/jpeg" ||
290 mimeType ==
"image/jpg" || mimeType ==
"image/gif" ||
291 mimeType ==
"image/bmp";
296 return mimeType ==
"video/mpeg" || mimeType ==
"video/x-ms-wmv" ||
297 mimeType ==
"application/x-troff-msvideo" || mimeType ==
"video/avi" ||
298 mimeType ==
"video/msvideo" || mimeType ==
"video/x-msvideo";
303 QMutexLocker locker(&
m_lock);
305 QDomNode channelNode = domDoc.documentElement().namedItem(
"channel");
307 m_desc = channelNode.namedItem(
"description")
308 .toElement().text().simplified();
310 QDomNode imageNode = channelNode.namedItem(
"image");
311 if (!imageNode.isNull())
312 m_imageURL = imageNode.namedItem(
"url").toElement().text().simplified();
314 QDomNodeList items = domDoc.elementsByTagName(
"item");
316 for (
unsigned int i = 0; i < (unsigned) items.count(); i++)
318 QDomNode itemNode = items.item(i);
320 .toElement().text().simplified());
322 QDomNode descNode = itemNode.namedItem(
"description");
324 if (!descNode.isNull())
326 description = descNode.toElement().text().simplified();
330 QDomNode linkNode = itemNode.namedItem(
"link");
332 if (!linkNode.isNull())
333 url = linkNode.toElement().text().simplified();
335 QDomNode enclosureNode = itemNode.namedItem(
"enclosure");
337 QString enclosure_type;
339 if (!enclosureNode.isNull())
341 QDomAttr enclosureURL = enclosureNode.toElement()
342 .attributeNode(
"url");
344 if (!enclosureURL.isNull())
345 enclosure = enclosureURL.value();
347 QDomAttr enclosureType = enclosureNode.toElement()
348 .attributeNode(
"type");
349 if (!enclosureType.isNull())
351 enclosure_type = enclosureType.value();
353 if (enclosure_type ==
"image/jpeg")
355 thumbnail = enclosure;
360 if (enclosure_type ==
"" || enclosure_type.isNull())
362 QStringList imageExtensions = QStringList() <<
".jpg" <<
".jpeg" <<
".png" <<
".gif";
363 for (
int x = 0; x < imageExtensions.count(); x++)
365 if (enclosure.endsWith(imageExtensions[x], Qt::CaseInsensitive))
367 thumbnail = enclosure;
390 QDomNode mediaGroup = itemNode.namedItem(
"media:group");
391 if (!mediaGroup.isNull())
392 itemNode = mediaGroup;
394 QDomNode thumbNode = itemNode.namedItem(
"media:thumbnail");
395 if (!thumbNode.isNull())
397 QDomAttr thumburl = thumbNode.toElement().attributeNode(
"url");
398 if (!thumburl.isNull())
399 thumbnail = thumburl.value();
402 QDomNode playerNode = itemNode.namedItem(
"media:player");
404 if (!playerNode.isNull())
406 QDomAttr mediaURL = playerNode.toElement().attributeNode(
"url");
407 if (!mediaURL.isNull())
408 mediaurl = mediaURL.value();
412 descNode = itemNode.namedItem(
"media:description");
413 if (!descNode.isNull())
414 description = descNode.toElement().text().simplified();
417 QDomElement e = itemNode.toElement();
418 QDomNodeList mediaNodes = e.elementsByTagName(
"media:content");
419 for (
int x = 0; x < mediaNodes.count(); x++)
425 QDomElement mediaElement = mediaNodes.at(x).toElement();
427 if (mediaElement.isNull())
430 if (mediaElement.hasAttribute(
"medium"))
431 medium = mediaElement.attributeNode(
"medium").value();
433 if (mediaElement.hasAttribute(
"type"))
434 type = mediaElement.attributeNode(
"type").value();
436 if (mediaElement.hasAttribute(
"url"))
437 url2 = mediaElement.attributeNode(
"url").value();
439 LOG(VB_GENERAL, LOG_DEBUG,
440 QString(
"parseRSS found media:content: medium: %1, type: %2, url: %3")
441 .arg(medium,
type, url2));
444 if (thumbnail.isEmpty() && (medium ==
"image" ||
isImage(
type)))
448 if (enclosure.isEmpty() && (medium ==
"video" ||
isVideo(
type)))
453 thumbnail, mediaurl, enclosure));
459 QDomNodeList entries = domDoc.elementsByTagName(
"entry");
461 for (
unsigned int i = 0; i < (unsigned) entries.count(); i++)
463 QDomNode itemNode = entries.item(i);
464 QString title =
ReplaceHtmlChar(itemNode.namedItem(
"title").toElement()
465 .text().simplified());
467 QDomNode summNode = itemNode.namedItem(
"summary");
469 if (!summNode.isNull())
472 summNode.toElement().text().simplified());
475 QDomNode linkNode = itemNode.namedItem(
"link");
477 if (!linkNode.isNull())
479 QDomAttr linkHref = linkNode.toElement().attributeNode(
"href");
480 if (!linkHref.isNull())
481 url = linkHref.value();
494 s.replace(
"&",
"&");
495 s.replace(
"£",
"£");
496 s.replace(
"<",
"<");
497 s.replace(
">",
">");
498 s.replace(
""",
"\"");
499 s.replace(
"'",
"\'");
500 s.replace(
"…",QChar(8230));
501 s.replace(
"é",QChar(233));
502 s.replace(
"—", QChar(8212));
503 s.replace(
" ",
" ");
504 s.replace(
" ", QChar(160));
505 s.replace(
"á", QChar(225));
506 s.replace(
"‘", QChar(8216));
507 s.replace(
"’", QChar(8217));
508 s.replace(
"'",
"\'");
509 s.replace(
"–", QChar(8211));
511 s.replace(
"ä", QChar(0x00e4));
512 s.replace(
"ö", QChar(0x00f6));
513 s.replace(
"ü", QChar(0x00fc));
514 s.replace(
"Ä", QChar(0x00c4));
515 s.replace(
"Ö", QChar(0x00d6));
516 s.replace(
"Ü", QChar(0x00dc));
517 s.replace(
"ß", QChar(0x00df));