Fix a date parser for one podcasts
This commit is contained in:
parent
958cb42e98
commit
6cc72e2f5d
|
@ -571,17 +571,43 @@ bool ParseUntilElement(QXmlStreamReader* reader, const QString& name) {
|
|||
QDateTime ParseRFC822DateTime(const QString& text) {
|
||||
// This sucks but we need it because some podcasts don't quite follow the
|
||||
// spec properly - they might have 1-digit hour numbers for example.
|
||||
|
||||
QDateTime ret;
|
||||
QRegExp re(
|
||||
"([a-zA-Z]{3}),? (\\d{1,2}) ([a-zA-Z]{3}) (\\d{4}) "
|
||||
"(\\d{1,2}):(\\d{1,2}):(\\d{1,2})");
|
||||
if (re.indexIn(text) == -1) return QDateTime();
|
||||
|
||||
return QDateTime(
|
||||
if (re.indexIn(text) != -1) {
|
||||
ret = QDateTime(
|
||||
QDate::fromString(QString("%1 %2 %3 %4")
|
||||
.arg(re.cap(1), re.cap(3), re.cap(2), re.cap(4)),
|
||||
Qt::TextDate),
|
||||
QTime(re.cap(5).toInt(), re.cap(6).toInt(), re.cap(7).toInt()));
|
||||
}
|
||||
if (ret.isValid()) return ret;
|
||||
// Because http://feeds.feedburner.com/reasonabledoubts/Msxh?format=xml
|
||||
QRegExp re2(
|
||||
"(\\d{1,2}) ([a-zA-Z]{3}) (\\d{4}) "
|
||||
"(\\d{1,2}):(\\d{1,2}):(\\d{1,2})");
|
||||
|
||||
QMap<QString, int> monthmap;
|
||||
monthmap["Jan"] = 1;
|
||||
monthmap["Feb"] = 2;
|
||||
monthmap["Mar"] = 3;
|
||||
monthmap["Apr"] = 4;
|
||||
monthmap["May"] = 5;
|
||||
monthmap["Jun"] = 6;
|
||||
monthmap["Jul"] = 7;
|
||||
monthmap["Aug"] = 8;
|
||||
monthmap["Sep"] = 9;
|
||||
monthmap["Oct"] = 10;
|
||||
monthmap["Nov"] = 11;
|
||||
monthmap["Dec"] = 12;
|
||||
|
||||
if (re2.indexIn(text) != -1) {
|
||||
QDate date(re2.cap(3).toInt(), monthmap[re2.cap(2)], re2.cap(1).toInt());
|
||||
ret = QDateTime(date,
|
||||
QTime(re2.cap(4).toInt(), re2.cap(5).toInt(), re2.cap(6).toInt()));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
const char* EnumToString(const QMetaObject& meta, const char* name, int value) {
|
||||
|
|
|
@ -211,8 +211,12 @@ void PodcastParser::ParseItem(QXmlStreamReader* reader, Podcast* ret) const {
|
|||
} else if (name == "description") {
|
||||
episode.set_description(reader->readElementText());
|
||||
} else if (name == "pubDate") {
|
||||
episode.set_publication_date(
|
||||
Utilities::ParseRFC822DateTime(reader->readElementText()));
|
||||
QString date = reader->readElementText();
|
||||
episode.set_publication_date(Utilities::ParseRFC822DateTime(date));
|
||||
if (!episode.publication_date().isValid()) {
|
||||
qLog(Error) << "Unable to parse date:" << date
|
||||
<< "Pleas submit it to https://github.com/clementine-player/Clementine/issues/new";
|
||||
}
|
||||
} else if (name == "duration" && lower_namespace == kItunesNamespace) {
|
||||
// http://www.apple.com/itunes/podcasts/specs.html
|
||||
QStringList parts = reader->readElementText().split(':');
|
||||
|
@ -238,6 +242,9 @@ void PodcastParser::ParseItem(QXmlStreamReader* reader, Podcast* ret) const {
|
|||
}
|
||||
|
||||
case QXmlStreamReader::EndElement:
|
||||
if (!episode.publication_date().isValid()) {
|
||||
episode.set_publication_date(QDateTime::currentDateTime());
|
||||
}
|
||||
if (!episode.url().isEmpty()) {
|
||||
ret->add_episode(episode);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue