MythTV master
videometadatautil.cpp
Go to the documentation of this file.
1#include <QChar> // Fix Qt6 GCC SFINAE warning
2#include <QReadWriteLock>
3#include <QHash>
4#include <QUrl>
5
8
9#include "videometadatautil.h"
10
11#define LOC QString("VideoMetaDataUtil: ")
12
13static QReadWriteLock art_path_map_lock;
14using ArtPair = QPair< QString, QString >;
15static QMultiHash<QString, ArtPair> art_path_map;
16using ArtList = QList<ArtPair>;
17
18QString VideoMetaDataUtil::GetArtPath(const QString &pathname,
19 const QString &type)
20{
21 QString basename = pathname.section('/', -1);
22
23 if (basename == pathname)
24 {
25 LOG(VB_GENERAL, LOG_WARNING, LOC +
26 "Programmer Error: Cannot determine art path\n\t\t\t"
27 "until the ProgramInfo pathname has been fully resolved.");
28 return {};
29 }
30
31 art_path_map_lock.lockForRead();
32 ArtList ret(art_path_map.values(basename));
33 art_path_map_lock.unlock();
34 // cppcheck-suppress unassignedVariable
35 for (const auto & [arttype, artpath] : std::as_const(ret))
36 {
37 if (arttype == type)
38 return artpath;
39 }
40
41 QString fn = basename;
42 fn.prepend("%");
43
44 QString dbcolumn;
45 if (type == "Coverart")
46 dbcolumn = "coverfile";
47 else if (type == "Fanart")
48 dbcolumn = "fanart";
49 else if (type == "Banners")
50 dbcolumn = "banner";
51 else if (type == "Screenshots")
52 dbcolumn = "screenshot";
53
54 QString querystr = QString("SELECT %1 "
55 "FROM videometadata WHERE filename "
56 "LIKE :FILENAME").arg(dbcolumn);
57
59 query.prepare(querystr);
60 query.bindValue(":FILENAME", fn);
61
62 QString artpath;
63 if (query.exec() && query.next())
64 artpath = query.value(0).toString();
65
66 if (!artpath.startsWith('/') && pathname.startsWith("myth://"))
67 {
68 const QString& workURL = pathname;
69 QUrl baseURL(workURL);
70 baseURL.setUserName(type);
71 QString finalURL =
72 baseURL.toString(QUrl::RemovePath) + '/' + artpath;
73 artpath = finalURL;
74 }
75
76 ArtPair ins(type, artpath);
77 art_path_map_lock.lockForWrite();
78 art_path_map.insert(basename, ins);
79 art_path_map_lock.unlock();
80
81 return artpath;
82}
QSqlQuery wrapper that fetches a DB connection from the connection pool.
Definition: mythdbcon.h:129
bool prepare(const QString &query)
QSqlQuery::prepare() is not thread safe in Qt <= 3.3.2.
Definition: mythdbcon.cpp:839
QVariant value(int i) const
Definition: mythdbcon.h:205
bool exec(void)
Wrap QSqlQuery::exec() so we can display SQL.
Definition: mythdbcon.cpp:620
void bindValue(const QString &placeholder, const QVariant &val)
Add a single binding.
Definition: mythdbcon.cpp:890
bool next(void)
Wrap QSqlQuery::next() so we can display the query results.
Definition: mythdbcon.cpp:814
static MSqlQueryInfo InitCon(ConnectionReuse _reuse=kNormalConnection)
Only use this in combination with MSqlQuery constructor.
Definition: mythdbcon.cpp:552
static QString GetArtPath(const QString &pathname, const QString &type)
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
#define LOC
QList< ArtPair > ArtList
static QMultiHash< QString, ArtPair > art_path_map
QPair< QString, QString > ArtPair
static QReadWriteLock art_path_map_lock