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