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);
189 if (size != download.size())
193 LOG(VB_GENERAL, LOG_ERR,
194 QString(
"Image Download: Error Writing Image "
195 "to file: %1").arg(finalfile));
205 QString finalfile = path +
filename;
206 QString oldurl =
info.url;
207 info.url = finalfile;
209 bool onMaster =
false;
233 QFileInfo fi(finalfile);
239 QFile::remove(resolvedFN);
242 LOG(VB_GENERAL, LOG_INFO,
243 QString(
"Metadata Image Download: %1 -> %2")
244 .arg(oldurl, finalfile));
249 bool didLoad = testImage.loadFromData(download);
252 LOG(VB_GENERAL, LOG_ERR,
253 QString(
"Tried to write %1, but it appears to be "
254 "an HTML redirect or corrupt file "
256 .arg(oldurl).arg(download.size()));
267 LOG(VB_GENERAL, LOG_ERR,
268 QString(
"Image Download: Failed to open "
269 "remote file (%1) for write. Does "
270 "Storage Group Exist?")
275 off_t written = outFile.
Write(download.constData(),
277 if (written != download.size())
282 LOG(VB_GENERAL, LOG_ERR,
283 QString(
"Image Download: Error Writing Image "
284 "to file: %1").arg(finalfile));
291 QFile dest_file(resolvedFN);
292 if (dest_file.open(QIODevice::WriteOnly))
294 off_t size = dest_file.write(download);
296 if (size != download.size())
300 LOG(VB_GENERAL, LOG_ERR,
301 QString(
"Image Download: Error Writing Image "
302 "to file: %1").arg(finalfile));
319 QCoreApplication::postEvent(
m_parent,
343 QDir dir(fileprefix);
345 dir.mkdir(fileprefix);
347 fileprefix +=
"/cache/metadata-thumbcache";
349 dir.setPath(fileprefix);;
351 dir.mkdir(fileprefix);
353 QByteArray titlearr(title.toLatin1());
354 QByteArray urlarr(url.toLatin1());
355#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
356 quint16 titleChecksum = qChecksum(titlearr.data(), titlearr.length());
357 quint16 urlChecksum = qChecksum(urlarr.data(), urlarr.length());
359 quint16 titleChecksum = qChecksum(titlearr);
360 quint16 urlChecksum = qChecksum(urlarr);
363 QString ext = QFileInfo(qurl.path()).suffix();
364 QString basefilename = QString(
"thumbnail_%1_%2.%3")
365 .arg(QString::number(urlChecksum),
366 QString::number(titleChecksum), ext);
368 QString outputfile = QString(
"%1/%2").arg(fileprefix, basefilename);
376 QString basefilename;
386 if (title.contains(
"/"))
387 title.replace(
"/",
"-");
388 if (title.contains(
"?"))
389 title.replace(
"?",
"");
390 if (title.contains(
"*"))
391 title.replace(
"*",
"");
392 inter = QString(
" Season %1").arg(QString::number(season));
394 inter += QString(
"x%1").arg(QString::number(episode));
407 inter = QString(
" Track %1").arg(QString::number(tracknum));
408 else if (!system.isEmpty())
409 inter = QString(
" (%1)").arg(system);
413 QString ext = QFileInfo(qurl.path()).suffix();
416 suffix =
"_coverart";
422 suffix =
"_screenshot";
426 suffix =
"_backcover";
428 suffix =
"_insidecover";
432 basefilename = title + inter + suffix +
"." + ext;
498 return "Screenshots";
506 QString cache = QString(
"%1/cache/metadata-thumbcache")
508 QDir cacheDir(cache);
509 QStringList thumbs = cacheDir.entryList(QDir::Files);
511 for (
auto i = thumbs.crbegin(); i != thumbs.crend(); ++i)
513 QString
filename = QString(
"%1/%2").arg(cache, *i);
515 QDateTime lastmod = fi.lastModified();
518 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.