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);
89 LOG(VB_GENERAL, LOG_ERR,
90 QString(
"MetadataImageDownload: failed to download thumbnail from: %1")
101 LOG(VB_GENERAL, LOG_DEBUG,
102 QString(
"Threaded Image Thumbnail Download: %1")
104 thumb->
url = sFilename;
105 QCoreApplication::postEvent(
m_parent,
131 bool errored =
false;
132 for (DownloadMap::iterator i = downloads.begin();
133 i != downloads.end(); ++i)
139 if (lookup->
GetHost().isEmpty())
143 if (!dirPath.exists())
145 if (!dirPath.mkpath(path))
147 LOG(VB_GENERAL, LOG_ERR,
148 QString(
"Metadata Image Download: Unable to create "
149 "path %1, aborting download.").arg(path));
154 QString finalfile = path +
"/" +
filename;
155 QString oldurl =
info.url;
156 info.url = finalfile;
159 QFile dest_file(finalfile);
160 if (dest_file.exists())
162 QFileInfo fi(finalfile);
167 LOG(VB_GENERAL, LOG_INFO,
168 QString(
"Metadata Image Download: %1 ->%2")
169 .arg(oldurl, finalfile));
174 bool didLoad = testImage.loadFromData(download);
177 LOG(VB_GENERAL, LOG_ERR,
178 QString(
"Tried to write %1, but it appears to be "
179 "an HTML redirect (filesize %2).")
180 .arg(oldurl).arg(download.size()));
185 if (dest_file.open(QIODevice::WriteOnly))
187 off_t size = dest_file.write(download,
190 if (size != download.size())
194 LOG(VB_GENERAL, LOG_ERR,
195 QString(
"Image Download: Error Writing Image "
196 "to file: %1").arg(finalfile));
206 QString finalfile = path +
filename;
207 QString oldurl =
info.url;
208 info.url = finalfile;
210 bool onMaster =
false;
234 QFileInfo fi(finalfile);
240 QFile::remove(resolvedFN);
243 LOG(VB_GENERAL, LOG_INFO,
244 QString(
"Metadata Image Download: %1 -> %2")
245 .arg(oldurl, finalfile));
250 bool didLoad = testImage.loadFromData(download);
253 LOG(VB_GENERAL, LOG_ERR,
254 QString(
"Tried to write %1, but it appears to be "
255 "an HTML redirect or corrupt file "
257 .arg(oldurl).arg(download.size()));
268 LOG(VB_GENERAL, LOG_ERR,
269 QString(
"Image Download: Failed to open "
270 "remote file (%1) for write. Does "
271 "Storage Group Exist?")
278 if (written != download.size())
283 LOG(VB_GENERAL, LOG_ERR,
284 QString(
"Image Download: Error Writing Image "
285 "to file: %1").arg(finalfile));
292 QFile dest_file(resolvedFN);
293 if (dest_file.open(QIODevice::WriteOnly))
295 off_t size = dest_file.write(download,
298 if (size != download.size())
302 LOG(VB_GENERAL, LOG_ERR,
303 QString(
"Image Download: Error Writing Image "
304 "to file: %1").arg(finalfile));
321 QCoreApplication::postEvent(
m_parent,
345 QDir dir(fileprefix);
347 dir.mkdir(fileprefix);
349 fileprefix +=
"/cache/metadata-thumbcache";
351 dir.setPath(fileprefix);;
353 dir.mkdir(fileprefix);
355 QByteArray titlearr(title.toLatin1());
356 QByteArray urlarr(url.toLatin1());
357#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
358 quint16 titleChecksum = qChecksum(titlearr.data(), titlearr.length());
359 quint16 urlChecksum = qChecksum(urlarr.data(), urlarr.length());
361 quint16 titleChecksum = qChecksum(titlearr);
362 quint16 urlChecksum = qChecksum(urlarr);
365 QString ext = QFileInfo(qurl.path()).suffix();
366 QString basefilename = QString(
"thumbnail_%1_%2.%3")
367 .arg(QString::number(urlChecksum),
368 QString::number(titleChecksum), ext);
370 QString outputfile = QString(
"%1/%2").arg(fileprefix, basefilename);
378 QString basefilename;
388 if (title.contains(
"/"))
389 title.replace(
"/",
"-");
390 if (title.contains(
"?"))
391 title.replace(
"?",
"");
392 if (title.contains(
"*"))
393 title.replace(
"*",
"");
394 inter = QString(
" Season %1").arg(QString::number(season));
396 inter += QString(
"x%1").arg(QString::number(episode));
409 inter = QString(
" Track %1").arg(QString::number(tracknum));
410 else if (!system.isEmpty())
411 inter = QString(
" (%1)").arg(system);
415 QString ext = QFileInfo(qurl.path()).suffix();
418 suffix =
"_coverart";
424 suffix =
"_screenshot";
428 suffix =
"_backcover";
430 suffix =
"_insidecover";
434 basefilename = title + inter + suffix +
"." + ext;
500 return "Screenshots";
508 QString cache = QString(
"%1/cache/metadata-thumbcache")
510 QDir cacheDir(cache);
511 QStringList thumbs = cacheDir.entryList(QDir::Files);
513 for (
auto i = thumbs.crbegin(); i != thumbs.crend(); ++i)
515 QString
filename = QString(
"%1/%2").arg(cache, *i);
517 QDateTime lastmod = fi.lastModified();
520 LOG(VB_GENERAL, LOG_DEBUG, QString(
"Deleting file %1")
static const Type kEventType
static const Type kEventType
bool isRunning(void) const
void RunProlog(void)
Sets up a thread, call this if you reimplement run().
void start(QThread::Priority p=QThread::InheritPriority)
Tell MThread to start running the thread in the near future.
void RunEpilog(void)
Cleans up a thread's resources, call this if you reimplement run().
bool wait(std::chrono::milliseconds time=std::chrono::milliseconds::max())
Wait for the MThread to exit, with a maximum timeout.
bool IsThisHost(const QString &addr)
is this address mapped to this host
QString GetSetting(const QString &key, const QString &defaultval="")
int GetBackendServerPort(void)
Returns the locally defined backend control port.
static QString GenMythURL(const QString &host=QString(), int port=0, QString path=QString(), const QString &storageGroup=QString())
bool IsMasterBackend(void)
is this the actual MBE process
bool download(const QString &url, const QString &dest, bool reload=false)
Downloads a URL to a file in blocking mode.
void RemoveFromCacheByFile(const QString &File)
RefCountHandler< T > takeFirstAndDecr(void)
Removes the first item in the list and returns it.
virtual int DecrRef(void)
Decrements reference count and deletes on 0.
static bool DeleteFile(const QString &url)
static bool Exists(const QString &url, struct stat *fileinfo)
int Write(const void *data, int size)
QString FindFile(const QString &filename)
QString FindNextDirMostFree(void)
static const Type kEventType
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
MythDownloadManager * GetMythDownloadManager(void)
Gets the pointer to the MythDownloadManager singleton.
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
MythUIHelper * GetMythUI()
QDateTime current(bool stripped)
Returns current Date and Time in UTC.