Go to the documentation of this file.
6 #include <QRegularExpression>
16 #include <libavformat/avformat.h>
17 #include <libavcodec/avcodec.h>
24 const static QRegularExpression
badChars1 { R
"((/|\\|:|'|"|\?|\|))" };
25 const static QRegularExpression
badChars2 { R
"((/|\\|:|'|\,|\!|\(|\)|"|\?|\|))" };
34 QString
findIcon(
const QString &
type,
const QString &name,
bool ignoreCache)
36 LOG(VB_FILE, LOG_INFO, QString(
"findicon: looking for type: %1, name: %2").arg(
type, name));
40 QMap<QString, QString>::iterator i =
iconMap.find(
type + name);
43 LOG(VB_FILE, LOG_INFO, QString(
"findicon: found in cache %1").arg(i.value()));
50 QString
file = QString(
"/Icons/%1/%2").arg(
type, cleanName);
51 QString imageExtensions =
"(jpg|jpeg|png|gif)";
55 if (!fileList.isEmpty())
57 LOG(VB_FILE, LOG_INFO, QString(
"findicon: found %1 icons using %2").arg(fileList.size()).arg(fileList[0]));
64 LOG(VB_FILE, LOG_INFO, QString(
"findicon: not found type: %1, name: %2").arg(
type, name));
73 static const QRegularExpression kBadFilenameCharRE { R
"((\\|:|'|"|\?|\|))" };
74 token.replace(kBadFilenameCharRE, QString("_"));
84 static const QRegularExpression rx_ws(
"\\s{1,}");
85 static const QRegularExpression rx(
"^(.*?)(GENRE|ARTIST|ALBUM|TRACK|TITLE|YEAR)");
86 auto match = rx.match(fntempl);
87 while (match.hasMatch())
91 if ((match.captured(2) ==
"GENRE") &&
92 (!track->
Genre().isEmpty()))
94 else if ((match.captured(2) ==
"ARTIST") &&
97 else if ((match.captured(2) ==
"ALBUM") &&
98 (!track->
Album().isEmpty()))
100 else if ((match.captured(2) ==
"TRACK") && (track->
Track() >= 0))
102 else if ((match.captured(2) ==
"TITLE") &&
105 else if ((match.captured(2) ==
"YEAR") && (track->
Year() >= 0))
107 fntempl.remove(0, match.capturedLength());
108 match = rx.match(fntempl);
117 QString tempstr = QString::number(track->
Track(), 10);
120 LOG(VB_GENERAL, LOG_ERR,
"Invalid file storage definition.");
126 bool isNewTune(
const QString& artist,
const QString& album,
const QString& title)
129 QString matchartist = artist;
130 QString matchalbum = album;
131 QString matchtitle = title;
133 if (! matchartist.isEmpty())
134 matchartist.replace(
badChars2, QString(
"_"));
136 if (! matchalbum.isEmpty())
137 matchalbum.replace(
badChars2, QString(
"_"));
139 if (! matchtitle.isEmpty())
140 matchtitle.replace(
badChars2, QString(
"_"));
143 QString queryString(
"SELECT filename, artist_name,"
144 " album_name, name, song_id "
146 "LEFT JOIN music_artists"
147 " ON music_songs.artist_id=music_artists.artist_id "
148 "LEFT JOIN music_albums"
149 " ON music_songs.album_id=music_albums.album_id "
150 "WHERE artist_name LIKE :ARTIST "
151 "AND album_name LIKE :ALBUM "
152 "AND name LIKE :TITLE "
153 "ORDER BY artist_name, album_name,"
154 " name, song_id, filename");
168 return query.
size() <= 0;
bool isActive(void) const
QSqlQuery wrapper that fetches a DB connection from the connection pool.
QString findIcon(const QString &type, const QString &name, bool ignoreCache)
find an image for a artist or genre
QString GetMasterHostName(void)
bool exec(void)
Wrap QSqlQuery::exec() so we can display SQL.
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
static QStringList FindFileList(const QString &filename, const QString &host, const QString &storageGroup, bool useRegex=false, bool allowFallback=false)
Search all BE's for files in the give storage group.
bool isNewTune(const QString &artist, const QString &album, const QString &title)
try to find a track in the db using the given artist, album and title
QString fixFilename(const QString &filename)
remove any bad filename characters
QString filenameFromMetadata(MusicMetadata *track)
create a filename using the template in the settings and a MusicMetadata object
static MSqlQueryInfo InitCon(ConnectionReuse _reuse=kNormalConnection)
Only use this in combination with MSqlQuery constructor.
static void DBError(const QString &where, const MSqlQuery &query)
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
bool GetBoolSetting(const QString &key, bool defaultval=false)
const static QRegularExpression badChars1
static QMap< QString, QString > iconMap
void bindValue(const QString &placeholder, const QVariant &val)
Add a single binding.
QString fixFileToken_sl(QString token)
remove any bad filename characters (leaving '/' untouched)
const static QRegularExpression badChars2
QString GetSetting(const QString &key, const QString &defaultval="")
bool prepare(const QString &query)
QSqlQuery::prepare() is not thread safe in Qt <= 3.3.2.