diff --git a/mythtv/libs/libmythtv/datadirect.cpp b/mythtv/libs/libmythtv/datadirect.cpp
index 1870ff0..1bc12d4 100644
a
|
b
|
|
25 | 25 | #include "exitcodes.h" |
26 | 26 | #include "mythdownloadmanager.h" |
27 | 27 | #include "mythtvexp.h" |
| 28 | #include "mythtimer.h" |
28 | 29 | |
29 | 30 | #define LOC QString("DataDirect: ") |
30 | 31 | |
… |
… |
void DataDirectProcessor::authenticationCallback(QNetworkReply *reply, |
976 | 977 | auth->setPassword(GetPassword()); |
977 | 978 | } |
978 | 979 | |
979 | | bool DataDirectProcessor::DDPost(QString ddurl, QString &inputFile, |
980 | | QDateTime pstartDate, QDateTime pendDate, |
981 | | QString &err_txt) |
| 980 | QByteArray DataDirectProcessor::DDPost( |
| 981 | const QString &url, |
| 982 | const QDateTime &startDate, const QDateTime &endDate, |
| 983 | QString &err_txt) |
982 | 984 | { |
983 | | if (!inputFile.isEmpty() && QFile(inputFile).exists()) |
984 | | { |
985 | | return true; |
986 | | } |
| 985 | QString startdatestr = startDate.toString(Qt::ISODate); |
| 986 | if (startdatestr.right(1) != "Z") |
| 987 | startdatestr += "Z"; // Z is only appended in some versions of Qt |
| 988 | |
| 989 | QString enddatestr = endDate.toString(Qt::ISODate); |
| 990 | if (enddatestr.right(1) != "Z") |
| 991 | enddatestr += "Z"; |
987 | 992 | |
988 | | QString startdatestr = pstartDate.toString(Qt::ISODate) + "Z"; |
989 | | QString enddatestr = pendDate.toString(Qt::ISODate) + "Z"; |
990 | 993 | QByteArray postdata; |
991 | 994 | postdata = "<?xml version='1.0' encoding='utf-8'?>\n"; |
992 | 995 | postdata += "<SOAP-ENV:Envelope\n"; |
… |
… |
bool DataDirectProcessor::DDPost(QString ddurl, QString &inputFile, |
1006 | 1009 | postdata += "</SOAP-ENV:Body>\n"; |
1007 | 1010 | postdata += "</SOAP-ENV:Envelope>\n"; |
1008 | 1011 | |
1009 | | if (inputFile.isEmpty()) { |
1010 | | inputFile = QString("/tmp/mythtv_ddp_data"); |
1011 | | } |
1012 | | |
1013 | 1012 | QHash<QByteArray, QByteArray> headers; |
1014 | 1013 | headers.insert("Accept-Encoding", "gzip"); |
1015 | 1014 | headers.insert("Content-Type", "application/soap+xml; charset=utf-8"); |
1016 | 1015 | |
1017 | | LOG(VB_GENERAL, LOG_INFO, "Downloading DataDirect feed"); |
| 1016 | LOG(VB_GENERAL, LOG_INFO, |
| 1017 | "Downloading DataDirect feed, this can take several minutes"); |
1018 | 1018 | |
1019 | 1019 | MythDownloadManager *manager = GetMythDownloadManager(); |
1020 | 1020 | |
1021 | | if (!manager->postAuth(ddurl, &postdata, &::authenticationCallback, this, |
1022 | | &headers)) |
| 1021 | MythTimer downloadTimer; |
| 1022 | downloadTimer.start(); |
| 1023 | |
| 1024 | if (!manager->postAuth( |
| 1025 | url, &postdata, &::authenticationCallback, this, &headers)) |
1023 | 1026 | { |
1024 | | err_txt = QString("Download error"); |
1025 | | return false; |
| 1027 | err_txt = "Download error"; |
| 1028 | return QByteArray(); |
1026 | 1029 | } |
1027 | 1030 | |
1028 | | LOG(VB_GENERAL, LOG_INFO, QString("Downloaded %1 bytes") |
1029 | | .arg(postdata.size())); |
1030 | | |
1031 | | LOG(VB_GENERAL, LOG_INFO, "Uncompressing DataDirect feed"); |
| 1031 | float downloadTime = downloadTimer.elapsed() * 0.001; |
1032 | 1032 | |
1033 | 1033 | QByteArray uncompressed = gUncompress(postdata); |
1034 | 1034 | |
1035 | | LOG(VB_GENERAL, LOG_INFO, QString("Uncompressed to %1 bytes") |
1036 | | .arg(uncompressed.size())); |
1037 | | |
1038 | | if (uncompressed.size() == 0) |
1039 | | uncompressed = postdata; |
1040 | | |
1041 | | QFile file(inputFile); |
1042 | | file.open(QIODevice::WriteOnly); |
1043 | | file.write(uncompressed); |
1044 | | file.close(); |
| 1035 | LOG(VB_GENERAL, LOG_INFO, |
| 1036 | QString("Downloaded %1 megabytes in %2 seconds, " |
| 1037 | "decompressed to %3 megabytes") |
| 1038 | .arg(postdata.size()/(1024.0*1024.0)).arg(downloadTime) |
| 1039 | .arg(uncompressed.size()/(1024.0*1024.0))); |
1045 | 1040 | |
1046 | 1041 | if (uncompressed.size() == 0) |
1047 | 1042 | { |
1048 | | err_txt = QString("Error uncompressing data"); |
1049 | | return false; |
| 1043 | err_txt = "Error uncompressing data"; |
| 1044 | return QByteArray(); |
1050 | 1045 | } |
1051 | 1046 | |
1052 | | return true; |
| 1047 | return uncompressed; |
1053 | 1048 | } |
1054 | 1049 | |
1055 | 1050 | bool DataDirectProcessor::GrabNextSuggestedTime(void) |
… |
… |
bool DataDirectProcessor::GrabNextSuggestedTime(void) |
1148 | 1143 | return nextSuggestedTime.isValid(); |
1149 | 1144 | } |
1150 | 1145 | |
1151 | | bool DataDirectProcessor::GrabData(const QDateTime &pstartDate, |
1152 | | const QDateTime &pendDate) |
| 1146 | bool DataDirectProcessor::GrabData( |
| 1147 | const QDateTime &startDate, const QDateTime &endDate) |
1153 | 1148 | { |
1154 | | QString msg = (pstartDate.addSecs(1) == pendDate) ? "channel" : "listing"; |
1155 | | LOG(VB_GENERAL, LOG_INFO, LOC + "Grabbing " + msg + " data"); |
| 1149 | LOG(VB_GENERAL, LOG_INFO, LOC + |
| 1150 | ((startDate.addSecs(1) == endDate) ? |
| 1151 | "Grabbing channel data" : "Grabbing listing data")); |
1156 | 1152 | |
1157 | | QString err = ""; |
1158 | 1153 | QString ddurl = m_providers[m_listingsProvider].webServiceURL; |
1159 | 1154 | QString inputfile = m_inputFilename; |
1160 | | QString cache_dd_data = QString::null; |
1161 | 1155 | |
1162 | 1156 | if (m_cacheData) |
1163 | 1157 | { |
1164 | 1158 | QByteArray userid = GetUserID().toAscii(); |
1165 | | cache_dd_data = m_tmpDir + |
| 1159 | QString cache_dd_data = m_tmpDir + |
1166 | 1160 | QString("/mythtv_dd_cache_%1_%2_UTC_%3_to_%4") |
1167 | 1161 | .arg(GetListingsProvider()) |
1168 | 1162 | .arg(userid.constData()) |
1169 | | .arg(MythDate::toString(pstartDate, MythDate::kFilename)) |
1170 | | .arg(MythDate::toString(pendDate, MythDate::kFilename)); |
| 1163 | .arg(MythDate::toString(startDate, MythDate::kFilename)) |
| 1164 | .arg(MythDate::toString(endDate, MythDate::kFilename)); |
1171 | 1165 | |
1172 | 1166 | if (QFile(cache_dd_data).exists() && m_inputFilename.isEmpty()) |
1173 | 1167 | { |
1174 | | LOG(VB_GENERAL, LOG_INFO, LOC + "Using DD cache"); |
| 1168 | LOG(VB_GENERAL, LOG_INFO, LOC + "Using cached DataDirect data"); |
1175 | 1169 | } |
1176 | 1170 | |
1177 | 1171 | if (m_inputFilename.isEmpty()) |
1178 | 1172 | inputfile = cache_dd_data; |
1179 | 1173 | } |
1180 | 1174 | |
1181 | | if (!DDPost(ddurl, inputfile, pstartDate, pendDate, err)) |
| 1175 | QByteArray data; |
| 1176 | if (!inputfile.isEmpty()) |
1182 | 1177 | { |
1183 | | LOG(VB_GENERAL, LOG_ERR, LOC + QString("Failed to get data: %1") |
1184 | | .arg(err)); |
1185 | | return false; |
| 1178 | QFile file(inputfile); |
| 1179 | if (file.open(QIODevice::ReadOnly)) |
| 1180 | data = file.readAll(); |
1186 | 1181 | } |
1187 | 1182 | |
1188 | | QFile file(inputfile); |
1189 | | file.open(QIODevice::ReadOnly); |
1190 | | QByteArray data = file.readAll(); |
1191 | | file.close(); |
| 1183 | if (data.isEmpty()) |
| 1184 | { |
| 1185 | QString err; |
| 1186 | |
| 1187 | data = DDPost(ddurl, startDate, endDate, err); |
| 1188 | |
| 1189 | if (!err.isEmpty()) |
| 1190 | { |
| 1191 | LOG(VB_GENERAL, LOG_ERR, LOC + |
| 1192 | QString("Failed to get data: %1").arg(err)); |
| 1193 | return false; |
| 1194 | } |
| 1195 | else if (!inputfile.isEmpty()) |
| 1196 | { |
| 1197 | QFile file(inputfile); |
| 1198 | if (file.open(QIODevice::WriteOnly)) |
| 1199 | file.write(data); |
| 1200 | } |
| 1201 | } |
1192 | 1202 | |
1193 | 1203 | if (data.isEmpty()) |
1194 | 1204 | { |
… |
… |
bool DataDirectProcessor::GrabData(const QDateTime &pstartDate, |
1196 | 1206 | return false; |
1197 | 1207 | } |
1198 | 1208 | |
1199 | | bool ok = true; |
| 1209 | QXmlInputSource xmlsource; |
| 1210 | xmlsource.setData(data); |
1200 | 1211 | |
1201 | | DDStructureParser ddhandler(*this); |
1202 | | QXmlInputSource xmlsource; |
1203 | 1212 | QXmlSimpleReader xmlsimplereader; |
1204 | | |
1205 | | xmlsource.setData(data); |
| 1213 | DDStructureParser ddhandler(*this); |
1206 | 1214 | xmlsimplereader.setContentHandler(&ddhandler); |
| 1215 | |
| 1216 | LOG(VB_GENERAL, LOG_INFO, LOC + |
| 1217 | "Parsing DataDirect XML, this can take a number of minutes"); |
| 1218 | |
1207 | 1219 | if (!xmlsimplereader.parse(xmlsource)) |
1208 | 1220 | { |
1209 | 1221 | LOG(VB_GENERAL, LOG_ERR, LOC + |
1210 | | "DataDirect XML failed to properly parse, downloaded listings " |
1211 | | "were probably corrupt."); |
1212 | | ok = false; |
| 1222 | "Failed to properly parse DataDirect XML"); |
| 1223 | return false; |
| 1224 | } |
| 1225 | else |
| 1226 | { |
| 1227 | LOG(VB_GENERAL, LOG_INFO, LOC + "Parsing DataDirect XML complete"); |
| 1228 | return true; |
1213 | 1229 | } |
1214 | | |
1215 | | return ok; |
1216 | 1230 | } |
1217 | 1231 | |
1218 | 1232 | bool DataDirectProcessor::GrabLineupsOnly(void) |
diff --git a/mythtv/libs/libmythtv/datadirect.h b/mythtv/libs/libmythtv/datadirect.h
index 1cc84a1..b945fe7 100644
a
|
b
|
class MTV_PUBLIC DataDirectProcessor |
414 | 414 | static bool Post(QString url, const PostList &list, QString documentFile, |
415 | 415 | QString inCookieFile, QString outCookieFile); |
416 | 416 | |
417 | | bool DDPost(QString url, QString &inputFilename, |
418 | | QDateTime pstartDate, QDateTime pendDate, |
419 | | QString &err_txt); |
| 417 | QByteArray DDPost( |
| 418 | const QString &url, |
| 419 | const QDateTime &startDate, const QDateTime &endDate, |
| 420 | QString &err_txt); |
420 | 421 | |
421 | 422 | |
422 | 423 | private: |