5 #include <QApplication>
8 #include <QDomDocument>
9 #include <QScopedPointer>
52 const UrlList &lurls, QString llogourl, QString lgenre, QString lmetaformat,
53 QString lcountry, QString llanguage, QString lformat)
54 : m_genre(std::move(lgenre)),
55 m_format(std::move(lformat)),
58 m_broadcaster(std::move(lbroadcaster)),
59 m_channel(std::move(lchannel)),
60 m_description(std::move(ldescription)),
62 m_logoUrl(std::move(llogourl)),
63 m_metaFormat(std::move(lmetaformat)),
64 m_country(std::move(lcountry)),
65 m_language(std::move(llanguage))
189 query.
prepare(
"UPDATE music_songs set rating = :RATING , "
190 "numplays = :PLAYCOUNT , lastplay = :LASTPLAY "
191 "where song_id = :ID ;");
209 query.
prepare(
"UPDATE music_songs SET hostname = :HOSTNAME "
210 "WHERE song_id = :ID ;");
222 QString sqldir =
filename.section(
'/', 0, -2);
224 QString sqlfilename =
filename.section(
'/', -1);
228 "SELECT song_id FROM music_songs "
229 "LEFT JOIN music_directories ON music_songs.directory_id=music_directories.directory_id "
230 "WHERE music_songs.filename = :FILENAME "
231 "AND music_directories.path = :DIRECTORY ;");
232 query.
bindValue(
":FILENAME", sqlfilename);
243 LOG(VB_GENERAL, LOG_WARNING,
244 QString(
"MusicMetadata::createFromFilename: Could not find '%1'")
249 int songID = query.
value(0).toInt();
258 query.
prepare(
"SELECT music_artists.artist_name, "
259 "music_comp_artists.artist_name AS compilation_artist, "
260 "music_albums.album_name, music_songs.name, music_genres.genre, "
261 "music_songs.year, music_songs.track, music_songs.length, "
262 "music_songs.song_id, music_songs.rating, music_songs.numplays, "
263 "music_songs.lastplay, music_albums.compilation, music_songs.format, "
264 "music_songs.track_count, music_songs.size, music_songs.date_entered, "
265 "music_songs.disc_number, music_songs.disc_count, "
266 "CONCAT_WS('/', music_directories.path, music_songs.filename) AS filename, "
267 "music_songs.hostname "
269 "LEFT JOIN music_directories ON music_songs.directory_id=music_directories.directory_id "
270 "LEFT JOIN music_artists ON music_songs.artist_id=music_artists.artist_id "
271 "LEFT JOIN music_albums ON music_songs.album_id=music_albums.album_id "
272 "LEFT JOIN music_artists AS music_comp_artists ON music_albums.artist_id=music_comp_artists.artist_id "
273 "LEFT JOIN music_genres ON music_songs.genre_id=music_genres.genre_id "
274 "WHERE music_songs.song_id = :SONGID; ");
280 mdata->m_artist = query.
value(0).toString();
281 mdata->m_compilationArtist = query.
value(1).toString();
282 mdata->m_album = query.
value(2).toString();
283 mdata->m_title = query.
value(3).toString();
284 mdata->m_genre = query.
value(4).toString();
285 mdata->m_year = query.
value(5).toInt();
286 mdata->m_trackNum = query.
value(6).toInt();
287 mdata->m_length = std::chrono::milliseconds(query.
value(7).toInt());
288 mdata->m_id = query.
value(8).toUInt();
289 mdata->m_rating = query.
value(9).toInt();
290 mdata->m_playCount = query.
value(10).toInt();
291 mdata->m_lastPlay = query.
value(11).toDateTime();
292 mdata->m_compilation = (query.
value(12).toInt() > 0);
293 mdata->m_format = query.
value(13).toString();
294 mdata->m_trackCount = query.
value(14).toInt();
295 mdata->m_fileSize = query.
value(15).toULongLong();
296 mdata->m_dateAdded = query.
value(16).toDateTime();
297 mdata->m_discNum = query.
value(17).toInt();
298 mdata->m_discCount = query.
value(18).toInt();
299 mdata->m_filename = query.
value(19).toString();
300 mdata->m_hostname = query.
value(20).toString();
301 mdata->ensureSortFields();
303 if (!QHostAddress(mdata->m_hostname).isNull())
305 mdata->m_hostname =
"";
306 mdata->saveHostname();
319 GetMythDB()->ClearSetting(
"MusicStreamListModified");
324 LOG(VB_GENERAL, LOG_ERR,
"MusicMetadata: looks like we are already updating the radio streams list");
328 QByteArray compressedData;
329 QByteArray uncompressedData;
338 LOG(VB_GENERAL, LOG_INFO,
"MusicMetadata: radio streams list is already up to date");
344 LOG(VB_GENERAL, LOG_INFO,
"MusicMetadata: downloading radio streams list");
349 LOG(VB_GENERAL, LOG_ERR,
"MusicMetadata: failed to download radio stream list");
360 #if QT_VERSION < QT_VERSION_CHECK(6,5,0)
365 if (!domDoc.setContent(uncompressedData,
false, &errorMsg,
366 &errorLine, &errorColumn))
368 LOG(VB_GENERAL, LOG_ERR,
369 "MusicMetadata: Could not read content of streams.xml" +
371 QString(
"\n\t\t\tat line: %1 column: %2 msg: %3")
372 .arg(errorLine).arg(errorColumn).arg(errorMsg));
377 auto parseResult = domDoc.setContent(uncompressedData);
380 LOG(VB_GENERAL, LOG_ERR,
381 "MusicMetadata: Could not read content of streams.xml" +
383 QString(
"\n\t\t\tat line: %1 column: %2 msg: %3")
384 .arg(parseResult.errorLine).arg(parseResult.errorColumn)
385 .arg(parseResult.errorMessage));
392 query.
prepare(
"DELETE FROM music_streams;");
400 LOG(VB_GENERAL, LOG_INFO,
"MusicMetadata: processing radio streams list");
402 QDomNodeList itemList = domDoc.elementsByTagName(
"item");
405 for (
int i = 0; i < itemList.count(); i++)
407 itemNode = itemList.item(i);
409 query.
prepare(
"INSERT INTO music_streams (broadcaster, channel, description, url1, url2, url3, url4, url5,"
410 " logourl, genre, metaformat, country, language) "
411 "VALUES (:BROADCASTER, :CHANNEL, :DESC, :URL1, :URL2, :URL3, :URL4, :URL5,"
412 " :LOGOURL, :GENRE, :META, :COUNTRY, :LANG);");
414 query.
bindValue(
":BROADCASTER", itemNode.namedItem(QString(
"broadcaster")).toElement().text());
415 query.
bindValue(
":CHANNEL", itemNode.namedItem(QString(
"channel")).toElement().text());
416 query.
bindValue(
":DESC", itemNode.namedItem(QString(
"description")).toElement().text());
417 query.
bindValue(
":URL1", itemNode.namedItem(QString(
"url1")).toElement().text());
418 query.
bindValue(
":URL2", itemNode.namedItem(QString(
"url2")).toElement().text());
419 query.
bindValue(
":URL3", itemNode.namedItem(QString(
"url3")).toElement().text());
420 query.
bindValue(
":URL4", itemNode.namedItem(QString(
"url4")).toElement().text());
421 query.
bindValue(
":URL5", itemNode.namedItem(QString(
"url5")).toElement().text());
422 query.
bindValue(
":LOGOURL", itemNode.namedItem(QString(
"logourl")).toElement().text());
423 query.
bindValue(
":GENRE", itemNode.namedItem(QString(
"genre")).toElement().text());
424 query.
bindValue(
":META", itemNode.namedItem(QString(
"metadataformat")).toElement().text());
425 query.
bindValue(
":COUNTRY", itemNode.namedItem(QString(
"country")).toElement().text());
426 query.
bindValue(
":LANG", itemNode.namedItem(QString(
"language")).toElement().text());
438 LOG(VB_GENERAL, LOG_INFO,
"MusicMetadata: updating radio streams list completed OK");
449 LOG(VB_GENERAL, LOG_ERR, QString(
"MusicMetadata: Asked to reload metadata "
450 "for trackID: %1 but not found!").arg(
m_id));
470 QString sqldir =
m_filename.section(
'/', 0, -2);
476 if (sqldir.isEmpty())
483 query.
prepare(
"SELECT directory_id FROM music_directories "
484 "WHERE path = :DIRECTORY ;");
498 query.
prepare(
"INSERT INTO music_directories (path) VALUES (:DIRECTORY);");
521 query.
prepare(
"SELECT artist_id FROM music_artists "
522 "WHERE artist_name = :ARTIST ;");
536 query.
prepare(
"INSERT INTO music_artists (artist_name) VALUES (:ARTIST);");
563 query.
prepare(
"SELECT artist_id FROM music_artists "
564 "WHERE artist_name = :ARTIST ;");
577 query.
prepare(
"INSERT INTO music_artists (artist_name) VALUES (:ARTIST);");
599 query.
prepare(
"SELECT album_id FROM music_albums "
600 "WHERE artist_id = :COMP_ARTIST_ID "
601 " AND album_name = :ALBUM ;");
615 query.
prepare(
"INSERT INTO music_albums (artist_id, album_name, compilation, year) "
616 "VALUES (:COMP_ARTIST_ID, :ALBUM, :COMPILATION, :YEAR);");
640 query.
prepare(
"SELECT genre_id FROM music_genres "
641 "WHERE genre = :GENRE ;");
654 query.
prepare(
"INSERT INTO music_genres (genre) VALUES (:GENRE);");
706 strQuery =
"INSERT INTO music_songs ( directory_id,"
707 " artist_id, album_id, name, genre_id,"
708 " year, track, length, filename,"
709 " rating, format, date_entered, date_modified,"
710 " numplays, track_count, disc_number, disc_count,"
714 " :ARTIST, :ALBUM, :TITLE, :GENRE,"
715 " :YEAR, :TRACKNUM, :LENGTH, :FILENAME,"
716 " :RATING, :FORMAT, :DATE_ADD, :DATE_MOD,"
717 " :PLAYCOUNT,:TRACKCOUNT, :DISC_NUMBER, :DISC_COUNT,"
718 " :SIZE, :HOSTNAME );";
722 strQuery =
"UPDATE music_songs SET"
723 " directory_id = :DIRECTORY"
724 ", artist_id = :ARTIST"
725 ", album_id = :ALBUM"
727 ", genre_id = :GENRE"
729 ", track = :TRACKNUM"
731 ", filename = :FILENAME"
734 ", date_modified = :DATE_MOD "
735 ", numplays = :PLAYCOUNT "
736 ", track_count = :TRACKCOUNT "
737 ", disc_number = :DISC_NUMBER "
738 ", disc_count = :DISC_COUNT "
740 ", hostname = :HOSTNAME "
741 "WHERE song_id= :ID ;";
744 QString sqlfilename =
m_filename.section(
'/', -1);
758 query.
bindValue(
":FILENAME", sqlfilename);
776 MythDB::DBError(
"MusicMetadata::dumpToDatabase - updating music_songs",
787 query.
prepare(
"UPDATE music_albums SET album_name = :ALBUM_NAME, "
788 "artist_id = :COMP_ARTIST_ID, compilation = :COMPILATION, "
790 "WHERE music_albums.album_id = :ALBUMID");
868 rv.replace(
"TRACK", QString(
"%1").arg(
m_trackNum, 2));
876 m_artist = tr(
"Unknown Artist",
"Default artist if no artist");
887 m_album = tr(
"Unknown Album",
"Default album if no album");
894 m_genre = tr(
"Unknown Genre",
"Default genre if no genre");
916 QString format_artist;
917 QString format_title;
1013 if (!mythUrl.isEmpty())
1019 QHostAddress(url.host()).isNull())
1029 LOG(VB_GENERAL, LOG_ERR, QString(
"MusicMetadata: Asked to get the filename for a track but no file found: %1")
1051 if (field ==
"artist")
1053 else if (field ==
"compilation_artist")
1055 else if (field ==
"album")
1057 else if (field ==
"title")
1059 else if (field ==
"genre")
1061 else if (field ==
"filename")
1063 else if (field ==
"year")
1065 else if (field ==
"tracknum")
1067 else if (field ==
"trackcount")
1069 else if (field ==
"discnum")
1071 else if (field ==
"disccount")
1073 else if (field ==
"length")
1074 m_length = std::chrono::milliseconds(data.toInt());
1075 else if (field ==
"compilation")
1079 LOG(VB_GENERAL, LOG_ERR, QString(
"Something asked me to set data "
1080 "for a field called %1").arg(field));
1087 if (field ==
"artist")
1089 else if (field ==
"album")
1091 else if (field ==
"title")
1093 else if (field ==
"genre")
1097 LOG(VB_GENERAL, LOG_ERR, QString(
"Something asked me to return data "
1098 "about a field called %1").arg(field));
1106 metadataMap[
prefix +
"songid"] = QString::number(
m_id);
1132 QString fmt = (
m_length >= 1h) ?
"H:mm:ss" :
"mm:ss";
1137 metadataMap[
prefix +
"lastplayed"] =
1142 metadataMap[
prefix +
"lastplayed"] = tr(
"Never Played");
1151 QString tmpSize = locale.toString(
m_fileSize *
1152 (1.0 / (1024.0 * 1024.0)),
'f', 2);
1153 metadataMap[
prefix +
"filesize"] = tmpSize;
1172 metadataMap[
prefix +
"url"] = url.toString(QUrl::RemoveUserInfo);
1226 for (
auto *art : std::as_const(albumart))
1228 art->m_filename = QString(
"%1-%2").arg(
m_id).arg(art->m_filename);
1237 QStringList searchList;
1241 if (
"artist" == field)
1243 query.
prepare(
"SELECT artist_name FROM music_artists ORDER BY artist_name;");
1245 else if (
"compilation_artist" == field)
1247 query.
prepare(
"SELECT DISTINCT artist_name FROM music_artists, music_albums where "
1248 "music_albums.artist_id=music_artists.artist_id ORDER BY artist_name");
1250 else if (
"album" == field)
1252 query.
prepare(
"SELECT album_name FROM music_albums ORDER BY album_name;");
1254 else if (
"title" == field)
1256 query.
prepare(
"SELECT name FROM music_songs ORDER BY name;");
1258 else if (
"genre" == field)
1260 query.
prepare(
"SELECT genre FROM music_genres ORDER BY genre;");
1269 while (query.
next())
1271 searchList << query.
value(0).toString();
1288 if (albumart_image ==
nullptr)
1295 if (!res.isEmpty() && albumart_image)
1301 QString path =
GetConfDir() +
"/MythMusic/AlbumArt/";
1303 QString
filename = QString(
"%1-%2.%3").arg(
m_id).arg(
"front", fi.suffix());
1319 else if (repo ==
RT_CD)
1329 if (url.path().isEmpty() || url.host().isEmpty() || url.userName().isEmpty())
1341 QStringList paramList;
1342 paramList.append(QString(
"--songid='%1'").arg(
ID()));
1343 paramList.append(QString(
"--imagetype='%1'").arg(albumart_image->
m_imageType));
1345 QString command =
"mythutil --extractimage " + paramList.join(
" ");
1355 slist <<
"MUSIC_TAG_GETIMAGE"
1357 << QString::number(
ID())
1416 LOG(VB_FILE, LOG_INFO, QString(
"MusicMetadata::getTagger - creating tagger for %1").arg(
filename));
1420 LOG(VB_GENERAL, LOG_ERR, QString(
"MusicMetadata::getTagger - failed to find %1 on the local filesystem").arg(
Filename(
false)));
1443 while (!m_allMusic.empty())
1445 delete m_allMusic.back();
1446 m_allMusic.pop_back();
1449 while (!m_cdData.empty())
1451 delete m_cdData.back();
1452 m_cdData.pop_back();
1455 m_metadataLoader->wait();
1456 delete m_metadataLoader;
1465 if (m_metadataLoader->isFinished())
1470 m_metadataLoader->wait();
1489 m_doneLoading =
false;
1491 if (m_metadataLoader)
1494 delete m_metadataLoader;
1498 m_metadataLoader->start();
1510 m_doneLoading =
false;
1512 QString aquery =
"SELECT music_songs.song_id, music_artists.artist_id, music_artists.artist_name, "
1513 "music_comp_artists.artist_name AS compilation_artist, "
1514 "music_albums.album_id, music_albums.album_name, music_songs.name, music_genres.genre, music_songs.year, "
1515 "music_songs.track, music_songs.length, music_songs.directory_id, "
1516 "CONCAT_WS('/', music_directories.path, music_songs.filename) AS filename, "
1517 "music_songs.rating, music_songs.numplays, music_songs.lastplay, music_songs.date_entered, "
1518 "music_albums.compilation, music_songs.format, music_songs.track_count, "
1519 "music_songs.size, music_songs.hostname, music_songs.disc_number, music_songs.disc_count "
1521 "LEFT JOIN music_directories ON music_songs.directory_id=music_directories.directory_id "
1522 "LEFT JOIN music_artists ON music_songs.artist_id=music_artists.artist_id "
1523 "LEFT JOIN music_albums ON music_songs.album_id=music_albums.album_id "
1524 "LEFT JOIN music_artists AS music_comp_artists ON music_albums.artist_id=music_comp_artists.artist_id "
1525 "LEFT JOIN music_genres ON music_songs.genre_id=music_genres.genre_id "
1526 "ORDER BY music_songs.song_id;";
1529 if (!query.
exec(aquery))
1532 m_numPcs = query.
size() * 2;
1534 QList<MusicMetadata::IdType> idList;
1538 while (query.
next())
1545 query.
value(12).toString(),
1546 query.
value(2).toString(),
1547 query.
value(3).toString(),
1548 query.
value(5).toString(),
1549 query.
value(6).toString(),
1550 query.
value(7).toString(),
1551 query.
value(8).toInt(),
1552 query.
value(9).toInt(),
1553 std::chrono::milliseconds(query.
value(10).toInt()),
1554 query.
value(0).toInt(),
1555 query.
value(13).toInt(),
1556 query.
value(14).toInt(),
1557 query.
value(15).toDateTime(),
1558 query.
value(16).toDateTime(),
1559 (query.
value(17).toInt() > 0),
1560 query.
value(18).toString());
1562 dbMeta->setDirectoryId(query.
value(11).toInt());
1563 dbMeta->setArtistId(query.
value(1).toInt());
1564 dbMeta->setCompilationArtistId(query.
value(3).toInt());
1565 dbMeta->setAlbumId(query.
value(4).toInt());
1566 dbMeta->setTrackCount(query.
value(19).toInt());
1567 dbMeta->setFileSize(query.
value(20).toULongLong());
1568 dbMeta->setHostname(query.
value(21).toString());
1569 dbMeta->setDiscNumber(query.
value(22).toInt());
1570 dbMeta->setDiscCount(query.
value(23).toInt());
1572 if (!m_musicMap.contains(
id))
1577 m_allMusic.append(dbMeta);
1579 m_musicMap[id] = dbMeta;
1588 if (cacheMeta && !cacheMeta->
compare(dbMeta))
1599 if (query.
at() == 0)
1602 m_playCountMin = m_playCountMax = query.
value(13).toInt();
1603 m_lastPlayMin = m_lastPlayMax = query.
value(14).toDateTime().toSecsSinceEpoch();
1607 int playCount = query.
value(13).toInt();
1608 qint64 lastPlay = query.
value(14).toDateTime().toSecsSinceEpoch();
1610 m_playCountMin = std::min(playCount, m_playCountMin);
1611 m_playCountMax = std::max(playCount, m_playCountMax);
1612 m_lastPlayMin = std::min(lastPlay, m_lastPlayMin);
1613 m_lastPlayMax = std::max(lastPlay, m_lastPlayMax);
1620 LOG(VB_GENERAL, LOG_ERR,
"MythMusic hasn't found any tracks!");
1624 QList<MusicMetadata::IdType> deleteList;
1625 for (
const auto *track : std::as_const(m_allMusic))
1627 if (!idList.contains(track->ID()))
1629 deleteList.append(track->ID());
1634 for (
uint id : deleteList)
1637 m_allMusic.removeAll(mdata);
1638 m_musicMap.remove(
id);
1644 LOG(VB_GENERAL, LOG_DEBUG, QString(
"AllMusic::resync sending MUSIC_RESYNC_FINISHED added: %1, removed: %2, changed: %3")
1645 .arg(added).arg(removed).arg(changed));
1648 m_doneLoading =
true;
1653 if (m_musicMap.contains(an_id))
1654 return m_musicMap[an_id];
1661 return m_musicMap.contains(an_id);
1671 *mdata = *the_track;
1681 for (
auto *item : std::as_const(m_allMusic))
1683 if (item->hasChanged())
1691 while (!m_cdData.empty())
1694 if (m_musicMap.contains(mdata->
ID()))
1695 m_musicMap.remove(mdata->
ID());
1697 delete m_cdData.back();
1698 m_cdData.pop_back();
1701 m_cdTitle = tr(
"CD -- none");
1707 mdata->setID(m_cdData.count() + 1);
1708 mdata->setRepo(
RT_CD);
1709 m_cdData.append(mdata);
1710 m_musicMap[mdata->ID()] = mdata;
1715 if (m_cdData.count() < 1)
1718 return m_cdData.last()->FormatTitle() == the_track->
FormatTitle();
1723 for (
auto *anit : std::as_const(m_cdData))
1725 if (anit->Track() == the_track)
1743 while (!m_streamList.empty())
1745 delete m_streamList.back();
1746 m_streamList.pop_back();
1752 for (
int x = 0; x < m_streamList.count(); x++)
1754 if (m_streamList.at(x)->ID() == an_id)
1763 for (
int x = 0; x < m_streamList.count(); x++)
1765 if (m_streamList.at(x)->ID() == an_id)
1766 return m_streamList.at(x);
1774 while (!m_streamList.empty())
1776 delete m_streamList.back();
1777 m_streamList.pop_back();
1780 QString aquery =
"SELECT intid, broadcaster, channel, description, url1, url2, url3, url4, url5,"
1781 "logourl, genre, metaformat, country, language, format "
1782 "FROM music_radios "
1783 "ORDER BY broadcaster,channel;";
1786 if (!query.
exec(aquery))
1791 while (query.
next())
1795 urls[x] = query.
value(4 + x).toString();
1798 query.
value(0).toInt(),
1799 query.
value(1).toString(),
1800 query.
value(2).toString(),
1801 query.
value(3).toString(),
1803 query.
value(9).toString(),
1804 query.
value(10).toString(),
1805 query.
value(11).toString(),
1806 query.
value(12).toString(),
1807 query.
value(13).toString(),
1808 query.
value(14).toString());
1812 m_streamList.append(mdata);
1817 LOG(VB_GENERAL, LOG_WARNING,
"MythMusic hasn't found any radio streams!");
1825 query.
prepare(
"INSERT INTO music_radios (broadcaster, channel, description, "
1826 "url1, url2, url3, url4, url5, "
1827 "logourl, genre, country, language, format, metaformat) "
1828 "VALUES (:BROADCASTER, :CHANNEL, :DESCRIPTION, :URL1, :URL2, :URL3, :URL4, :URL5, "
1829 ":LOGOURL, :GENRE, :COUNTRY, :LANGUAGE, :FORMAT, :METAFORMAT);");
1862 query.
prepare(
"DELETE FROM music_radios WHERE intid = :ID");
1879 query.
prepare(
"UPDATE music_radios set broadcaster = :BROADCASTER, channel = :CHANNEL, description = :DESCRIPTION, "
1880 "url1 = :URL1, url2 = :URL2, url3 = :URL3, url4 = :URL4, url5 = :URL5, "
1881 "logourl = :LOGOURL, genre = :GENRE, country = :COUNTRY, language = :LANGUAGE, "
1882 "format = :FORMAT, metaformat = :METAFORMAT "
1883 "WHERE intid = :ID");
1912 : m_parent(metadata)
1919 : m_parent(metadata)
1921 for (
const auto &srcImage : std::as_const(other.
m_imageList))
1954 query.
prepare(
"SELECT logourl FROM music_radios WHERE url1 = :URL;");
1958 while (query.
next())
1960 QString logoUrl = query.
value(0).toString();
1964 image->m_filename = logoUrl;
1966 image->m_embedded =
false;
1967 image->m_hostname =
"";
1978 QString dir = fi.path();
1981 query.
prepare(
"SELECT albumart_id, CONCAT_WS('/', music_directories.path, "
1982 "music_albumart.filename), music_albumart.filename, music_albumart.imagetype, "
1983 "music_albumart.embedded, music_albumart.hostname "
1984 "FROM music_albumart "
1985 "LEFT JOIN music_directories ON "
1986 "music_directories.directory_id = music_albumart.directory_id "
1987 "WHERE music_directories.path = :DIR "
1988 "OR song_id = :SONGID "
1989 "ORDER BY music_albumart.imagetype;");
1994 while (query.
next())
1997 bool embedded = (query.
value(4).toInt() == 1);
1998 image->m_id = query.
value(0).toInt();
2004 if (url.scheme() ==
"myth")
2007 QString(
"AlbumArt/") + query.
value(1).toString(),
2012 image->m_filename = query.
value(1).toString();
2017 if (url.scheme() ==
"myth")
2020 query.
value(1).toString(),
2025 image->m_filename = query.
value(1).toString();
2030 image->m_embedded = embedded;
2031 image->m_hostname = query.
value(5).toString();
2039 if (
findIcon(
"artist", artist) != QString())
2043 image->m_filename =
findIcon(
"artist", artist);
2045 image->m_embedded =
false;
2056 popupStack,
"scanbusydialog");
2068 QStringList strList;
2069 strList <<
"MUSIC_FIND_ALBUMART"
2075 scanThread->start();
2077 while (scanThread->isRunning())
2079 QCoreApplication::processEvents();
2083 strList = scanThread->getResult();
2096 for (
int x = 2; x < strList.count(); x += 6)
2099 image->
m_id = strList[x].toInt();
2100 image->m_imageType = (
ImageType) strList[x + 1].toInt();
2101 image->m_embedded = (strList[x + 2].toInt() == 1);
2102 image->m_description = strList[x + 3];
2104 if (image->m_embedded)
2107 QString(
"AlbumArt/") + strList[x + 4],
2117 image->m_hostname = strList[x + 5];
2119 LOG(VB_FILE, LOG_INFO,
"AlbumArtImages::scanForImages found image");
2120 LOG(VB_FILE, LOG_INFO, QString(
"ID: %1").arg(image->m_id));
2121 LOG(VB_FILE, LOG_INFO, QString(
"ImageType: %1").arg(image->m_imageType));
2122 LOG(VB_FILE, LOG_INFO, QString(
"Embedded: %1").arg(image->m_embedded));
2123 LOG(VB_FILE, LOG_INFO, QString(
"Description: %1").arg(image->m_description));
2124 LOG(VB_FILE, LOG_INFO, QString(
"Filename: %1").arg(image->m_filename));
2125 LOG(VB_FILE, LOG_INFO, QString(
"Hostname: %1").arg(image->m_hostname));
2126 LOG(VB_FILE, LOG_INFO,
"-------------------------------");
2138 if (item->m_imageType ==
type)
2149 if (item->m_id == imageID)
2160 for (
const auto *item : std::as_const(
m_imageList))
2161 paths += item->m_filename;
2178 static const std::array<const std::string,6> s_typeStrings {
2179 QT_TR_NOOP(
"Unknown"),
2180 QT_TR_NOOP(
"Front Cover"),
2181 QT_TR_NOOP(
"Back Cover"),
2183 QT_TR_NOOP(
"Inlay"),
2184 QT_TR_NOOP(
"Artist"),
2187 return QCoreApplication::translate(
"AlbumArtImages",
2188 s_typeStrings[
type].c_str());
2195 static const std::array<const std::string,6> s_filenameStrings {
2196 QT_TR_NOOP(
"unknown"),
2197 QT_TR_NOOP(
"front"),
2200 QT_TR_NOOP(
"inlay"),
2201 QT_TR_NOOP(
"artist")
2204 return QCoreApplication::translate(
"AlbumArtImages",
2205 s_filenameStrings[
type].c_str());
2213 if (
filename.contains(
"front", Qt::CaseInsensitive) ||
2214 filename.contains(tr(
"front"), Qt::CaseInsensitive) ||
2215 filename.contains(
"cover", Qt::CaseInsensitive) ||
2216 filename.contains(tr(
"cover"), Qt::CaseInsensitive))
2218 else if (
filename.contains(
"back", Qt::CaseInsensitive) ||
2219 filename.contains(tr(
"back"), Qt::CaseInsensitive))
2221 else if (
filename.contains(
"inlay", Qt::CaseInsensitive) ||
2222 filename.contains(tr(
"inlay"), Qt::CaseInsensitive))
2224 else if (
filename.contains(
"cd", Qt::CaseInsensitive) ||
2225 filename.contains(tr(
"cd"), Qt::CaseInsensitive))
2236 if (name.toLower() ==
"front")
2238 else if (name.toLower() ==
"back")
2240 else if (name.toLower() ==
"inlay")
2242 else if (name.toLower() ==
"cd")
2244 else if (name.toLower() ==
"artist")
2246 else if (name.toLower() ==
"unknown")
2291 if (trackID == 0 || directoryID == -1)
2293 LOG(VB_GENERAL, LOG_ERR,
"AlbumArtImages: Asked to save to the DB but "
2294 "have invalid songid or directoryid");
2301 query.
prepare(
"DELETE FROM music_albumart "
2302 "WHERE song_id = :SONGID "
2303 "OR (embedded = 0 AND directory_id = :DIRECTORYID)");
2306 query.
bindValue(
":DIRECTORYID", directoryID);
2311 "deleting existing albumart", query);
2321 if (image->m_id > 0)
2324 query.
prepare(
"INSERT INTO music_albumart ( albumart_id, "
2325 "filename, imagetype, song_id, directory_id, embedded, hostname ) "
2326 "VALUES ( :ID, :FILENAME, :TYPE, :SONGID, :DIRECTORYID, :EMBED, :HOSTNAME );");
2331 query.
prepare(
"INSERT INTO music_albumart ( filename, "
2332 "imagetype, song_id, directory_id, embedded, hostname ) VALUES ( "
2333 ":FILENAME, :TYPE, :SONGID, :DIRECTORYID, :EMBED, :HOSTNAME );");
2336 QFileInfo fi(image->m_filename);
2337 query.
bindValue(
":FILENAME", fi.fileName());
2339 query.
bindValue(
":TYPE", image->m_imageType);
2340 query.
bindValue(
":SONGID", image->m_embedded ? trackID : 0);
2341 query.
bindValue(
":DIRECTORYID", image->m_embedded ? 0 : directoryID);
2342 query.
bindValue(
":EMBED", image->m_embedded);
2343 query.
bindValue(
":HOSTNAME", image->m_hostname);
2348 "add/update music_albumart", query);
2352 if (image->m_id <= 0)