Go to the documentation of this file.
2 #include <QCoreApplication>
21 (QEvent::Type) QEvent::registerEventType();
24 (QEvent::Type) QEvent::registerEventType();
27 (QEvent::Type) QEvent::registerEventType();
36 QString url, QVariant data)
41 id->title = std::move(
title);
42 id->data = std::move(data);
43 id->url = std::move(url);
83 bool exists = QFile::exists(sFilename);
84 if (!exists && !thumb->
url.isEmpty())
88 LOG(VB_GENERAL, LOG_ERR,
89 QString(
"MetadataImageDownload: failed to download thumbnail from: %1")
98 if (QFile::exists(sFilename) &&
m_parent)
100 LOG(VB_GENERAL, LOG_DEBUG,
101 QString(
"Threaded Image Thumbnail Download: %1")
103 thumb->
url = sFilename;
104 QCoreApplication::postEvent(
m_parent,
128 bool errored =
false;
129 for (DownloadMap::iterator i = downloads.begin();
130 i != downloads.end(); ++i)
136 if (lookup->
GetHost().isEmpty())
140 if (!dirPath.exists())
142 if (!dirPath.mkpath(path))
144 LOG(VB_GENERAL, LOG_ERR,
145 QString(
"Metadata Image Download: Unable to create "
146 "path %1, aborting download.").
arg(path));
151 QString finalfile = path +
"/" +
filename;
152 QString oldurl = info.
url;
153 info.
url = finalfile;
156 QFile dest_file(finalfile);
157 if (dest_file.exists())
159 QFileInfo fi(finalfile);
164 LOG(VB_GENERAL, LOG_INFO,
165 QString(
"Metadata Image Download: %1 ->%2")
166 .
arg(oldurl).
arg(finalfile));
171 bool didLoad = testImage.loadFromData(download);
174 LOG(VB_GENERAL, LOG_ERR,
175 QString(
"Tried to write %1, but it appears to be "
176 "an HTML redirect (filesize %2).")
177 .
arg(oldurl).
arg(download.size()));
182 if (dest_file.open(QIODevice::WriteOnly))
184 off_t size = dest_file.write(download,
187 if (size != download.size())
191 LOG(VB_GENERAL, LOG_ERR,
192 QString(
"Image Download: Error Writing Image "
193 "to file: %1").
arg(finalfile));
203 QString finalfile = path +
filename;
204 QString oldurl = info.
url;
205 info.
url = finalfile;
207 bool onMaster =
false;
214 exists = !resolvedFN.isEmpty() && QFile::exists(resolvedFN);
227 if (exists && !onMaster)
229 QFileInfo fi(finalfile);
234 QFile::remove(resolvedFN);
236 LOG(VB_GENERAL, LOG_INFO,
237 QString(
"Metadata Image Download: %1 -> %2")
238 .
arg(oldurl).
arg(finalfile));
243 bool didLoad = testImage.loadFromData(download);
246 LOG(VB_GENERAL, LOG_ERR,
247 QString(
"Tried to write %1, but it appears to be "
248 "an HTML redirect or corrupt file "
250 .
arg(oldurl).
arg(download.size()));
261 LOG(VB_GENERAL, LOG_ERR,
262 QString(
"Image Download: Failed to open "
263 "remote file (%1) for write. Does "
264 "Storage Group Exist?")
271 if (written != download.size())
276 LOG(VB_GENERAL, LOG_ERR,
277 QString(
"Image Download: Error Writing Image "
278 "to file: %1").
arg(finalfile));
285 QFile dest_file(resolvedFN);
286 if (dest_file.open(QIODevice::WriteOnly))
288 off_t size = dest_file.write(download,
291 if (size != download.size())
295 LOG(VB_GENERAL, LOG_ERR,
296 QString(
"Image Download: Error Writing Image "
297 "to file: %1").
arg(finalfile));
309 downloaded.insert(
type, info);
314 QCoreApplication::postEvent(
m_parent,
338 QDir
dir(fileprefix);
340 dir.mkdir(fileprefix);
342 fileprefix +=
"/cache/metadata-thumbcache";
344 dir.setPath(fileprefix);;
346 dir.mkdir(fileprefix);
348 QByteArray titlearr(
title.toLatin1());
349 quint16 titleChecksum = qChecksum(titlearr.data(), titlearr.length());
350 QByteArray urlarr(url.toLatin1());
351 quint16 urlChecksum = qChecksum(urlarr.data(), urlarr.length());
353 QString ext = QFileInfo(qurl.path()).suffix();
354 QString basefilename = QString(
"thumbnail_%1_%2.%3")
355 .arg(QString::number(urlChecksum))
356 .arg(QString::number(titleChecksum)).arg(ext);
358 QString outputfile = QString(
"%1/%2").arg(fileprefix).arg(basefilename);
366 QString basefilename;
376 if (
title.contains(
"/"))
377 title.replace(
"/",
"-");
378 if (
title.contains(
"?"))
379 title.replace(
"?",
"");
380 if (
title.contains(
"*"))
381 title.replace(
"*",
"");
382 inter = QString(
" Season %1").arg(QString::number(season));
384 inter += QString(
"x%1").arg(QString::number(episode));
394 inter = QString(
" Track %1").arg(QString::number(tracknum));
395 else if (!system.isEmpty())
396 inter = QString(
" (%1)").arg(system);
400 QString ext = QFileInfo(qurl.path()).suffix();
403 suffix =
"_coverart";
409 suffix =
"_screenshot";
413 suffix =
"_backcover";
415 suffix =
"_insidecover";
419 basefilename =
title + inter + suffix +
"." + ext;
485 return "Screenshots";
493 QString cache = QString(
"%1/cache/metadata-thumbcache")
495 QDir cacheDir(cache);
496 QStringList thumbs = cacheDir.entryList(QDir::Files);
498 for (
auto i = thumbs.crbegin(); i != thumbs.crend(); ++i)
500 QString
filename = QString(
"%1/%2").arg(cache).arg(*i);
502 QDateTime lastmod = fi.lastModified();
505 LOG(VB_GENERAL, LOG_DEBUG, QString(
"Deleting file %1")
void start(QThread::Priority p=QThread::InheritPriority)
Tell MThread to start running the thread in the near future.
virtual int DecrRef(void)
Decrements reference count and deletes on 0.
static bool Exists(const QString &url, struct stat *fileinfo)
RefCountHandler< T > takeFirstAndDecr(void)
Removes the first item in the list and returns it.
QString FindFile(const QString &filename)
arg(title).arg(filename).arg(doDelete))
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
void RunProlog(void)
Sets up a thread, call this if you reimplement run().
int Write(const void *data, int size)
QDateTime current(bool stripped)
Returns current Date and Time in UTC.
bool IsMasterBackend(void)
is this the actual MBE process
static QString GenMythURL(const QString &host=QString(), int port=0, QString path=QString(), const QString &storageGroup=QString())
int GetBackendServerPort(void)
Returns the locally defined backend control port.
void RemoveFromCacheByFile(const QString &File)
void RunEpilog(void)
Cleans up a thread's resources, call this if you reimplement run().
bool download(const QString &url, const QString &dest, bool reload=false)
Downloads a URL to a file in blocking mode.
static bool DeleteFile(const QString &url)
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
QString FindNextDirMostFree(void)
bool isRunning(void) const
bool IsThisHost(const QString &addr)
is this address mapped to this host
bool wait(unsigned long time=ULONG_MAX)
Wait for the MThread to exit, with a maximum timeout.
MythUIHelper * GetMythUI()
QString GetSetting(const QString &key, const QString &defaultval="")
MythDownloadManager * GetMythDownloadManager(void)
Gets the pointer to the MythDownloadManager singleton.