2 #include <QCoreApplication>
22 (QEvent::Type) QEvent::registerEventType();
25 (QEvent::Type) QEvent::registerEventType();
28 (QEvent::Type) QEvent::registerEventType();
37 QString url, QVariant data)
42 id->title = std::move(title);
43 id->data = std::move(data);
44 id->url = std::move(url);
84 bool exists = QFile::exists(sFilename);
85 if (!exists && !thumb->
url.isEmpty())
89 LOG(VB_GENERAL, LOG_ERR,
90 QString(
"MetadataImageDownload: failed to download thumbnail from: %1")
99 if (QFile::exists(sFilename) &&
m_parent)
101 LOG(VB_GENERAL, LOG_DEBUG,
102 QString(
"Threaded Image Thumbnail Download: %1")
104 thumb->
url = sFilename;
105 QCoreApplication::postEvent(
m_parent,
129 bool errored =
false;
130 for (DownloadMap::iterator i = downloads.begin();
131 i != downloads.end(); ++i)
137 if (lookup->
GetHost().isEmpty())
141 if (!dirPath.exists())
143 if (!dirPath.mkpath(path))
145 LOG(VB_GENERAL, LOG_ERR,
146 QString(
"Metadata Image Download: Unable to create "
147 "path %1, aborting download.").arg(path));
152 QString finalfile = path +
"/" +
filename;
153 QString oldurl = info.
url;
154 info.
url = finalfile;
157 QFile dest_file(finalfile);
158 if (dest_file.exists())
160 QFileInfo fi(finalfile);
165 LOG(VB_GENERAL, LOG_INFO,
166 QString(
"Metadata Image Download: %1 ->%2")
167 .arg(oldurl, finalfile));
172 bool didLoad = testImage.loadFromData(download);
175 LOG(VB_GENERAL, LOG_ERR,
176 QString(
"Tried to write %1, but it appears to be "
177 "an HTML redirect (filesize %2).")
178 .arg(oldurl).arg(download.size()));
183 if (dest_file.open(QIODevice::WriteOnly))
185 off_t size = dest_file.write(download,
188 if (size != download.size())
192 LOG(VB_GENERAL, LOG_ERR,
193 QString(
"Image Download: Error Writing Image "
194 "to file: %1").arg(finalfile));
204 QString finalfile = path +
filename;
205 QString oldurl = info.
url;
206 info.
url = finalfile;
208 bool onMaster =
false;
215 exists = !resolvedFN.isEmpty() && QFile::exists(resolvedFN);
228 if (exists && !onMaster)
230 QFileInfo fi(finalfile);
235 QFile::remove(resolvedFN);
237 LOG(VB_GENERAL, LOG_INFO,
238 QString(
"Metadata Image Download: %1 -> %2")
239 .arg(oldurl, finalfile));
244 bool didLoad = testImage.loadFromData(download);
247 LOG(VB_GENERAL, LOG_ERR,
248 QString(
"Tried to write %1, but it appears to be "
249 "an HTML redirect or corrupt file "
251 .arg(oldurl).arg(download.size()));
262 LOG(VB_GENERAL, LOG_ERR,
263 QString(
"Image Download: Failed to open "
264 "remote file (%1) for write. Does "
265 "Storage Group Exist?")
272 if (written != download.size())
277 LOG(VB_GENERAL, LOG_ERR,
278 QString(
"Image Download: Error Writing Image "
279 "to file: %1").arg(finalfile));
286 QFile dest_file(resolvedFN);
287 if (dest_file.open(QIODevice::WriteOnly))
289 off_t size = dest_file.write(download,
292 if (size != download.size())
296 LOG(VB_GENERAL, LOG_ERR,
297 QString(
"Image Download: Error Writing Image "
298 "to file: %1").arg(finalfile));
310 downloaded.insert(
type, info);
315 QCoreApplication::postEvent(
m_parent,
339 QDir dir(fileprefix);
341 dir.mkdir(fileprefix);
343 fileprefix +=
"/cache/metadata-thumbcache";
345 dir.setPath(fileprefix);;
347 dir.mkdir(fileprefix);
349 QByteArray titlearr(title.toLatin1());
350 QByteArray urlarr(url.toLatin1());
351 #if QT_VERSION < QT_VERSION_CHECK(6,0,0)
352 quint16 titleChecksum = qChecksum(titlearr.data(), titlearr.length());
353 quint16 urlChecksum = qChecksum(urlarr.data(), urlarr.length());
355 quint16 titleChecksum = qChecksum(titlearr);
356 quint16 urlChecksum = qChecksum(urlarr);
359 QString ext = QFileInfo(qurl.path()).suffix();
360 QString basefilename = QString(
"thumbnail_%1_%2.%3")
361 .arg(QString::number(urlChecksum),
362 QString::number(titleChecksum), ext);
364 QString outputfile = QString(
"%1/%2").arg(fileprefix, basefilename);
372 QString basefilename;
382 if (title.contains(
"/"))
383 title.replace(
"/",
"-");
384 if (title.contains(
"?"))
385 title.replace(
"?",
"");
386 if (title.contains(
"*"))
387 title.replace(
"*",
"");
388 inter = QString(
" Season %1").arg(QString::number(season));
390 inter += QString(
"x%1").arg(QString::number(episode));
399 inter = QString(
" Track %1").arg(QString::number(tracknum));
400 else if (!system.isEmpty())
401 inter = QString(
" (%1)").arg(system);
405 QString ext = QFileInfo(qurl.path()).suffix();
408 suffix =
"_coverart";
414 suffix =
"_screenshot";
418 suffix =
"_backcover";
420 suffix =
"_insidecover";
424 basefilename = title + inter + suffix +
"." + ext;
490 return "Screenshots";
498 QString cache = QString(
"%1/cache/metadata-thumbcache")
500 QDir cacheDir(cache);
501 QStringList thumbs = cacheDir.entryList(QDir::Files);
503 for (
auto i = thumbs.crbegin(); i != thumbs.crend(); ++i)
505 QString
filename = QString(
"%1/%2").arg(cache, *i);
507 QDateTime lastmod = fi.lastModified();
510 LOG(VB_GENERAL, LOG_DEBUG, QString(
"Deleting file %1")