6#include <QCoreApplication>
25 (QEvent::Type) QEvent::registerEventType();
28 (QEvent::Type) QEvent::registerEventType();
31 (QEvent::Type) QEvent::registerEventType();
40 QString url, QVariant data)
45 id->title = std::move(title);
46 id->data = std::move(data);
47 id->url = std::move(url);
92 LOG(VB_GENERAL, LOG_ERR,
93 QString(
"MetadataImageDownload: failed to download thumbnail from: %1")
104 LOG(VB_GENERAL, LOG_DEBUG,
105 QString(
"Threaded Image Thumbnail Download: %1")
107 thumb->
url = sFilename;
108 QCoreApplication::postEvent(
m_parent,
134 bool errored =
false;
135 for (DownloadMap::iterator i = downloads.begin();
136 i != downloads.end(); ++i)
142 if (lookup->
GetHost().isEmpty())
146 if (!dirPath.exists())
148 if (!dirPath.mkpath(path))
150 LOG(VB_GENERAL, LOG_ERR,
151 QString(
"Metadata Image Download: Unable to create "
152 "path %1, aborting download.").arg(path));
157 QString finalfile = path +
"/" +
filename;
158 QString oldurl =
info.url;
159 info.url = finalfile;
162 QFile dest_file(finalfile);
163 if (dest_file.exists())
165 QFileInfo fi(finalfile);
170 LOG(VB_GENERAL, LOG_INFO,
171 QString(
"Metadata Image Download: %1 ->%2")
172 .arg(oldurl, finalfile));
177 bool didLoad = testImage.loadFromData(download);
180 LOG(VB_GENERAL, LOG_ERR,
181 QString(
"Tried to write %1, but it appears to be "
182 "an HTML redirect (filesize %2).")
183 .arg(oldurl).arg(download.size()));
188 if (dest_file.open(QIODevice::WriteOnly))
190 off_t size = dest_file.write(download);
192 if (size != download.size())
196 LOG(VB_GENERAL, LOG_ERR,
197 QString(
"Image Download: Error Writing Image "
198 "to file: %1").arg(finalfile));
208 QString finalfile = path +
filename;
209 QString oldurl =
info.url;
210 info.url = finalfile;
212 bool onMaster =
false;
236 QFileInfo fi(finalfile);
242 QFile::remove(resolvedFN);
245 LOG(VB_GENERAL, LOG_INFO,
246 QString(
"Metadata Image Download: %1 -> %2")
247 .arg(oldurl, finalfile));
252 bool didLoad = testImage.loadFromData(download);
255 LOG(VB_GENERAL, LOG_ERR,
256 QString(
"Tried to write %1, but it appears to be "
257 "an HTML redirect or corrupt file "
259 .arg(oldurl).arg(download.size()));
270 LOG(VB_GENERAL, LOG_ERR,
271 QString(
"Image Download: Failed to open "
272 "remote file (%1) for write. Does "
273 "Storage Group Exist?")
278 off_t written = outFile.
Write(download.constData(),
280 if (written != download.size())
285 LOG(VB_GENERAL, LOG_ERR,
286 QString(
"Image Download: Error Writing Image "
287 "to file: %1").arg(finalfile));
294 QFile dest_file(resolvedFN);
295 if (dest_file.open(QIODevice::WriteOnly))
297 off_t size = dest_file.write(download);
299 if (size != download.size())
303 LOG(VB_GENERAL, LOG_ERR,
304 QString(
"Image Download: Error Writing Image "
305 "to file: %1").arg(finalfile));
322 QCoreApplication::postEvent(
m_parent,
346 QDir dir(fileprefix);
348 dir.mkdir(fileprefix);
350 fileprefix +=
"/cache/metadata-thumbcache";
352 dir.setPath(fileprefix);;
354 dir.mkdir(fileprefix);
356 QByteArray titlearr(title.toLatin1());
357 QByteArray urlarr(url.toLatin1());
358#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
359 quint16 titleChecksum = qChecksum(titlearr.data(), titlearr.length());
360 quint16 urlChecksum = qChecksum(urlarr.data(), urlarr.length());
362 quint16 titleChecksum = qChecksum(titlearr);
363 quint16 urlChecksum = qChecksum(urlarr);
366 QString ext = QFileInfo(qurl.path()).suffix();
367 QString basefilename = QString(
"thumbnail_%1_%2.%3")
368 .arg(QString::number(urlChecksum),
369 QString::number(titleChecksum), ext);
371 QString outputfile = QString(
"%1/%2").arg(fileprefix, basefilename);
379 QString basefilename;
389 if (title.contains(
"/"))
390 title.replace(
"/",
"-");
391 if (title.contains(
"?"))
392 title.replace(
"?",
"");
393 if (title.contains(
"*"))
394 title.replace(
"*",
"");
395 inter = QString(
" Season %1").arg(QString::number(season));
397 inter += QString(
"x%1").arg(QString::number(episode));
410 inter = QString(
" Track %1").arg(QString::number(tracknum));
411 else if (!system.isEmpty())
412 inter = QString(
" (%1)").arg(system);
416 QString ext = QFileInfo(qurl.path()).suffix();
419 suffix =
"_coverart";
425 suffix =
"_screenshot";
429 suffix =
"_backcover";
431 suffix =
"_insidecover";
435 basefilename = title + inter + suffix +
"." + ext;
501 return "Screenshots";
509 QString cache = QString(
"%1/cache/metadata-thumbcache")
511 QDir cacheDir(cache);
512 QStringList thumbs = cacheDir.entryList(QDir::Files);
514 for (
const auto & thumb : std::ranges::reverse_view(thumbs))
516 QString
filename = QString(
"%1/%2").arg(cache, thumb);
518 QDateTime lastmod = fi.lastModified();
521 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.