MythTV master
musicmetadata.cpp
Go to the documentation of this file.
1
2#include "musicmetadata.h"
3
4// qt
5#include <QApplication>
6#include <QDateTime>
7#include <QDir>
8#include <QDomDocument>
9#include <QScopedPointer>
10#include <utility>
11
12// mythtv
15#include "libmythbase/mythdb.h"
26
27// libmythmetadata
28#include "metaio.h"
29#include "metaioid3.h"
30#include "metaiomp4.h"
31#include "metaioavfcomment.h"
32#include "metaiooggvorbis.h"
33#include "metaioflacvorbis.h"
34#include "metaiowavpack.h"
35#include "musicutils.h"
36#include "lyricsdata.h"
37
38static QString thePrefix = "the ";
39
41{
42 return a.Filename() == b.Filename();
43}
44
46{
47 return a.Filename() != b.Filename();
48}
49
50// this ctor is for radio streams
51MusicMetadata::MusicMetadata(int lid, QString lbroadcaster, QString lchannel, QString ldescription,
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)),
56 m_id(lid),
57 m_filename(lurls[0]),
58 m_broadcaster(std::move(lbroadcaster)),
59 m_channel(std::move(lchannel)),
60 m_description(std::move(ldescription)),
61 m_urls(lurls),
62 m_logoUrl(std::move(llogourl)),
63 m_metaFormat(std::move(lmetaformat)),
64 m_country(std::move(lcountry)),
65 m_language(std::move(llanguage))
66{
69}
70
72{
73 if (m_albumArt)
74 {
75 delete m_albumArt;
76 m_albumArt = nullptr;
77 }
78
79 if (m_lyricsData)
80 {
81 delete m_lyricsData;
82 m_lyricsData = nullptr;
83 }
84}
85
86
88{
89 if (this == &rhs)
90 return *this;
91
92 m_artist = rhs.m_artist;
96 m_album = rhs.m_album;
98 m_title = rhs.m_title;
102 m_genre = rhs.m_genre;
103 m_year = rhs.m_year;
106 m_discNum = rhs.m_discNum;
108 m_length = rhs.m_length;
109 m_rating = rhs.m_rating;
116 m_id = rhs.m_id;
123 m_albumId = rhs.m_albumId;
124 m_genreId = rhs.m_genreId;
125 if (rhs.m_albumArt)
126 {
127 m_albumArt = new AlbumArtImages(this, *rhs.m_albumArt);
128 }
129 m_lyricsData = nullptr;
130 m_format = rhs.m_format;
131 m_changed = rhs.m_changed;
134 m_channel = rhs.m_channel;
136
137 m_urls = rhs.m_urls;
138 m_logoUrl = rhs.m_logoUrl;
140 m_country = rhs.m_country;
142
143 return *this;
144}
145
146// return true if this == mdata
148{
149 return (
150 m_artist == mdata->m_artist &&
152 m_album == mdata->m_album &&
153 m_title == mdata->m_title &&
154 m_year == mdata->m_year &&
155 m_trackNum == mdata->m_trackNum &&
156 m_trackCount == mdata->m_trackCount &&
157 m_discNum == mdata->m_discNum &&
158 m_discCount == mdata->m_discCount &&
159 //m_length == mdata->m_length &&
160 m_rating == mdata->m_rating &&
161 m_lastPlay == mdata->m_lastPlay &&
162 m_playCount == mdata->m_playCount &&
163 m_compilation == mdata->m_compilation &&
164 m_filename == mdata->m_filename &&
165 m_directoryId == mdata->m_directoryId &&
166 m_artistId == mdata->m_artistId &&
167 m_compartistId == mdata->m_compartistId &&
168 m_albumId == mdata->m_albumId &&
169 m_genreId == mdata->m_genreId &&
170 m_format == mdata->m_format &&
171 m_fileSize == mdata->m_fileSize
172 );
173}
174
176{
177 if (m_id < 1)
178 return;
179
180 if (m_tempLastPlay.isValid())
181 {
184
185 m_tempLastPlay = QDateTime();
186 }
187
189 query.prepare("UPDATE music_songs set rating = :RATING , "
190 "numplays = :PLAYCOUNT , lastplay = :LASTPLAY "
191 "where song_id = :ID ;");
192 query.bindValue(":RATING", m_rating);
193 query.bindValue(":PLAYCOUNT", m_playCount);
194 query.bindValue(":LASTPLAY", m_lastPlay);
195 query.bindValue(":ID", m_id);
196
197 if (!query.exec())
198 MythDB::DBError("music persist", query);
199
200 m_changed = false;
201}
202
204{
205 if (m_id < 1)
206 return;
207
209 query.prepare("UPDATE music_songs SET hostname = :HOSTNAME "
210 "WHERE song_id = :ID ;");
211 query.bindValue(":HOSTNAME", m_hostname);
212 query.bindValue(":ID", m_id);
213
214 if (!query.exec())
215 MythDB::DBError("music save hostname", query);
216}
217
218// static
220{
221 // find the trackid for this filename
222 QString sqldir = filename.section('/', 0, -2);
223
224 QString sqlfilename = filename.section('/', -1);
225
227 query.prepare(
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);
233 query.bindValue(":DIRECTORY", sqldir);
234
235 if (!query.exec())
236 {
237 MythDB::DBError("MusicMetadata::createFromFilename", query);
238 return nullptr;
239 }
240
241 if (!query.next())
242 {
243 LOG(VB_GENERAL, LOG_WARNING,
244 QString("MusicMetadata::createFromFilename: Could not find '%1'")
245 .arg(filename));
246 return nullptr;
247 }
248
249 int songID = query.value(0).toInt();
250
251 return MusicMetadata::createFromID(songID);
252}
253
254// static
256{
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 "
268 "FROM music_songs "
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; ");
275 query.bindValue(":SONGID", trackid);
276
277 if (query.exec() && query.next())
278 {
279 auto *mdata = new MusicMetadata();
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();
302
303 if (!QHostAddress(mdata->m_hostname).isNull()) // A bug caused an IP to replace hostname, reset and it will fix itself
304 {
305 mdata->m_hostname = "";
306 mdata->saveHostname();
307 }
308
309 return mdata;
310 }
311
312 return nullptr;
313}
314
315// static
317{
318 // we are only interested in the global setting so remove any local host setting just in case
319 GetMythDB()->ClearSetting("MusicStreamListModified");
320
321 // make sure we are not already doing an update
322 if (gCoreContext->GetSetting("MusicStreamListModified") == "Updating")
323 {
324 LOG(VB_GENERAL, LOG_ERR, "MusicMetadata: looks like we are already updating the radio streams list");
325 return false;
326 }
327
328 QByteArray compressedData;
329 QByteArray uncompressedData;
330
331 // check if the streamlist has been updated since we last checked
332 QString streamupdateurl = gCoreContext->GetSetting("ServicesRepositoryURL",
333 "https://services.mythtv.org") + "/music/data/?data=streams";
334 QDateTime lastModified = GetMythDownloadManager()->GetLastModified(streamupdateurl);
335
336 QDateTime lastUpdate = QDateTime::fromString(gCoreContext->GetSetting("MusicStreamListModified"), Qt::ISODate);
337
338 if (lastModified <= lastUpdate)
339 {
340 LOG(VB_GENERAL, LOG_INFO, "MusicMetadata: radio streams list is already up to date");
341 return true;
342 }
343
344 gCoreContext->SaveSettingOnHost("MusicStreamListModified", "Updating", nullptr);
345
346 LOG(VB_GENERAL, LOG_INFO, "MusicMetadata: downloading radio streams list");
347
348 // download compressed stream file
349 if (!GetMythDownloadManager()->download(streamupdateurl, &compressedData, false))
350 {
351 LOG(VB_GENERAL, LOG_ERR, "MusicMetadata: failed to download radio stream list");
352 gCoreContext->SaveSettingOnHost("MusicStreamListModified", "", nullptr);
353 return false;
354 }
355
356 // uncompress the data
357 uncompressedData = gzipUncompress(compressedData);
358
359 // load the xml
360 QDomDocument domDoc;
361
362#if QT_VERSION < QT_VERSION_CHECK(6,5,0)
363 QString errorMsg;
364 int errorLine = 0;
365 int errorColumn = 0;
366
367 if (!domDoc.setContent(uncompressedData, false, &errorMsg,
368 &errorLine, &errorColumn))
369 {
370 LOG(VB_GENERAL, LOG_ERR,
371 "MusicMetadata: Could not read content of streams.xml" +
372 QString("\n\t\t\tError parsing %1").arg(streamupdateurl) +
373 QString("\n\t\t\tat line: %1 column: %2 msg: %3")
374 .arg(errorLine).arg(errorColumn).arg(errorMsg));
375 gCoreContext->SaveSettingOnHost("MusicStreamListModified", "", nullptr);
376 return false;
377 }
378#else
379 auto parseResult = domDoc.setContent(uncompressedData);
380 if (!parseResult)
381 {
382 LOG(VB_GENERAL, LOG_ERR,
383 "MusicMetadata: Could not read content of streams.xml" +
384 QString("\n\t\t\tError parsing %1").arg(streamupdateurl) +
385 QString("\n\t\t\tat line: %1 column: %2 msg: %3")
386 .arg(parseResult.errorLine).arg(parseResult.errorColumn)
387 .arg(parseResult.errorMessage));
388 gCoreContext->SaveSettingOnHost("MusicStreamListModified", "", nullptr);
389 return false;
390 }
391#endif
392
394 query.prepare("DELETE FROM music_streams;");
395 if (!query.exec() || !query.isActive() || query.numRowsAffected() < 0)
396 {
397 MythDB::DBError("music delete radio streams", query);
398 gCoreContext->SaveSettingOnHost("MusicStreamListModified", "", nullptr);
399 return false;
400 }
401
402 LOG(VB_GENERAL, LOG_INFO, "MusicMetadata: processing radio streams list");
403
404 QDomNodeList itemList = domDoc.elementsByTagName("item");
405
406 QDomNode itemNode;
407 for (int i = 0; i < itemList.count(); i++)
408 {
409 itemNode = itemList.item(i);
410
411 query.prepare("INSERT INTO music_streams (broadcaster, channel, description, url1, url2, url3, url4, url5,"
412 " logourl, genre, metaformat, country, language) "
413 "VALUES (:BROADCASTER, :CHANNEL, :DESC, :URL1, :URL2, :URL3, :URL4, :URL5,"
414 " :LOGOURL, :GENRE, :META, :COUNTRY, :LANG);");
415
416 query.bindValue(":BROADCASTER", itemNode.namedItem(QString("broadcaster")).toElement().text());
417 query.bindValue(":CHANNEL", itemNode.namedItem(QString("channel")).toElement().text());
418 query.bindValue(":DESC", itemNode.namedItem(QString("description")).toElement().text());
419 query.bindValue(":URL1", itemNode.namedItem(QString("url1")).toElement().text());
420 query.bindValue(":URL2", itemNode.namedItem(QString("url2")).toElement().text());
421 query.bindValue(":URL3", itemNode.namedItem(QString("url3")).toElement().text());
422 query.bindValue(":URL4", itemNode.namedItem(QString("url4")).toElement().text());
423 query.bindValue(":URL5", itemNode.namedItem(QString("url5")).toElement().text());
424 query.bindValue(":LOGOURL", itemNode.namedItem(QString("logourl")).toElement().text());
425 query.bindValue(":GENRE", itemNode.namedItem(QString("genre")).toElement().text());
426 query.bindValue(":META", itemNode.namedItem(QString("metadataformat")).toElement().text());
427 query.bindValue(":COUNTRY", itemNode.namedItem(QString("country")).toElement().text());
428 query.bindValue(":LANG", itemNode.namedItem(QString("language")).toElement().text());
429
430 if (!query.exec() || !query.isActive() || query.numRowsAffected() <= 0)
431 {
432 MythDB::DBError("music insert radio stream", query);
433 gCoreContext->SaveSettingOnHost("MusicStreamListModified", "", nullptr);
434 return false;
435 }
436 }
437
438 gCoreContext->SaveSettingOnHost("MusicStreamListModified", lastModified.toString(Qt::ISODate), nullptr);
439
440 LOG(VB_GENERAL, LOG_INFO, "MusicMetadata: updating radio streams list completed OK");
441
442 return true;
443}
444
446{
448
449 if (!mdata)
450 {
451 LOG(VB_GENERAL, LOG_ERR, QString("MusicMetadata: Asked to reload metadata "
452 "for trackID: %1 but not found!").arg(m_id));
453
454 return;
455 }
456
457 *this = *mdata;
458
459 delete mdata;
460
461 m_directoryId = -1;
462 m_artistId = -1;
463 m_compartistId = -1;
464 m_albumId = -1;
465 m_genreId = -1;
466}
467
469{
470 if (m_directoryId < 0)
471 {
472 QString sqldir = m_filename.section('/', 0, -2);
473
475
477
478 if (sqldir.isEmpty())
479 {
480 m_directoryId = 0;
481 }
482 else if (m_directoryId < 0)
483 {
484 // Load the directory id
485 query.prepare("SELECT directory_id FROM music_directories "
486 "WHERE path = :DIRECTORY ;");
487 query.bindValue(":DIRECTORY", sqldir);
488
489 if (!query.exec() || !query.isActive())
490 {
491 MythDB::DBError("music select directory id", query);
492 return -1;
493 }
494 if (query.next())
495 {
496 m_directoryId = query.value(0).toInt();
497 }
498 else
499 {
500 query.prepare("INSERT INTO music_directories (path) VALUES (:DIRECTORY);");
501 query.bindValue(":DIRECTORY", sqldir);
502
503 if (!query.exec() || !query.isActive() || query.numRowsAffected() <= 0)
504 {
505 MythDB::DBError("music insert directory", query);
506 return -1;
507 }
508 m_directoryId = query.lastInsertId().toInt();
509 }
510 }
511 }
512
513 return m_directoryId;
514}
515
517{
518 if (m_artistId < 0)
519 {
521
522 // Load the artist id
523 query.prepare("SELECT artist_id FROM music_artists "
524 "WHERE artist_name = :ARTIST ;");
525 query.bindValueNoNull(":ARTIST", m_artist);
526
527 if (!query.exec() || !query.isActive())
528 {
529 MythDB::DBError("music select artist id", query);
530 return -1;
531 }
532 if (query.next())
533 {
534 m_artistId = query.value(0).toInt();
535 }
536 else
537 {
538 query.prepare("INSERT INTO music_artists (artist_name) VALUES (:ARTIST);");
539 query.bindValueNoNull(":ARTIST", m_artist);
540
541 if (!query.exec() || !query.isActive() || query.numRowsAffected() <= 0)
542 {
543 MythDB::DBError("music insert artist", query);
544 return -1;
545 }
546 m_artistId = query.lastInsertId().toInt();
547 }
548 }
549
550 return m_artistId;
551}
552
554{
555 if (m_compartistId < 0) {
557
558 // Compilation Artist
560 {
562 }
563 else
564 {
565 query.prepare("SELECT artist_id FROM music_artists "
566 "WHERE artist_name = :ARTIST ;");
567 query.bindValueNoNull(":ARTIST", m_compilationArtist);
568 if (!query.exec() || !query.isActive())
569 {
570 MythDB::DBError("music select compilation artist id", query);
571 return -1;
572 }
573 if (query.next())
574 {
575 m_compartistId = query.value(0).toInt();
576 }
577 else
578 {
579 query.prepare("INSERT INTO music_artists (artist_name) VALUES (:ARTIST);");
580 query.bindValueNoNull(":ARTIST", m_compilationArtist);
581
582 if (!query.exec() || !query.isActive() || query.numRowsAffected() <= 0)
583 {
584 MythDB::DBError("music insert compilation artist", query);
585 return -1 ;
586 }
587 m_compartistId = query.lastInsertId().toInt();
588 }
589 }
590 }
591
592 return m_compartistId;
593}
594
596{
597 if (m_albumId < 0)
598 {
600
601 query.prepare("SELECT album_id FROM music_albums "
602 "WHERE artist_id = :COMP_ARTIST_ID "
603 " AND album_name = :ALBUM ;");
604 query.bindValueNoNull(":COMP_ARTIST_ID", m_compartistId);
605 query.bindValueNoNull(":ALBUM", m_album);
606 if (!query.exec() || !query.isActive())
607 {
608 MythDB::DBError("music select album id", query);
609 return -1;
610 }
611 if (query.next())
612 {
613 m_albumId = query.value(0).toInt();
614 }
615 else
616 {
617 query.prepare("INSERT INTO music_albums (artist_id, album_name, compilation, year) "
618 "VALUES (:COMP_ARTIST_ID, :ALBUM, :COMPILATION, :YEAR);");
619 query.bindValueNoNull(":COMP_ARTIST_ID", m_compartistId);
620 query.bindValueNoNull(":ALBUM", m_album);
621 query.bindValue(":COMPILATION", m_compilation);
622 query.bindValue(":YEAR", m_year);
623
624 if (!query.exec() || !query.isActive() || query.numRowsAffected() <= 0)
625 {
626 MythDB::DBError("music insert album", query);
627 return -1;
628 }
629 m_albumId = query.lastInsertId().toInt();
630 }
631 }
632
633 return m_albumId;
634}
635
637{
638 if (m_genreId < 0)
639 {
641
642 query.prepare("SELECT genre_id FROM music_genres "
643 "WHERE genre = :GENRE ;");
644 query.bindValueNoNull(":GENRE", m_genre);
645 if (!query.exec() || !query.isActive())
646 {
647 MythDB::DBError("music select genre id", query);
648 return -1;
649 }
650 if (query.next())
651 {
652 m_genreId = query.value(0).toInt();
653 }
654 else
655 {
656 query.prepare("INSERT INTO music_genres (genre) VALUES (:GENRE);");
657 query.bindValueNoNull(":GENRE", m_genre);
658
659 if (!query.exec() || !query.isActive() || query.numRowsAffected() <= 0)
660 {
661 MythDB::DBError("music insert genre", query);
662 return -1;
663 }
664 m_genreId = query.lastInsertId().toInt();
665 }
666 }
667
668 return m_genreId;
669}
670
671void MusicMetadata::setUrl(const QString& url, size_t index)
672{
673 if (index < STREAMURLCOUNT)
674 m_urls[index] = url;
675}
676
677QString MusicMetadata::Url(size_t index)
678{
679 if (index < STREAMURLCOUNT)
680 return m_urls[index];
681
682 return {};
683}
684
686{
688
689 if (m_directoryId < 0)
691
692 if (m_artistId < 0)
693 getArtistId();
694
695 if (m_compartistId < 0)
697
698 if (m_albumId < 0)
699 getAlbumId();
700
701 if (m_genreId < 0)
702 getGenreId();
703
704 // We have all the id's now. We can insert it.
705 QString strQuery;
706 if (m_id < 1)
707 {
708 strQuery = "INSERT INTO music_songs ( directory_id,"
709 " artist_id, album_id, name, genre_id,"
710 " year, track, length, filename,"
711 " rating, format, date_entered, date_modified,"
712 " numplays, track_count, disc_number, disc_count,"
713 " size, hostname) "
714 "VALUES ( "
715 " :DIRECTORY, "
716 " :ARTIST, :ALBUM, :TITLE, :GENRE,"
717 " :YEAR, :TRACKNUM, :LENGTH, :FILENAME,"
718 " :RATING, :FORMAT, :DATE_ADD, :DATE_MOD,"
719 " :PLAYCOUNT,:TRACKCOUNT, :DISC_NUMBER, :DISC_COUNT,"
720 " :SIZE, :HOSTNAME );";
721 }
722 else
723 {
724 strQuery = "UPDATE music_songs SET"
725 " directory_id = :DIRECTORY"
726 ", artist_id = :ARTIST"
727 ", album_id = :ALBUM"
728 ", name = :TITLE"
729 ", genre_id = :GENRE"
730 ", year = :YEAR"
731 ", track = :TRACKNUM"
732 ", length = :LENGTH"
733 ", filename = :FILENAME"
734 ", rating = :RATING"
735 ", format = :FORMAT"
736 ", date_modified = :DATE_MOD "
737 ", numplays = :PLAYCOUNT "
738 ", track_count = :TRACKCOUNT "
739 ", disc_number = :DISC_NUMBER "
740 ", disc_count = :DISC_COUNT "
741 ", size = :SIZE "
742 ", hostname = :HOSTNAME "
743 "WHERE song_id= :ID ;";
744 }
745
746 QString sqlfilename = m_filename.section('/', -1);
747
749
750 query.prepare(strQuery);
751
752 query.bindValue(":DIRECTORY", m_directoryId);
753 query.bindValue(":ARTIST", m_artistId);
754 query.bindValue(":ALBUM", m_albumId);
755 query.bindValue(":TITLE", m_title);
756 query.bindValue(":GENRE", m_genreId);
757 query.bindValue(":YEAR", m_year);
758 query.bindValue(":TRACKNUM", m_trackNum);
759 query.bindValue(":LENGTH", static_cast<qint64>(m_length.count()));
760 query.bindValue(":FILENAME", sqlfilename);
761 query.bindValue(":RATING", m_rating);
762 query.bindValueNoNull(":FORMAT", m_format);
763 query.bindValue(":DATE_MOD", MythDate::current());
764 query.bindValue(":PLAYCOUNT", m_playCount);
765
766 if (m_id < 1)
767 query.bindValue(":DATE_ADD", MythDate::current());
768 else
769 query.bindValue(":ID", m_id);
770
771 query.bindValue(":TRACKCOUNT", m_trackCount);
772 query.bindValue(":DISC_NUMBER", m_discNum);
773 query.bindValue(":DISC_COUNT",m_discCount);
774 query.bindValue(":SIZE", (quint64)m_fileSize);
775 query.bindValue(":HOSTNAME", m_hostname);
776
777 if (!query.exec())
778 MythDB::DBError("MusicMetadata::dumpToDatabase - updating music_songs",
779 query);
780
781 if (m_id < 1 && query.isActive() && 1 == query.numRowsAffected())
782 m_id = query.lastInsertId().toInt();
783
784 // save the albumart to the db
785 if (m_albumArt)
787
788 // update the album
789 query.prepare("UPDATE music_albums SET album_name = :ALBUM_NAME, "
790 "artist_id = :COMP_ARTIST_ID, compilation = :COMPILATION, "
791 "year = :YEAR "
792 "WHERE music_albums.album_id = :ALBUMID");
793 query.bindValue(":ALBUMID", m_albumId);
794 query.bindValue(":ALBUM_NAME", m_album);
795 query.bindValue(":COMP_ARTIST_ID", m_compartistId);
796 query.bindValue(":COMPILATION", m_compilation);
797 query.bindValue(":YEAR", m_year);
798
799 if (!query.exec() || !query.isActive())
800 {
801 MythDB::DBError("music compilation update", query);
802 return;
803 }
804}
805
806// Default values for formats
807// NB These will eventually be customizable....
813QString MusicMetadata::s_formatCompilationFileTrack = "TITLE (ARTIST)";
814QString MusicMetadata::s_formatCompilationCdArtist = "COMPARTIST";
815QString MusicMetadata::s_formatCompilationCdTrack = "TITLE (ARTIST)";
816
818{
819 QString tmp;
820
821 tmp = gCoreContext->GetSetting("MusicFormatNormalFileArtist");
822 if (!tmp.isEmpty())
824
825 tmp = gCoreContext->GetSetting("MusicFormatNormalFileTrack");
826 if (!tmp.isEmpty())
828
829 tmp = gCoreContext->GetSetting("MusicFormatNormalCDArtist");
830 if (!tmp.isEmpty())
832
833 tmp = gCoreContext->GetSetting("MusicFormatNormalCDTrack");
834 if (!tmp.isEmpty())
836
837 tmp = gCoreContext->GetSetting("MusicFormatCompilationFileArtist");
838 if (!tmp.isEmpty())
840
841 tmp = gCoreContext->GetSetting("MusicFormatCompilationFileTrack");
842 if (!tmp.isEmpty())
844
845 tmp = gCoreContext->GetSetting("MusicFormatCompilationCDArtist");
846 if (!tmp.isEmpty())
848
849 tmp = gCoreContext->GetSetting("MusicFormatCompilationCDTrack");
850 if (!tmp.isEmpty())
852}
853
854
856{
860 return m_compilation;
861}
862
863
864inline QString MusicMetadata::formatReplaceSymbols(const QString &format)
865{
866 QString rv = format;
867 rv.replace("COMPARTIST", m_compilationArtist);
868 rv.replace("ARTIST", m_artist);
869 rv.replace("TITLE", m_title);
870 rv.replace("TRACK", QString("%1").arg(m_trackNum, 2));
871 return rv;
872}
873
875{
876 if (m_artist.isEmpty())
877 {
878 m_artist = tr("Unknown Artist", "Default artist if no artist");
879 m_artistId = -1;
880 }
881 // This should be the same as Artist if it's a compilation track or blank
882 if (!m_compilation || m_compilationArtist.isEmpty())
883 {
885 m_compartistId = -1;
886 }
887 if (m_album.isEmpty())
888 {
889 m_album = tr("Unknown Album", "Default album if no album");
890 m_albumId = -1;
891 }
892 if (m_title.isEmpty())
894 if (m_genre.isEmpty())
895 {
896 m_genre = tr("Unknown Genre", "Default genre if no genre");
897 m_genreId = -1;
898 }
900}
901
903{
904 std::shared_ptr<MythSortHelper>sh = getMythSortHelper();
905
906 if (m_artistSort.isEmpty() and not m_artist.isEmpty())
907 m_artistSort = sh->doTitle(m_artist);
908 if (m_compilationArtistSort.isEmpty() and not m_compilationArtist.isEmpty())
910 if (m_albumSort.isEmpty() and not m_album.isEmpty())
911 m_albumSort = sh->doTitle(m_album);
912 if (m_titleSort.isEmpty() and not m_title.isEmpty())
913 m_titleSort = sh->doTitle(m_title);
914}
915
917{
918 QString format_artist;
919 QString format_title;
920
921 if (!m_compilation
922 || "" == m_compilationArtist
924 {
925 if (!cd)
926 {
927 format_artist = s_formatNormalFileArtist;
928 format_title = s_formatNormalFileTrack;
929 }
930 else
931 {
932 format_artist = s_formatNormalCdArtist;
933 format_title = s_formatNormalCdTrack;
934 }
935 }
936 else
937 {
938 if (!cd)
939 {
940 format_artist = s_formatCompilationFileArtist;
941 format_title = s_formatCompilationFileTrack;
942 }
943 else
944 {
945 format_artist = s_formatCompilationCdArtist;
946 format_title = s_formatCompilationCdTrack;
947 }
948 }
949
950 // NB Could do some comparisons here to save memory with shallow copies...
953}
954
955
957{
958 if (m_formattedArtist.isEmpty())
960
961 return m_formattedArtist;
962}
963
964
966{
967 if (m_formattedTitle.isEmpty())
969
970 return m_formattedTitle;
971}
972
973void MusicMetadata::setFilename(const QString& lfilename)
974{
975 m_filename = lfilename;
976 m_actualFilename.clear();
977}
978
980{
981 // FIXME: for now just use the first url for radio streams
982 if (isRadio())
983 return m_urls[0];
984
985 // if not asked to find the file just return the raw filename from the DB
986 if (!find)
987 return m_filename;
988
989 if (!m_actualFilename.isEmpty())
990 return m_actualFilename;
991
992 // check for a cd track
993 if (m_filename.endsWith(".cda"))
994 {
996 return m_filename;
997 }
998
999 // check for http urls etc
1000 if (m_filename.contains("://"))
1001 {
1003 return m_filename;
1004 }
1005
1006 // first check to see if the filename is complete
1008 {
1010 return m_filename;
1011 }
1012
1013 // maybe it's in our 'Music' storage group
1014 QString mythUrl = RemoteFile::FindFile(m_filename, m_hostname, "Music");
1015 if (!mythUrl.isEmpty())
1016 {
1017 m_actualFilename = mythUrl;
1018
1019 QUrl url(mythUrl);
1020 if (url.host() != m_hostname &&
1021 QHostAddress(url.host()).isNull()) // Check that it's not an IP address
1022 {
1023 m_hostname = url.host();
1024 saveHostname();
1025 }
1026
1027 return mythUrl;
1028 }
1029
1030 // not found
1031 LOG(VB_GENERAL, LOG_ERR, QString("MusicMetadata: Asked to get the filename for a track but no file found: %1")
1032 .arg(m_filename));
1033
1035
1036 return m_actualFilename;
1037}
1038
1041{
1042 // try the file name as is first
1044 return m_filename;
1045
1046 // not found so now try to find the file in the local 'Music' storage group
1047 StorageGroup storageGroup("Music", gCoreContext->GetHostName(), false);
1048 return storageGroup.FindFile(m_filename);
1049}
1050
1051void MusicMetadata::setField(const QString &field, const QString &data)
1052{
1053 if (field == "artist")
1054 m_artist = data;
1055 else if (field == "compilation_artist")
1056 m_compilationArtist = data;
1057 else if (field == "album")
1058 m_album = data;
1059 else if (field == "title")
1060 m_title = data;
1061 else if (field == "genre")
1062 m_genre = data;
1063 else if (field == "filename")
1064 m_filename = data;
1065 else if (field == "year")
1066 m_year = data.toInt();
1067 else if (field == "tracknum")
1068 m_trackNum = data.toInt();
1069 else if (field == "trackcount")
1070 m_trackCount = data.toInt();
1071 else if (field == "discnum")
1072 m_discNum = data.toInt();
1073 else if (field == "disccount")
1074 m_discCount = data.toInt();
1075 else if (field == "length")
1076 m_length = std::chrono::milliseconds(data.toInt());
1077 else if (field == "compilation")
1078 m_compilation = (data.toInt() > 0);
1079 else
1080 {
1081 LOG(VB_GENERAL, LOG_ERR, QString("Something asked me to set data "
1082 "for a field called %1").arg(field));
1083 }
1085}
1086
1087void MusicMetadata::getField(const QString &field, QString *data)
1088{
1089 if (field == "artist")
1090 *data = FormatArtist();
1091 else if (field == "album")
1092 *data = m_album;
1093 else if (field == "title")
1094 *data = FormatTitle();
1095 else if (field == "genre")
1096 *data = m_genre;
1097 else
1098 {
1099 LOG(VB_GENERAL, LOG_ERR, QString("Something asked me to return data "
1100 "about a field called %1").arg(field));
1101 *data = "I Dunno";
1102 }
1103}
1104
1105void MusicMetadata::toMap(InfoMap &metadataMap, const QString &prefix)
1106{
1107 using namespace MythDate;
1108 metadataMap[prefix + "songid"] = QString::number(m_id);
1109 metadataMap[prefix + "artist"] = m_artist;
1110 metadataMap[prefix + "formatartist"] = FormatArtist();
1111 metadataMap[prefix + "compilationartist"] = m_compilationArtist;
1112
1113 if (m_album.isEmpty() && ID_TO_REPO(m_id) == RT_Radio)
1114 {
1115 if (m_broadcaster.isEmpty())
1116 metadataMap[prefix + "album"] = m_channel;
1117 else
1118 metadataMap[prefix + "album"] = QString("%1 - %2").arg(m_broadcaster, m_channel);
1119 }
1120 else
1121 {
1122 metadataMap[prefix + "album"] = m_album;
1123 }
1124
1125 metadataMap[prefix + "title"] = m_title;
1126 metadataMap[prefix + "formattitle"] = FormatTitle();
1127 metadataMap[prefix + "tracknum"] = (m_trackNum > 0 ? QString("%1").arg(m_trackNum) : "");
1128 metadataMap[prefix + "trackcount"] = (m_trackCount > 0 ? QString("%1").arg(m_trackCount) : "");
1129 metadataMap[prefix + "discnum"] = (m_discNum > 0 ? QString("%1").arg(m_discNum) : "");
1130 metadataMap[prefix + "disccount"] = (m_discCount > 0 ? QString("%1").arg(m_discCount) : "");
1131 metadataMap[prefix + "genre"] = m_genre;
1132 metadataMap[prefix + "year"] = (m_year > 0 ? QString("%1").arg(m_year) : "");
1133
1134 QString fmt = (m_length >= 1h) ? "H:mm:ss" : "mm:ss";
1135 metadataMap[prefix + "length"] = MythDate::formatTime(m_length, fmt);
1136
1137 if (m_lastPlay.isValid())
1138 {
1139 metadataMap[prefix + "lastplayed"] =
1141 }
1142 else
1143 {
1144 metadataMap[prefix + "lastplayed"] = tr("Never Played");
1145 }
1146
1147 metadataMap[prefix + "dateadded"] = MythDate::toString(
1149
1150 metadataMap[prefix + "playcount"] = QString::number(m_playCount);
1151
1152 QLocale locale = gCoreContext->GetQLocale();
1153 QString tmpSize = locale.toString(m_fileSize *
1154 (1.0 / (1024.0 * 1024.0)), 'f', 2);
1155 metadataMap[prefix + "filesize"] = tmpSize;
1156
1157 metadataMap[prefix + "filename"] = m_filename;
1158
1159 // radio stream
1160 if (!m_broadcaster.isEmpty())
1161 metadataMap[prefix + "broadcasterchannel"] = m_broadcaster + " - " + m_channel;
1162 else
1163 metadataMap[prefix + "broadcasterchannel"] = m_channel;
1164 metadataMap[prefix + "broadcaster"] = m_broadcaster;
1165 metadataMap[prefix + "channel"] = m_channel;
1166 metadataMap[prefix + "genre"] = m_genre;
1167 metadataMap[prefix + "country"] = m_country;
1168 metadataMap[prefix + "language"] = m_language;
1169 metadataMap[prefix + "description"] = m_description;
1170
1171 if (isRadio())
1172 {
1173 QUrl url(m_urls[0]);
1174 metadataMap[prefix + "url"] = url.toString(QUrl::RemoveUserInfo);
1175 }
1176 else
1177 {
1178 metadataMap[prefix + "url"] = m_filename;
1179 }
1180
1181 metadataMap[prefix + "logourl"] = m_logoUrl;
1182 metadataMap[prefix + "metadataformat"] = m_metaFormat;
1183}
1184
1186{
1187 if (m_rating > 0)
1188 {
1189 m_rating--;
1190 }
1191 m_changed = true;
1192}
1193
1195{
1196 if (m_rating < 10)
1197 {
1198 m_rating++;
1199 }
1200 m_changed = true;
1201}
1202
1203void MusicMetadata::setLastPlay(const QDateTime& lastPlay)
1204{
1205 m_tempLastPlay = MythDate::as_utc(lastPlay);
1206 m_changed = true;
1207}
1208
1210{
1212 m_changed = true;
1213}
1214
1216{
1218 m_changed = true;
1219}
1220
1222{
1223 // add the images found in the tag to the ones we got from the DB
1224
1225 if (!m_albumArt)
1226 m_albumArt = new AlbumArtImages(this, false);
1227
1228 for (auto *art : std::as_const(albumart))
1229 {
1230 art->m_filename = QString("%1-%2").arg(m_id).arg(art->m_filename);
1231 m_albumArt->addImage(art);
1232 }
1233
1234 m_changed = true;
1235}
1236
1237QStringList MusicMetadata::fillFieldList(const QString& field)
1238{
1239 QStringList searchList;
1240 searchList.clear();
1241
1243 if ("artist" == field)
1244 {
1245 query.prepare("SELECT artist_name FROM music_artists ORDER BY artist_name;");
1246 }
1247 else if ("compilation_artist" == field)
1248 {
1249 query.prepare("SELECT DISTINCT artist_name FROM music_artists, music_albums where "
1250 "music_albums.artist_id=music_artists.artist_id ORDER BY artist_name");
1251 }
1252 else if ("album" == field)
1253 {
1254 query.prepare("SELECT album_name FROM music_albums ORDER BY album_name;");
1255 }
1256 else if ("title" == field)
1257 {
1258 query.prepare("SELECT name FROM music_songs ORDER BY name;");
1259 }
1260 else if ("genre" == field)
1261 {
1262 query.prepare("SELECT genre FROM music_genres ORDER BY genre;");
1263 }
1264 else
1265 {
1266 return searchList;
1267 }
1268
1269 if (query.exec() && query.isActive())
1270 {
1271 while (query.next())
1272 {
1273 searchList << query.value(0).toString();
1274 }
1275 }
1276 return searchList;
1277}
1278
1280{
1281 if (!m_albumArt)
1282 m_albumArt = new AlbumArtImages(this);
1283
1284 AlbumArtImage *albumart_image = nullptr;
1285 QString res;
1286
1288 {
1289 albumart_image = m_albumArt->getImage(Type);
1290 if (albumart_image == nullptr)
1291 continue;
1292 res = albumart_image->m_filename;
1293 break;
1294 }
1295
1296 // check file exists
1297 if (!res.isEmpty() && albumart_image)
1298 {
1299 int repo = ID_TO_REPO(m_id);
1300 if (repo == RT_Radio)
1301 {
1302 // image is a radio station icon, check if we have already downloaded and cached it
1303 QString path = GetConfDir() + "/MythMusic/AlbumArt/";
1304 QFileInfo fi(res);
1305 QString filename = QString("%1-%2.%3").arg(m_id).arg("front", fi.suffix());
1306
1307 albumart_image->m_filename = path + filename;
1308
1309 if (!QFile::exists(albumart_image->m_filename))
1310 {
1311 // file does not exist so try to download and cache it
1312 if (!GetMythDownloadManager()->download(res, albumart_image->m_filename))
1313 {
1314 m_albumArt->getImageList()->removeAll(albumart_image);
1315 return {""};
1316 }
1317 }
1318
1319 res = albumart_image->m_filename;
1320 }
1321 else if (repo == RT_CD)
1322 {
1323 // CD tracks can only be played locally, so coverart is local too
1324 return res;
1325 }
1326 else
1327 {
1328 // check for the image in the storage group
1329 QUrl url(res);
1330
1331 if (url.path().isEmpty() || url.host().isEmpty() || url.userName().isEmpty())
1332 {
1333 return {""};
1334 }
1335
1336 if (!RemoteFile::Exists(res))
1337 {
1338 if (albumart_image->m_embedded)
1339 {
1341 url.host() == gCoreContext->GetMasterHostName())
1342 {
1343 QStringList paramList;
1344 paramList.append(QString("--songid='%1'").arg(ID()));
1345 paramList.append(QString("--imagetype='%1'").arg(albumart_image->m_imageType));
1346
1347 QString command = "mythutil --extractimage " + paramList.join(" ");
1348
1349 QScopedPointer<MythSystem> cmd(MythSystem::Create(command,
1353 }
1354 else
1355 {
1356 QStringList slist;
1357 slist << "MUSIC_TAG_GETIMAGE"
1358 << Hostname()
1359 << QString::number(ID())
1360 << QString::number(albumart_image->m_imageType);
1362 }
1363 }
1364 }
1365 }
1366
1367 return res;
1368 }
1369
1370 return {""};
1371}
1372
1374{
1375 if (!m_albumArt)
1376 m_albumArt = new AlbumArtImages(this);
1377
1378 AlbumArtImage *albumart_image = m_albumArt->getImage(type);
1379 if (albumart_image)
1380 return albumart_image->m_filename;
1381
1382 return {""};
1383}
1384
1386{
1387 if (!m_albumArt)
1388 m_albumArt = new AlbumArtImages(this);
1389
1390 return m_albumArt;
1391}
1392
1394{
1395 delete m_albumArt;
1396 m_albumArt = nullptr; //new AlbumArtImages(this);
1397}
1398
1400{
1401 if (!m_lyricsData)
1402 m_lyricsData = new LyricsData(this);
1403
1404 return m_lyricsData;
1405}
1406
1407// create a MetaIO for the file to read/write any tags etc
1408// NOTE the caller is responsible for deleting it
1410{
1411 // the taggers require direct file access so try to find
1412 // the file on the local filesystem
1413
1414 QString filename = getLocalFilename();
1415
1416 if (!filename.isEmpty())
1417 {
1418 LOG(VB_FILE, LOG_INFO, QString("MusicMetadata::getTagger - creating tagger for %1").arg(filename));
1420 }
1421
1422 LOG(VB_GENERAL, LOG_ERR, QString("MusicMetadata::getTagger - failed to find %1 on the local filesystem").arg(Filename(false)));
1423 return nullptr;
1424}
1425
1426//--------------------------------------------------------------------------
1427
1429{
1430 RunProlog();
1431 //if you want to simulate a big music collection load
1432 //sleep(3);
1433 m_parent->resync();
1434 RunEpilog();
1435}
1436
1438{
1439 // Start a thread to do data loading and sorting
1440 startLoading();
1441}
1442
1444{
1445 while (!m_allMusic.empty())
1446 {
1447 delete m_allMusic.back();
1448 m_allMusic.pop_back();
1449 }
1450
1451 while (!m_cdData.empty())
1452 {
1453 delete m_cdData.back();
1454 m_cdData.pop_back();
1455 }
1456
1458 delete m_metadataLoader;
1459}
1460
1462{
1463 // If this is still running, the user
1464 // probably selected mythmusic and then
1465 // escaped out right away
1466
1468 {
1469 return true;
1470 }
1471
1473 return false;
1474}
1475
1488{
1489 // Set this to false early rather than letting it be
1490 // delayed till the thread calls resync.
1491 m_doneLoading = false;
1492
1493 if (m_metadataLoader)
1494 {
1496 delete m_metadataLoader;
1497 }
1498
1501
1502 return true;
1503}
1504
1507{
1508 uint added = 0;
1509 uint removed = 0;
1510 uint changed = 0;
1511
1512 m_doneLoading = false;
1513
1514 QString aquery = "SELECT music_songs.song_id, music_artists.artist_id, music_artists.artist_name, "
1515 "music_comp_artists.artist_name AS compilation_artist, "
1516 "music_albums.album_id, music_albums.album_name, music_songs.name, music_genres.genre, music_songs.year, "
1517 "music_songs.track, music_songs.length, music_songs.directory_id, "
1518 "CONCAT_WS('/', music_directories.path, music_songs.filename) AS filename, "
1519 "music_songs.rating, music_songs.numplays, music_songs.lastplay, music_songs.date_entered, "
1520 "music_albums.compilation, music_songs.format, music_songs.track_count, "
1521 "music_songs.size, music_songs.hostname, music_songs.disc_number, music_songs.disc_count "
1522 "FROM music_songs "
1523 "LEFT JOIN music_directories ON music_songs.directory_id=music_directories.directory_id "
1524 "LEFT JOIN music_artists ON music_songs.artist_id=music_artists.artist_id "
1525 "LEFT JOIN music_albums ON music_songs.album_id=music_albums.album_id "
1526 "LEFT JOIN music_artists AS music_comp_artists ON music_albums.artist_id=music_comp_artists.artist_id "
1527 "LEFT JOIN music_genres ON music_songs.genre_id=music_genres.genre_id "
1528 "ORDER BY music_songs.song_id;";
1529
1531 if (!query.exec(aquery))
1532 MythDB::DBError("AllMusic::resync", query);
1533
1534 m_numPcs = query.size() * 2;
1535 m_numLoaded = 0;
1536 QList<MusicMetadata::IdType> idList;
1537
1538 if (query.isActive() && query.size() > 0)
1539 {
1540 while (query.next())
1541 {
1542 MusicMetadata::IdType id = query.value(0).toInt();
1543
1544 idList.append(id);
1545
1546 auto *dbMeta = new MusicMetadata(
1547 query.value(12).toString(), // filename
1548 query.value(2).toString(), // artist
1549 query.value(3).toString(), // compilation artist
1550 query.value(5).toString(), // album
1551 query.value(6).toString(), // title
1552 query.value(7).toString(), // genre
1553 query.value(8).toInt(), // year
1554 query.value(9).toInt(), // track no.
1555 std::chrono::milliseconds(query.value(10).toInt()), // length
1556 query.value(0).toInt(), // id
1557 query.value(13).toInt(), // rating
1558 query.value(14).toInt(), // playcount
1559 query.value(15).toDateTime(), // lastplay
1560 query.value(16).toDateTime(), // date_entered
1561 (query.value(17).toInt() > 0), // compilation
1562 query.value(18).toString()); // format
1563
1564 dbMeta->setDirectoryId(query.value(11).toInt());
1565 dbMeta->setArtistId(query.value(1).toInt());
1566 dbMeta->setCompilationArtistId(query.value(3).toInt());
1567 dbMeta->setAlbumId(query.value(4).toInt());
1568 dbMeta->setTrackCount(query.value(19).toInt());
1569 dbMeta->setFileSize(query.value(20).toULongLong());
1570 dbMeta->setHostname(query.value(21).toString());
1571 dbMeta->setDiscNumber(query.value(22).toInt());
1572 dbMeta->setDiscCount(query.value(23).toInt());
1573
1574 if (!m_musicMap.contains(id))
1575 {
1576 // new track
1577
1578 // Don't delete dbMeta, as the MetadataPtrList now owns it
1579 m_allMusic.append(dbMeta);
1580
1581 m_musicMap[id] = dbMeta;
1582
1583 added++;
1584 }
1585 else
1586 {
1587 // existing track, check for any changes
1588 MusicMetadata *cacheMeta = m_musicMap[id];
1589
1590 if (cacheMeta && !cacheMeta->compare(dbMeta))
1591 {
1592 cacheMeta->reloadMetadata();
1593 changed++;
1594 }
1595
1596 // we already have this track in the cache so don't need dbMeta anymore
1597 delete dbMeta;
1598 }
1599
1600 // compute max/min playcount,lastplay for all music
1601 if (query.at() == 0)
1602 {
1603 // first song
1604 m_playCountMin = m_playCountMax = query.value(13).toInt();
1605 m_lastPlayMin = m_lastPlayMax = query.value(14).toDateTime().toSecsSinceEpoch();
1606 }
1607 else
1608 {
1609 int playCount = query.value(13).toInt();
1610 qint64 lastPlay = query.value(14).toDateTime().toSecsSinceEpoch();
1611
1612 m_playCountMin = std::min(playCount, m_playCountMin);
1613 m_playCountMax = std::max(playCount, m_playCountMax);
1614 m_lastPlayMin = std::min(lastPlay, m_lastPlayMin);
1615 m_lastPlayMax = std::max(lastPlay, m_lastPlayMax);
1616 }
1617 m_numLoaded++;
1618 }
1619 }
1620 else
1621 {
1622 LOG(VB_GENERAL, LOG_ERR, "MythMusic hasn't found any tracks!");
1623 }
1624
1625 // get a list of tracks in our cache that's now not in the database
1626 QList<MusicMetadata::IdType> deleteList;
1627 for (const auto *track : std::as_const(m_allMusic))
1628 {
1629 if (!idList.contains(track->ID()))
1630 {
1631 deleteList.append(track->ID());
1632 }
1633 }
1634
1635 // remove the no longer available tracks
1636 for (uint id : deleteList)
1637 {
1638 MusicMetadata *mdata = m_musicMap[id];
1639 m_allMusic.removeAll(mdata);
1640 m_musicMap.remove(id);
1641 removed++;
1642 delete mdata;
1643 }
1644
1645 // tell any listeners a resync has just finished and they may need to reload/resync
1646 LOG(VB_GENERAL, LOG_DEBUG, QString("AllMusic::resync sending MUSIC_RESYNC_FINISHED added: %1, removed: %2, changed: %3")
1647 .arg(added).arg(removed).arg(changed));
1648 gCoreContext->SendMessage(QString("MUSIC_RESYNC_FINISHED %1 %2 %3").arg(added).arg(removed).arg(changed));
1649
1650 m_doneLoading = true;
1651}
1652
1654{
1655 if (m_musicMap.contains(an_id))
1656 return m_musicMap[an_id];
1657
1658 return nullptr;
1659}
1660
1661bool AllMusic::isValidID(int an_id)
1662{
1663 return m_musicMap.contains(an_id);
1664}
1665
1666bool AllMusic::updateMetadata(int an_id, MusicMetadata *the_track)
1667{
1668 if (an_id > 0)
1669 {
1670 MusicMetadata *mdata = getMetadata(an_id);
1671 if (mdata)
1672 {
1673 *mdata = *the_track;
1674 return true;
1675 }
1676 }
1677 return false;
1678}
1679
1682{
1683 for (auto *item : std::as_const(m_allMusic))
1684 {
1685 if (item->hasChanged())
1686 item->persist();
1687 }
1688}
1689
1690// cd stuff
1692{
1693 while (!m_cdData.empty())
1694 {
1695 MusicMetadata *mdata = m_cdData.back();
1696 if (m_musicMap.contains(mdata->ID()))
1697 m_musicMap.remove(mdata->ID());
1698
1699 delete m_cdData.back();
1700 m_cdData.pop_back();
1701 }
1702
1703 m_cdTitle = tr("CD -- none");
1704}
1705
1707{
1708 auto *mdata = new MusicMetadata(the_track);
1709 mdata->setID(m_cdData.count() + 1);
1710 mdata->setRepo(RT_CD);
1711 m_cdData.append(mdata);
1712 m_musicMap[mdata->ID()] = mdata;
1713}
1714
1716{
1717 if (m_cdData.count() < 1)
1718 return false;
1719
1720 return m_cdData.last()->FormatTitle() == the_track->FormatTitle();
1721}
1722
1724{
1725 for (auto *anit : std::as_const(m_cdData))
1726 {
1727 if (anit->Track() == the_track)
1728 {
1729 return anit;
1730 }
1731 }
1732
1733 return nullptr;
1734}
1735
1736/**************************************************************************/
1737
1739{
1740 loadStreams();
1741}
1742
1744{
1745 while (!m_streamList.empty())
1746 {
1747 delete m_streamList.back();
1748 m_streamList.pop_back();
1749 }
1750}
1751
1753{
1754 for (int x = 0; x < m_streamList.count(); x++)
1755 {
1756 if (m_streamList.at(x)->ID() == an_id)
1757 return true;
1758 }
1759
1760 return false;
1761}
1762
1764{
1765 for (int x = 0; x < m_streamList.count(); x++)
1766 {
1767 if (m_streamList.at(x)->ID() == an_id)
1768 return m_streamList.at(x);
1769 }
1770
1771 return nullptr;
1772}
1773
1775{
1776 while (!m_streamList.empty())
1777 {
1778 delete m_streamList.back();
1779 m_streamList.pop_back();
1780 }
1781
1782 QString aquery = "SELECT intid, broadcaster, channel, description, url1, url2, url3, url4, url5,"
1783 "logourl, genre, metaformat, country, language, format "
1784 "FROM music_radios "
1785 "ORDER BY broadcaster,channel;";
1786
1788 if (!query.exec(aquery))
1789 MythDB::DBError("AllStream::loadStreams", query);
1790
1791 if (query.isActive() && query.size() > 0)
1792 {
1793 while (query.next())
1794 {
1795 UrlList urls;
1796 for (size_t x = 0; x < STREAMURLCOUNT; x++)
1797 urls[x] = query.value(4 + x).toString();
1798
1799 auto *mdata = new MusicMetadata(
1800 query.value(0).toInt(), // intid
1801 query.value(1).toString(), // broadcaster
1802 query.value(2).toString(), // channel
1803 query.value(3).toString(), // description
1804 urls, // array of 5 urls
1805 query.value(9).toString(), // logourl
1806 query.value(10).toString(), // genre
1807 query.value(11).toString(), // metadataformat
1808 query.value(12).toString(), // country
1809 query.value(13).toString(), // language
1810 query.value(14).toString()); // format
1811
1812 mdata->setRepo(RT_Radio);
1813
1814 m_streamList.append(mdata);
1815 }
1816 }
1817 else
1818 {
1819 LOG(VB_GENERAL, LOG_WARNING, "MythMusic hasn't found any radio streams!");
1820 }
1821}
1822
1824{
1825 // add the stream to the db
1827 query.prepare("INSERT INTO music_radios (broadcaster, channel, description, "
1828 "url1, url2, url3, url4, url5, "
1829 "logourl, genre, country, language, format, metaformat) "
1830 "VALUES (:BROADCASTER, :CHANNEL, :DESCRIPTION, :URL1, :URL2, :URL3, :URL4, :URL5, "
1831 ":LOGOURL, :GENRE, :COUNTRY, :LANGUAGE, :FORMAT, :METAFORMAT);");
1832 query.bindValueNoNull(":BROADCASTER", mdata->Broadcaster());
1833 query.bindValueNoNull(":CHANNEL", mdata->Channel());
1834 query.bindValueNoNull(":DESCRIPTION", mdata->Description());
1835 query.bindValueNoNull(":URL1", mdata->Url(0));
1836 query.bindValueNoNull(":URL2", mdata->Url(1));
1837 query.bindValueNoNull(":URL3", mdata->Url(2));
1838 query.bindValueNoNull(":URL4", mdata->Url(3));
1839 query.bindValueNoNull(":URL5", mdata->Url(4));
1840 query.bindValueNoNull(":LOGOURL", mdata->LogoUrl());
1841 query.bindValueNoNull(":GENRE", mdata->Genre());
1842 query.bindValueNoNull(":COUNTRY", mdata->Country());
1843 query.bindValueNoNull(":LANGUAGE", mdata->Language());
1844 query.bindValueNoNull(":FORMAT", mdata->Format());
1845 query.bindValueNoNull(":METAFORMAT", mdata->MetadataFormat());
1846
1847 if (!query.exec() || !query.isActive() || query.numRowsAffected() <= 0)
1848 {
1849 MythDB::DBError("music insert radio", query);
1850 return;
1851 }
1852
1853 mdata->setID(query.lastInsertId().toInt());
1854 mdata->setRepo(RT_Radio);
1855
1856 loadStreams();
1857}
1858
1860{
1861 // remove the stream from the db
1862 int id = ID_TO_ID(mdata->ID());
1864 query.prepare("DELETE FROM music_radios WHERE intid = :ID");
1865 query.bindValue(":ID", id);
1866
1867 if (!query.exec() || query.numRowsAffected() <= 0)
1868 {
1869 MythDB::DBError("AllStream::removeStream", query);
1870 return;
1871 }
1872
1873 loadStreams();
1874}
1875
1877{
1878 // update the stream in the db
1879 int id = ID_TO_ID(mdata->ID());
1881 query.prepare("UPDATE music_radios set broadcaster = :BROADCASTER, channel = :CHANNEL, description = :DESCRIPTION, "
1882 "url1 = :URL1, url2 = :URL2, url3 = :URL3, url4 = :URL4, url5 = :URL5, "
1883 "logourl = :LOGOURL, genre = :GENRE, country = :COUNTRY, language = :LANGUAGE, "
1884 "format = :FORMAT, metaformat = :METAFORMAT "
1885 "WHERE intid = :ID");
1886 query.bindValueNoNull(":BROADCASTER", mdata->Broadcaster());
1887 query.bindValueNoNull(":CHANNEL", mdata->Channel());
1888 query.bindValueNoNull(":DESCRIPTION", mdata->Description());
1889 query.bindValueNoNull(":URL1", mdata->Url(0));
1890 query.bindValueNoNull(":URL2", mdata->Url(1));
1891 query.bindValueNoNull(":URL3", mdata->Url(2));
1892 query.bindValueNoNull(":URL4", mdata->Url(3));
1893 query.bindValueNoNull(":URL5", mdata->Url(4));
1894 query.bindValueNoNull(":LOGOURL", mdata->LogoUrl());
1895 query.bindValueNoNull(":GENRE", mdata->Genre());
1896 query.bindValueNoNull(":COUNTRY", mdata->Country());
1897 query.bindValueNoNull(":LANGUAGE", mdata->Language());
1898 query.bindValueNoNull(":FORMAT", mdata->Format());
1899 query.bindValueNoNull(":METAFORMAT", mdata->MetadataFormat());
1900 query.bindValue(":ID", id);
1901
1902 if (!query.exec() || !query.isActive() || query.numRowsAffected() <= 0)
1903 {
1904 MythDB::DBError("AllStream::updateStream", query);
1905 return;
1906 }
1907
1908 loadStreams();
1909}
1910
1911/**************************************************************************/
1912
1914 : m_parent(metadata)
1915{
1916 if (loadFromDB)
1917 findImages();
1918}
1919
1921 : m_parent(metadata)
1922{
1923 for (const auto &srcImage : std::as_const(other.m_imageList))
1924 {
1925 m_imageList.append(new AlbumArtImage(srcImage));
1926 }
1927}
1928
1930{
1931 while (!m_imageList.empty())
1932 {
1933 delete m_imageList.back();
1934 m_imageList.pop_back();
1935 }
1936}
1937
1939{
1940 while (!m_imageList.empty())
1941 {
1942 delete m_imageList.back();
1943 m_imageList.pop_back();
1944 }
1945
1946 if (m_parent == nullptr)
1947 return;
1948
1949 int trackid = ID_TO_ID(m_parent->ID());
1950 int repo = ID_TO_REPO(m_parent->ID());
1951
1952 if (repo == RT_Radio)
1953 {
1955 //FIXME: this should work with the alternate urls as well eg url2, url3 etc
1956 query.prepare("SELECT logourl FROM music_radios WHERE url1 = :URL;");
1957 query.bindValue(":URL", m_parent->Filename());
1958 if (query.exec())
1959 {
1960 while (query.next())
1961 {
1962 QString logoUrl = query.value(0).toString();
1963
1964 auto *image = new AlbumArtImage();
1965 image->m_id = -1;
1966 image->m_filename = logoUrl;
1967 image->m_imageType = IT_FRONTCOVER;
1968 image->m_embedded = false;
1969 image->m_hostname = "";
1970 m_imageList.push_back(image);
1971 }
1972 }
1973 }
1974 else
1975 {
1976 if (trackid == 0)
1977 return;
1978
1979 QFileInfo fi(m_parent->Filename(false));
1980 QString dir = fi.path();
1981
1983 query.prepare("SELECT albumart_id, CONCAT_WS('/', music_directories.path, "
1984 "music_albumart.filename), music_albumart.filename, music_albumart.imagetype, "
1985 "music_albumart.embedded, music_albumart.hostname "
1986 "FROM music_albumart "
1987 "LEFT JOIN music_directories ON "
1988 "music_directories.directory_id = music_albumart.directory_id "
1989 "WHERE music_directories.path = :DIR "
1990 "OR song_id = :SONGID "
1991 "ORDER BY music_albumart.imagetype;");
1992 query.bindValue(":DIR", dir);
1993 query.bindValue(":SONGID", trackid);
1994 if (query.exec())
1995 {
1996 while (query.next())
1997 {
1998 auto *image = new AlbumArtImage();
1999 bool embedded = (query.value(4).toInt() == 1);
2000 image->m_id = query.value(0).toInt();
2001
2002 QUrl url(m_parent->Filename(true));
2003
2004 if (embedded)
2005 {
2006 if (url.scheme() == "myth")
2007 {
2008 image->m_filename = MythCoreContext::GenMythURL(url.host(), url.port(),
2009 QString("AlbumArt/") + query.value(1).toString(),
2010 "MusicArt");
2011 }
2012 else
2013 {
2014 image->m_filename = query.value(1).toString();
2015 }
2016 }
2017 else
2018 {
2019 if (url.scheme() == "myth")
2020 {
2021 image->m_filename = MythCoreContext::GenMythURL(url.host(), url.port(),
2022 query.value(1).toString(),
2023 "Music");
2024 }
2025 else
2026 {
2027 image->m_filename = query.value(1).toString();
2028 }
2029 }
2030
2031 image->m_imageType = (ImageType) query.value(3).toInt();
2032 image->m_embedded = embedded;
2033 image->m_hostname = query.value(5).toString();
2034
2035 m_imageList.push_back(image);
2036 }
2037 }
2038
2039 // add any artist images
2040 QString artist = m_parent->Artist().toLower();
2041 if (findIcon("artist", artist) != QString())
2042 {
2043 auto *image = new AlbumArtImage();
2044 image->m_id = -1;
2045 image->m_filename = findIcon("artist", artist);
2046 image->m_imageType = IT_ARTIST;
2047 image->m_embedded = false;
2048
2049 m_imageList.push_back(image);
2050 }
2051 }
2052}
2053
2055{
2056 MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack");
2057 auto *busy = new MythUIBusyDialog(tr("Scanning for music album art..."),
2058 popupStack, "scanbusydialog");
2059
2060 if (busy->Create())
2061 {
2062 popupStack->AddScreen(busy, false);
2063 }
2064 else
2065 {
2066 delete busy;
2067 busy = nullptr;
2068 }
2069
2070 QStringList strList;
2071 strList << "MUSIC_FIND_ALBUMART"
2072 << m_parent->Hostname()
2073 << QString::number(m_parent->ID())
2074 << "1";
2075
2076 auto *scanThread = new AlbumArtScannerThread(strList);
2077 scanThread->start();
2078
2079 while (scanThread->isRunning())
2080 {
2081 QCoreApplication::processEvents();
2082 usleep(1000);
2083 }
2084
2085 strList = scanThread->getResult();
2086
2087 delete scanThread;
2088
2089 if (busy)
2090 busy->Close();
2091
2092 while (!m_imageList.empty())
2093 {
2094 delete m_imageList.back();
2095 m_imageList.pop_back();
2096 }
2097
2098 for (int x = 2; x < strList.count(); x += 6)
2099 {
2100 auto *image = new AlbumArtImage;
2101 image->m_id = strList[x].toInt();
2102 image->m_imageType = (ImageType) strList[x + 1].toInt();
2103 image->m_embedded = (strList[x + 2].toInt() == 1);
2104 image->m_description = strList[x + 3];
2105
2106 if (image->m_embedded)
2107 {
2108 image->m_filename = MythCoreContext::GenMythURL(m_parent->Hostname(), 0,
2109 QString("AlbumArt/") + strList[x + 4],
2110 "MusicArt");
2111 }
2112 else
2113 {
2114 image->m_filename = MythCoreContext::GenMythURL(m_parent->Hostname(), 0,
2115 strList[x + 4],
2116 "Music");
2117 }
2118
2119 image->m_hostname = strList[x + 5];
2120
2121 LOG(VB_FILE, LOG_INFO, "AlbumArtImages::scanForImages found image");
2122 LOG(VB_FILE, LOG_INFO, QString("ID: %1").arg(image->m_id));
2123 LOG(VB_FILE, LOG_INFO, QString("ImageType: %1").arg(image->m_imageType));
2124 LOG(VB_FILE, LOG_INFO, QString("Embedded: %1").arg(image->m_embedded));
2125 LOG(VB_FILE, LOG_INFO, QString("Description: %1").arg(image->m_description));
2126 LOG(VB_FILE, LOG_INFO, QString("Filename: %1").arg(image->m_filename));
2127 LOG(VB_FILE, LOG_INFO, QString("Hostname: %1").arg(image->m_hostname));
2128 LOG(VB_FILE, LOG_INFO, "-------------------------------");
2129
2130 addImage(image);
2131
2132 delete image;
2133 }
2134}
2135
2137{
2138 for (auto *item : std::as_const(m_imageList))
2139 {
2140 if (item->m_imageType == type)
2141 return item;
2142 }
2143
2144 return nullptr;
2145}
2146
2148{
2149 for (auto *item : std::as_const(m_imageList))
2150 {
2151 if (item->m_id == imageID)
2152 return item;
2153 }
2154
2155 return nullptr;
2156}
2157
2159{
2160 QStringList paths;
2161
2162 for (const auto *item : std::as_const(m_imageList))
2163 paths += item->m_filename;
2164
2165 return paths;
2166}
2167
2169{
2170 if (index < (uint)m_imageList.size())
2171 return m_imageList[index];
2172
2173 return nullptr;
2174}
2175
2176// static method to get a translated type name from an ImageType
2178{
2179 // these const's should match the ImageType enum's
2180 static const std::array<const std::string,6> s_typeStrings {
2181 QT_TR_NOOP("Unknown"), // IT_UNKNOWN
2182 QT_TR_NOOP("Front Cover"), // IT_FRONTCOVER
2183 QT_TR_NOOP("Back Cover"), // IT_BACKCOVER
2184 QT_TR_NOOP("CD"), // IT_CD
2185 QT_TR_NOOP("Inlay"), // IT_INLAY
2186 QT_TR_NOOP("Artist"), // IT_ARTIST
2187 };
2188
2189 return QCoreApplication::translate("AlbumArtImages",
2190 s_typeStrings[type].c_str());
2191}
2192
2193// static method to get a filename from an ImageType
2195{
2196 // these const's should match the ImageType enum's
2197 static const std::array<const std::string,6> s_filenameStrings {
2198 QT_TR_NOOP("unknown"), // IT_UNKNOWN
2199 QT_TR_NOOP("front"), // IT_FRONTCOVER
2200 QT_TR_NOOP("back"), // IT_BACKCOVER
2201 QT_TR_NOOP("cd"), // IT_CD
2202 QT_TR_NOOP("inlay"), // IT_INLAY
2203 QT_TR_NOOP("artist") // IT_ARTIST
2204 };
2205
2206 return QCoreApplication::translate("AlbumArtImages",
2207 s_filenameStrings[type].c_str());
2208}
2209
2210// static method to guess the image type from the filename
2212{
2214
2215 if (filename.contains("front", Qt::CaseInsensitive) ||
2216 filename.contains(tr("front"), Qt::CaseInsensitive) ||
2217 filename.contains("cover", Qt::CaseInsensitive) ||
2218 filename.contains(tr("cover"), Qt::CaseInsensitive))
2220 else if (filename.contains("back", Qt::CaseInsensitive) ||
2221 filename.contains(tr("back"), Qt::CaseInsensitive))
2223 else if (filename.contains("inlay", Qt::CaseInsensitive) ||
2224 filename.contains(tr("inlay"), Qt::CaseInsensitive))
2225 type = IT_INLAY;
2226 else if (filename.contains("cd", Qt::CaseInsensitive) ||
2227 filename.contains(tr("cd"), Qt::CaseInsensitive))
2228 type = IT_CD;
2229
2230 return type;
2231}
2232
2233// static method to get image type from the type name
2235{
2237
2238 if (name.toLower() == "front")
2240 else if (name.toLower() == "back")
2242 else if (name.toLower() == "inlay")
2243 type = IT_INLAY;
2244 else if (name.toLower() == "cd")
2245 type = IT_CD;
2246 else if (name.toLower() == "artist")
2247 type = IT_ARTIST;
2248 else if (name.toLower() == "unknown")
2249 type = IT_UNKNOWN;
2250
2251 return type;
2252}
2253
2254void AlbumArtImages::addImage(const AlbumArtImage * const newImage)
2255{
2256 // do we already have an image of this type?
2257 AlbumArtImage *image = nullptr;
2258
2259 for (auto *item : std::as_const(m_imageList))
2260 {
2261 if (item->m_imageType == newImage->m_imageType
2262 && item->m_embedded == newImage->m_embedded)
2263 {
2264 image = item;
2265 break;
2266 }
2267 }
2268
2269 if (!image)
2270 {
2271 // not found so just add it to the list
2272 image = new AlbumArtImage(newImage);
2273 m_imageList.push_back(image);
2274 }
2275 else
2276 {
2277 // we already have an image of this type so just update it with the new info
2278 image->m_filename = newImage->m_filename;
2279 image->m_imageType = newImage->m_imageType;
2280 image->m_embedded = newImage->m_embedded;
2281 image->m_description = newImage->m_description;
2282 image->m_hostname = newImage->m_hostname;
2283 }
2284}
2285
2288{
2290 int directoryID = m_parent->getDirectoryId();
2291
2292 // sanity check we have a valid songid and directoryid
2293 if (trackID == 0 || directoryID == -1)
2294 {
2295 LOG(VB_GENERAL, LOG_ERR, "AlbumArtImages: Asked to save to the DB but "
2296 "have invalid songid or directoryid");
2297 return;
2298 }
2299
2301
2302 // remove all albumart for this track from the db
2303 query.prepare("DELETE FROM music_albumart "
2304 "WHERE song_id = :SONGID "
2305 "OR (embedded = 0 AND directory_id = :DIRECTORYID)");
2306
2307 query.bindValue(":SONGID", trackID);
2308 query.bindValue(":DIRECTORYID", directoryID);
2309
2310 if (!query.exec())
2311 {
2312 MythDB::DBError("AlbumArtImages::dumpToDatabase - "
2313 "deleting existing albumart", query);
2314 }
2315
2316 // now add the albumart to the db
2317 for (auto *image : std::as_const(m_imageList))
2318 {
2319 //TODO: for the moment just ignore artist images
2320 if (image->m_imageType == IT_ARTIST)
2321 continue;
2322
2323 if (image->m_id > 0)
2324 {
2325 // re-use the same id this image had before
2326 query.prepare("INSERT INTO music_albumart ( albumart_id, "
2327 "filename, imagetype, song_id, directory_id, embedded, hostname ) "
2328 "VALUES ( :ID, :FILENAME, :TYPE, :SONGID, :DIRECTORYID, :EMBED, :HOSTNAME );");
2329 query.bindValue(":ID", image->m_id);
2330 }
2331 else
2332 {
2333 query.prepare("INSERT INTO music_albumart ( filename, "
2334 "imagetype, song_id, directory_id, embedded, hostname ) VALUES ( "
2335 ":FILENAME, :TYPE, :SONGID, :DIRECTORYID, :EMBED, :HOSTNAME );");
2336 }
2337
2338 QFileInfo fi(image->m_filename);
2339 query.bindValue(":FILENAME", fi.fileName());
2340
2341 query.bindValue(":TYPE", image->m_imageType);
2342 query.bindValue(":SONGID", image->m_embedded ? trackID : 0);
2343 query.bindValue(":DIRECTORYID", image->m_embedded ? 0 : directoryID);
2344 query.bindValue(":EMBED", image->m_embedded);
2345 query.bindValue(":HOSTNAME", image->m_hostname);
2346
2347 if (!query.exec())
2348 {
2349 MythDB::DBError("AlbumArtImages::dumpToDatabase - "
2350 "add/update music_albumart", query);
2351 }
2352 else
2353 {
2354 if (image->m_id <= 0)
2355 image->m_id = query.lastInsertId().toInt();
2356 }
2357 }
2358}
2359
2361{
2362 RunProlog();
2364 RunEpilog();
2365}
QString m_filename
Definition: musicmetadata.h:55
QString m_description
Definition: musicmetadata.h:58
ImageType m_imageType
Definition: musicmetadata.h:57
QString m_hostname
Definition: musicmetadata.h:56
AlbumArtList * getImageList(void)
AlbumArtImage * getImage(ImageType type)
MusicMetadata * m_parent
void scanForImages(void)
static QString getTypeFilename(ImageType type)
AlbumArtImage * getImageAt(uint index)
static QString getTypeName(ImageType type)
void dumpToDatabase(void)
saves or updates the image details in the DB
QStringList getImageFilenames(void) const
AlbumArtImages(MusicMetadata *metadata, bool loadFromDB=true)
AlbumArtList m_imageList
void findImages(void)
void addImage(const AlbumArtImage *newImage)
static ImageType guessImageType(const QString &filename)
static ImageType getImageTypeFromName(const QString &name)
AlbumArtImage * getImageByID(int imageID)
void run() override
Runs the Qt event loop unless we have a QRunnable, in which case we run the runnable run instead.
int m_playCountMin
int m_playCountMax
MetadataLoadingThread * m_metadataLoader
MusicMetadata * getCDMetadata(int m_the_track)
bool startLoading(void)
Start loading metadata.
void addCDTrack(const MusicMetadata &the_track)
void resync()
resync our cache with the database
MusicMap m_musicMap
MusicMetadata * getMetadata(int an_id)
int m_numLoaded
void clearCDData(void)
bool checkCDTrack(MusicMetadata *the_track)
bool m_doneLoading
bool cleanOutThreads()
QString m_cdTitle
bool isValidID(int an_id)
void save()
Check each MusicMetadata entry and save those that have changed (ratings, etc.)
bool updateMetadata(int an_id, MusicMetadata *the_track)
MetadataPtrList m_allMusic
qint64 m_lastPlayMin
qint64 m_lastPlayMax
MetadataPtrList m_cdData
void removeStream(MusicMetadata *mdata)
bool isValidID(MusicMetadata::IdType an_id)
StreamList m_streamList
void loadStreams(void)
void updateStream(MusicMetadata *mdata)
MusicMetadata * getMetadata(MusicMetadata::IdType an_id)
void addStream(MusicMetadata *mdata)
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
int size(void) const
Definition: mythdbcon.h:214
int numRowsAffected() const
Definition: mythdbcon.h:217
bool isActive(void) const
Definition: mythdbcon.h:215
void bindValueNoNull(const QString &placeholder, const QVariant &val)
Add a single binding, taking care not to set a NULL value.
Definition: mythdbcon.cpp:902
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
QVariant lastInsertId()
Return the id of the last inserted row.
Definition: mythdbcon.cpp:935
int at(void) const
Definition: mythdbcon.h:221
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
void RunProlog(void)
Sets up a thread, call this if you reimplement run().
Definition: mthread.cpp:196
bool isFinished(void) const
Definition: mthread.cpp:258
void start(QThread::Priority p=QThread::InheritPriority)
Tell MThread to start running the thread in the near future.
Definition: mthread.cpp:283
void RunEpilog(void)
Cleans up a thread's resources, call this if you reimplement run().
Definition: mthread.cpp:209
bool wait(std::chrono::milliseconds time=std::chrono::milliseconds::max())
Wait for the MThread to exit, with a maximum timeout.
Definition: mthread.cpp:300
Definition: metaio.h:18
static MetaIO * createTagger(const QString &filename)
Finds an appropriate tagger for the given file.
Definition: metaio.cpp:31
void run() override
Runs the Qt event loop unless we have a QRunnable, in which case we run the runnable run instead.
LyricsData * getLyricsData(void)
QString m_formattedTitle
void setRepo(RepoType repo)
bool isRadio(void) const
void getField(const QString &field, QString *data)
QString m_albumSort
QString m_format
QString m_description
void persist(void)
void setID(IdType lid)
static MusicMetadata * createFromFilename(const QString &filename)
QString m_compilationArtistSort
QString Language(void)
static QString s_formatCompilationCdArtist
static QString s_formatNormalCdArtist
QString m_artistSort
AlbumArtImages * m_albumArt
void reloadMetadata(void)
QString Country(void)
static QString s_formatNormalCdTrack
QString Hostname(void)
std::chrono::milliseconds m_length
QString m_titleSort
static QString s_formatNormalFileArtist
void setCompilationFormatting(bool cd=false)
static QStringList fillFieldList(const QString &field)
QString m_logoUrl
QString FormatArtist()
QString formatReplaceSymbols(const QString &format)
void toMap(InfoMap &metadataMap, const QString &prefix="")
void ensureSortFields(void)
QString Broadcaster(void)
LyricsData * m_lyricsData
QString m_country
QString m_artist
void reloadAlbumArtImages(void)
QString MetadataFormat(void)
void setFilename(const QString &lfilename)
QString getAlbumArtFile(void)
QString m_language
void setEmbeddedAlbumArt(AlbumArtList &albumart)
QString m_broadcaster
QString m_hostname
QString Channel(void)
QString m_filename
IdType ID() const
QString Filename(bool find=true)
QString Artist() const
QString m_actualFilename
QString Url(size_t index=0)
QString getLocalFilename(void)
try to find the track on the local file system
QString LogoUrl(void)
bool compare(MusicMetadata *mdata) const
static QString s_formatNormalFileTrack
static void setArtistAndTrackFormats()
void setField(const QString &field, const QString &data)
QDateTime m_dateAdded
QString Format() const
QString m_compilationArtist
QDateTime m_lastPlay
bool determineIfCompilation(bool cd=false)
MusicMetadata(QString lfilename="", QString lartist="", QString lcompilation_artist="", QString lalbum="", QString ltitle="", QString lgenre="", int lyear=0, int ltracknum=0, std::chrono::milliseconds llength=0ms, int lid=0, int lrating=0, int lplaycount=0, QDateTime llastplay=QDateTime(), QDateTime ldateadded=QDateTime(), bool lcompilation=false, QString lformat="")
Definition: musicmetadata.h:93
uint32_t IdType
Definition: musicmetadata.h:91
QString Genre() const
int getCompilationArtistId()
AlbumArtImages * getAlbumArtImages(void)
static MusicMetadata * createFromID(int trackid)
MetaIO * getTagger(void)
QString FormatTitle()
uint64_t m_fileSize
MusicMetadata & operator=(const MusicMetadata &rhs)
QDateTime m_tempLastPlay
void saveHostname(void)
static QString s_formatCompilationFileTrack
QString Description(void)
void setUrl(const QString &url, size_t index=0)
QString m_channel
QString m_metaFormat
static bool updateStreamList(void)
static QString s_formatCompilationFileArtist
void checkEmptyFields(void)
void dumpToDatabase(void)
static QString s_formatCompilationCdTrack
QString m_formattedArtist
QString GetHostName(void)
QLocale GetQLocale(void)
QString GetSetting(const QString &key, const QString &defaultval="")
bool SaveSettingOnHost(const QString &key, const QString &newValue, const QString &host)
void SendMessage(const QString &message)
bool SendReceiveStringList(QStringList &strlist, bool quickTimeout=false, bool block=true)
Send a message to the backend and wait for a response.
static QString GenMythURL(const QString &host=QString(), int port=0, QString path=QString(), const QString &storageGroup=QString())
QString GetMasterHostName(void)
bool IsMasterBackend(void)
is this the actual MBE process
static void DBError(const QString &where, const MSqlQuery &query)
Definition: mythdb.cpp:226
QDateTime GetLastModified(const QString &url)
Gets the Last Modified timestamp for a URI.
MythScreenStack * GetStack(const QString &Stackname)
virtual void AddScreen(MythScreenType *screen, bool allowFade=true)
static MythSystem * Create(const QStringList &args, uint flags=kMSNone, const QString &startPath=QString(), Priority cpuPriority=kInheritPriority, Priority diskPriority=kInheritPriority)
Definition: mythsystem.cpp:205
static QString FindFile(const QString &filename, const QString &host, const QString &storageGroup, bool useRegex=false, bool allowFallback=false)
Search all BE's for a file in the give storage group.
static bool Exists(const QString &url, struct stat *fileinfo)
Definition: remotefile.cpp:461
QString FindFile(const QString &filename)
static pid_list_t::iterator find(const PIDInfoMap &map, pid_list_t &list, pid_list_t::iterator begin, pid_list_t::iterator end, bool find_open)
unsigned int uint
Definition: freesurround.h:24
static guint32 * tmp
Definition: goom_core.cpp:26
bool operator==(MusicMetadata &a, MusicMetadata &b)
bool operator!=(MusicMetadata &a, MusicMetadata &b)
static QString thePrefix
ImageType
Definition: musicmetadata.h:35
@ IT_INLAY
Definition: musicmetadata.h:40
@ IT_BACKCOVER
Definition: musicmetadata.h:38
@ IT_UNKNOWN
Definition: musicmetadata.h:36
@ IT_FRONTCOVER
Definition: musicmetadata.h:37
@ IT_ARTIST
Definition: musicmetadata.h:41
@ IT_CD
Definition: musicmetadata.h:39
@ RT_Radio
Definition: musicmetadata.h:68
@ RT_CD
Definition: musicmetadata.h:67
static constexpr const char * METADATA_INVALID_FILENAME
Definition: musicmetadata.h:79
QList< AlbumArtImage * > AlbumArtList
Definition: musicmetadata.h:62
static constexpr size_t STREAMURLCOUNT
Definition: musicmetadata.h:81
std::array< QString, STREAMURLCOUNT > UrlList
Definition: musicmetadata.h:83
static constexpr uint32_t ID_TO_ID(uint32_t x)
Definition: musicmetadata.h:76
static constexpr uint32_t ID_TO_REPO(uint32_t x)
Definition: musicmetadata.h:77
QString findIcon(const QString &type, const QString &name, bool ignoreCache)
find an image for a artist or genre
Definition: musicutils.cpp:34
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
MythDB * GetMythDB(void)
Definition: mythdb.cpp:51
QString GetConfDir(void)
Definition: mythdirs.cpp:263
MythDownloadManager * GetMythDownloadManager(void)
Gets the pointer to the MythDownloadManager singleton.
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
MythMainWindow * GetMythMainWindow(void)
std::shared_ptr< MythSortHelper > getMythSortHelper(void)
Get a pointer to the MythSortHelper singleton.
@ kMSDontBlockInputDevs
avoid blocking LIRC & Joystick Menu
Definition: mythsystem.h:36
@ kMSProcessEvents
process events while waiting
Definition: mythsystem.h:39
@ kMSRunBackground
run child in the background
Definition: mythsystem.h:38
@ kMSDontDisableDrawing
avoid disabling UI drawing
Definition: mythsystem.h:37
@ kMSAutoCleanup
automatically delete if backgrounded
Definition: mythsystem.h:45
QHash< QString, QString > InfoMap
Definition: mythtypes.h:15
QString formatTime(std::chrono::milliseconds msecs, QString fmt)
Format a milliseconds time value.
Definition: mythdate.cpp:242
QDateTime as_utc(const QDateTime &old_dt)
Returns copy of QDateTime with TimeSpec set to UTC.
Definition: mythdate.cpp:28
QString toString(const QDateTime &raw_dt, uint format)
Returns formatted string representing the time.
Definition: mythdate.cpp:93
@ kSimplify
Do Today/Yesterday/Tomorrow transform.
Definition: mythdate.h:26
@ kDateFull
Default local time.
Definition: mythdate.h:19
@ ISODate
Default UTC.
Definition: mythdate.h:17
@ kAddYear
Add year to string if not included.
Definition: mythdate.h:25
QDateTime fromString(const QString &dtstr)
Converts kFilename && kISODate formats to QDateTime.
Definition: mythdate.cpp:39
QDateTime current(bool stripped)
Returns current Date and Time in UTC.
Definition: mythdate.cpp:15
STL namespace.
bool exists(str path)
Definition: xbmcvfs.py:51
QDateTime lastUpdate(GrabberScript *script)
Definition: netutils.cpp:338
QByteArray gzipUncompress(const QByteArray &data)
Definition: unziputil.cpp:150