MythTV  master
playlist.cpp
Go to the documentation of this file.
1 #include <algorithm>
2 #include <cinttypes>
3 #include <cstdlib>
4 #include <map>
5 #include <unistd.h>
6 
7 // qt
8 #include <QApplication>
9 #include <QFileInfo>
10 #include <QObject>
11 
12 // mythmusic
13 #include "musicdata.h"
14 #include "playlist.h"
15 #include "playlistcontainer.h"
16 #include "smartplaylist.h"
17 #include "musicplayer.h"
18 
19 // mythtv
20 #include <mythcontext.h>
21 #include <mythdb.h>
22 #include <compat.h>
23 #include <mythmediamonitor.h>
24 #include <mythmiscutil.h>
25 #include <mythsystemlegacy.h>
26 #include <exitcodes.h>
27 
29 // Playlist
30 
31 #define LOC QString("Playlist: ")
32 #define LOC_WARN QString("Playlist, Warning: ")
33 #define LOC_ERR QString("Playlist, Error: ")
34 
36 {
37  return m_songs.contains(trackID);
38 }
39 
40 void Playlist::copyTracks(Playlist *to_ptr, bool update_display)
41 {
42  disableSaves();
43 
44  for (int x = 0; x < m_songs.size(); x++)
45  {
46  MusicMetadata *mdata = getRawSongAt(x);
47  if (mdata)
48  {
49  if (mdata->isDBTrack())
50  to_ptr->addTrack(mdata->ID(), update_display);
51  }
52  }
53 
54  enableSaves();
55 
56  changed();
57 }
58 
60 void Playlist::addTrack(MusicMetadata::IdType trackID, bool update_display)
61 {
62  int repo = ID_TO_REPO(trackID);
63  MusicMetadata *mdata = nullptr;
64 
65  if (repo == RT_Radio)
66  mdata = gMusicData->m_all_streams->getMetadata(trackID);
67  else
68  mdata = gMusicData->m_all_music->getMetadata(trackID);
69 
70  if (mdata)
71  {
72  m_songs.push_back(trackID);
73  m_shuffledSongs.push_back(trackID);
74 
75  changed();
76 
77  if (update_display && isActivePlaylist())
78  gPlayer->activePlaylistChanged(trackID, false);
79  }
80  else
81  LOG(VB_GENERAL, LOG_ERR, LOC + "Can't add track, given a bad track ID");
82 }
83 
85 {
86  m_songs.clear();
87  m_shuffledSongs.clear();
88 
89  changed();
90 }
91 
93 {
94  // find the cd tracks
95  SongList cdTracks;
96  for (int x = 0; x < m_songs.count(); x++)
97  {
98  MusicMetadata *mdata = getRawSongAt(x);
99 
100  if (mdata && mdata->isCDTrack())
101  cdTracks.append(m_songs.at(x));
102  }
103 
104  // remove the tracks from our lists
105  for (int x = 0; x < cdTracks.count(); x++)
106  {
107  m_songs.removeAll(cdTracks.at(x));
108  m_shuffledSongs.removeAll(cdTracks.at(x));;
109  }
110 
111  changed();
112 }
113 
115 {
116  m_songs.removeAll(trackID);
117  m_shuffledSongs.removeAll(trackID);
118 
119  changed();
120 
121  if (isActivePlaylist())
122  gPlayer->activePlaylistChanged(trackID, true);
123 }
124 
125 void Playlist::moveTrackUpDown(bool flag, int where_its_at)
126 {
127  uint insertion_point = 0;
128  MusicMetadata::IdType id = m_shuffledSongs.at(where_its_at);
129 
130  if (flag)
131  insertion_point = ((uint)where_its_at) - 1;
132  else
133  insertion_point = ((uint)where_its_at) + 1;
134 
135  m_shuffledSongs.removeAt(where_its_at);
136  m_shuffledSongs.insert(insertion_point, id);
137 
138  changed();
139 }
140 
142  m_name(tr("oops"))
143 {
144 }
145 
147 {
148  m_songs.clear();
149  m_shuffledSongs.clear();
150 }
151 
153 {
154  m_shuffledSongs.clear();
155 
156  switch (shuffleMode)
157  {
159  {
160  QMultiMap<int, MusicMetadata::IdType> songMap;
161 
162  for (int x = 0; x < m_songs.count(); x++)
163  {
164  // Pseudo-random is good enough. Don't need a true random.
165  // NOLINTNEXTLINE(cert-msc30-c,cert-msc50-cpp)
166  songMap.insert(rand(), m_songs.at(x));
167  }
168 
169  QMultiMap<int, MusicMetadata::IdType>::const_iterator i = songMap.constBegin();
170  while (i != songMap.constEnd())
171  {
172  m_shuffledSongs.append(i.value());
173  ++i;
174  }
175 
176  break;
177  }
178 
180  {
181  int RatingWeight = 2;
182  int PlayCountWeight = 2;
183  int LastPlayWeight = 2;
184  int RandomWeight = 2;
185  m_parent->FillIntelliWeights(RatingWeight, PlayCountWeight,
186  LastPlayWeight, RandomWeight);
187 
188  // compute max/min playcount,lastplay for this playlist
189  int playcountMin = 0;
190  int playcountMax = 0;
191  double lastplayMin = 0.0;
192  double lastplayMax = 0.0;
193 
194  for (int x = 0; x < m_songs.count(); x++)
195  {
196  MusicMetadata *mdata = getRawSongAt(x);
197  if (!mdata)
198  continue;
199 
200  if (!mdata->isCDTrack())
201  {
202 
203  if (0 == x)
204  {
205  // first song
206  playcountMin = playcountMax = mdata->PlayCount();
207  lastplayMin = lastplayMax = mdata->LastPlay().toSecsSinceEpoch();
208  }
209  else
210  {
211  if (mdata->PlayCount() < playcountMin)
212  playcountMin = mdata->PlayCount();
213  else if (mdata->PlayCount() > playcountMax)
214  playcountMax = mdata->PlayCount();
215 
216  double lastplaysecs = mdata->LastPlay().toSecsSinceEpoch();
217  if (lastplaysecs < lastplayMin)
218  lastplayMin = lastplaysecs;
219  else if (lastplaysecs > lastplayMax)
220  lastplayMax = lastplaysecs;
221  }
222  }
223  }
224 
225  // next we compute all the weights
226  std::map<int,double> weights;
227  std::map<int,int> ratings;
228  std::map<int,int> ratingCounts;
229  int TotalWeight = RatingWeight + PlayCountWeight + LastPlayWeight;
230  for (int x = 0; x < m_songs.size(); x++)
231  {
232  MusicMetadata *mdata = getRawSongAt(x);
233  if (mdata && !mdata->isCDTrack())
234  {
235  int rating = mdata->Rating();
236  int playcount = mdata->PlayCount();
237  double lastplaydbl = mdata->LastPlay().toSecsSinceEpoch();
238  double ratingValue = (double)(rating) / 10;
239  double playcountValue = NAN;
240  double lastplayValue = NAN;
241 
242  if (playcountMax == playcountMin)
243  playcountValue = 0;
244  else
245  playcountValue = ((playcountMin - (double)playcount) / (playcountMax - playcountMin) + 1);
246 
247  if (lastplayMax == lastplayMin)
248  lastplayValue = 0;
249  else
250  lastplayValue = ((lastplayMin - lastplaydbl) / (lastplayMax - lastplayMin) + 1);
251 
252  double weight = (RatingWeight * ratingValue +
253  PlayCountWeight * playcountValue +
254  LastPlayWeight * lastplayValue) / TotalWeight;
255  weights[mdata->ID()] = weight;
256  ratings[mdata->ID()] = rating;
257  ++ratingCounts[rating];
258  }
259  }
260 
261  // then we divide weights with the number of songs in the rating class
262  // (more songs in a class ==> lower weight, without affecting other classes)
263  double totalWeights = 0;
264  auto weightsEnd = weights.end();
265  for (auto weightsIt = weights.begin() ; weightsIt != weightsEnd ; ++weightsIt)
266  {
267  weightsIt->second /= ratingCounts[ratings[weightsIt->first]];
268  totalWeights += weightsIt->second;
269  }
270 
271  // then we get a random order, balanced with relative weights of remaining songs
272  std::map<int,uint32_t> order;
273  uint32_t orderCpt = 1;
274  while (!weights.empty())
275  {
276  // Pseudo-random is good enough. Don't need a true random.
277  // NOLINTNEXTLINE(cert-msc30-c,cert-msc50-cpp)
278  double hit = totalWeights * (double)rand() / (double)RAND_MAX;
279  auto weightEnd = weights.end();
280  auto weightIt = weights.begin();
281  double pos = 0;
282  while (weightIt != weightEnd)
283  {
284  pos += weightIt->second;
285  if (pos >= hit)
286  break;
287  ++weightIt;
288  }
289 
290  // FIXME If we don't exit here then we'll segfault, but it
291  // probably won't give us the desired randomisation
292  // either - There seems to be a flaw in this code, we
293  // erase items from the map but never adjust
294  // 'totalWeights' so at a point 'pos' will never be
295  // greater or equal to 'hit' and we will always hit the
296  // end of the map
297  if (weightIt == weightEnd)
298  break;
299 
300  order[weightIt->first] = orderCpt;
301  totalWeights -= weightIt->second;
302  weights.erase(weightIt);
303  ++orderCpt;
304  }
305 
306  // create a map of tracks sorted by the computed order
307  QMultiMap<int, MusicMetadata::IdType> songMap;
308  for (int x = 0; x < m_songs.count(); x++)
309  songMap.insert(order[m_songs.at(x)], m_songs.at(x));
310 
311  // copy the shuffled tracks to the shuffled song list
312  QMultiMap<int, MusicMetadata::IdType>::const_iterator i = songMap.constBegin();
313  while (i != songMap.constEnd())
314  {
315  m_shuffledSongs.append(i.value());
316  ++i;
317  }
318 
319  break;
320  }
321 
323  {
324  // "intellegent/album" order
325 
326  using AlbumMap = std::map<QString, uint32_t>;
327  AlbumMap album_map;
328  AlbumMap::iterator Ialbum;
329  QString album;
330 
331  // pre-fill the album-map with the album name.
332  // This allows us to do album mode in album order
333  for (int x = 0; x < m_songs.count(); x++)
334  {
335  MusicMetadata *mdata = getRawSongAt(x);
336  if (mdata)
337  {
338  album = mdata->Album() + " ~ " + QString("%1").arg(mdata->getAlbumId());
339  if ((Ialbum = album_map.find(album)) == album_map.end())
340  album_map.insert(AlbumMap::value_type(album, 0));
341  }
342  }
343 
344  // populate the sort id into the album map
345  uint32_t album_count = 1;
346  for (Ialbum = album_map.begin(); Ialbum != album_map.end(); ++Ialbum)
347  {
348  Ialbum->second = album_count;
349  album_count++;
350  }
351 
352  // create a map of tracks sorted by the computed order
353  QMultiMap<int, MusicMetadata::IdType> songMap;
354  for (int x = 0; x < m_songs.count(); x++)
355  {
356  MusicMetadata *mdata = getRawSongAt(x);
357  if (mdata)
358  {
359  uint32_t album_order = 1;
360  album = album = mdata->Album() + " ~ " + QString("%1").arg(mdata->getAlbumId());;
361  if ((Ialbum = album_map.find(album)) == album_map.end())
362  {
363  // we didn't find this album in the map,
364  // yet we pre-loaded them all. we are broken,
365  // but we just set the track order to 1, since there
366  // is no real point in reporting an error
367  album_order = 1;
368  }
369  else
370  {
371  album_order = Ialbum->second * 10000;
372  }
373  if (mdata->DiscNumber() != -1)
374  album_order += mdata->DiscNumber()*100;
375  album_order += mdata->Track();
376 
377  songMap.insert(album_order, m_songs.at(x));
378  }
379  }
380 
381  // copy the shuffled tracks to the shuffled song list
382  QMultiMap<int, MusicMetadata::IdType>::const_iterator i = songMap.constBegin();
383  while (i != songMap.constEnd())
384  {
385  m_shuffledSongs.append(i.value());
386  ++i;
387  }
388 
389  break;
390  }
391 
393  {
394  // "intellegent/album" order
395 
396  using ArtistMap = std::map<QString, uint32_t>;
397  ArtistMap artist_map;
398  ArtistMap::iterator Iartist;
399  QString artist;
400 
401  // pre-fill the album-map with the album name.
402  // This allows us to do artist mode in artist order
403  for (int x = 0; x < m_songs.count(); x++)
404  {
405  MusicMetadata *mdata = getRawSongAt(x);
406  if (mdata)
407  {
408  artist = mdata->Artist() + " ~ " + mdata->Title();
409  if ((Iartist = artist_map.find(artist)) == artist_map.end())
410  artist_map.insert(ArtistMap::value_type(artist,0));
411  }
412  }
413 
414  // populate the sort id into the artist map
415  uint32_t artist_count = 1;
416  for (Iartist = artist_map.begin(); Iartist != artist_map.end(); ++Iartist)
417  {
418  Iartist->second = artist_count;
419  artist_count++;
420  }
421 
422  // create a map of tracks sorted by the computed order
423  QMultiMap<int, MusicMetadata::IdType> songMap;
424  for (int x = 0; x < m_songs.count(); x++)
425  {
426  MusicMetadata *mdata = getRawSongAt(x);
427  if (mdata)
428  {
429  uint32_t artist_order = 1;
430  artist = mdata->Artist() + " ~ " + mdata->Title();
431  if ((Iartist = artist_map.find(artist)) == artist_map.end())
432  {
433  // we didn't find this artist in the map,
434  // yet we pre-loaded them all. we are broken,
435  // but we just set the track order to 1, since there
436  // is no real point in reporting an error
437  artist_order = 1;
438  }
439  else
440  {
441  artist_order = Iartist->second * 1000;
442  }
443  artist_order += mdata->Track();
444 
445  songMap.insert(artist_order, m_songs.at(x));
446  }
447  }
448 
449  // copy the shuffled tracks to the shuffled song list
450  QMultiMap<int, MusicMetadata::IdType>::const_iterator i = songMap.constBegin();
451  while (i != songMap.constEnd())
452  {
453  m_shuffledSongs.append(i.value());
454  ++i;
455  }
456 
457  break;
458  }
459 
460  default:
461  {
462  // copy the raw song list to the shuffled track list
463  // NOLINTNEXTLINE(modernize-loop-convert)
464  for (auto it = m_songs.begin(); it != m_songs.end(); ++it)
465  m_shuffledSongs.append(*it);
466 
467  break;
468  }
469  }
470 }
471 
473 {
474  // This is for debugging
475 #if 0
476  LOG(VB_GENERAL, LOG_DEBUG,
477  QString("Playlist with name of \"%1\"").arg(name));
478  LOG(VB_GENERAL, LOG_DEBUG,
479  QString(" playlistid is %1").arg(laylistid));
480  LOG(VB_GENERAL, LOG_DEBUG,
481  QString(" songlist(raw) is \"%1\"").arg(raw_songlist));
482  LOG(VB_GENERAL, LOG_DEBUG, " songlist list is ");
483 #endif
484 
485  QString msg;
486  for (int x = 0; x < m_songs.count(); x++)
487  msg += QString("%1,").arg(m_songs.at(x));
488 
489  LOG(VB_GENERAL, LOG_INFO, LOC + msg);
490 }
491 
492 void Playlist::getStats(uint *trackCount, uint *totalLength, uint currenttrack, uint *playedLength) const
493 {
494  uint64_t total = 0;
495  uint64_t played = 0;
496 
497  *trackCount = m_shuffledSongs.size();
498 
499  if ((int)currenttrack >= m_shuffledSongs.size())
500  currenttrack = 0;
501 
502  for (int x = 0; x < m_shuffledSongs.count(); x++)
503  {
504  MusicMetadata *mdata = getSongAt(x);
505  if (mdata)
506  {
507  total += mdata->Length();
508  if (x < (int)currenttrack)
509  played += mdata->Length();
510  }
511  }
512 
513  if (playedLength)
514  *playedLength = played / 1000;
515 
516  *totalLength = total / 1000;
517 }
518 
519 void Playlist::loadPlaylist(const QString& a_name, const QString& a_host)
520 {
521  QString rawSonglist;
522 
523  if (a_host.isEmpty())
524  {
525  LOG(VB_GENERAL, LOG_ERR, LOC +
526  "loadPlaylist() - We need a valid hostname");
527  return;
528  }
529 
531 
532  if (m_name == "default_playlist_storage" ||
533  m_name == "stream_playlist")
534  {
535  query.prepare("SELECT playlist_id, playlist_name, playlist_songs "
536  "FROM music_playlists "
537  "WHERE playlist_name = :NAME"
538  " AND hostname = :HOST;");
539  }
540  else
541  {
542  // Technically this is never called as this function
543  // is only used to load the default playlist.
544  query.prepare("SELECT playlist_id, playlist_name, playlist_songs "
545  "FROM music_playlists "
546  "WHERE playlist_name = :NAME"
547  " AND (hostname = '' OR hostname = :HOST);");
548  }
549  query.bindValue(":NAME", a_name);
550  query.bindValue(":HOST", a_host);
551 
552  if (query.exec() && query.size() > 0)
553  {
554  while (query.next())
555  {
556  m_playlistid = query.value(0).toInt();
557  m_name = query.value(1).toString();
558  rawSonglist = query.value(2).toString();
559  }
560  }
561  else
562  {
563  // Asked me to load a playlist I can't find so let's create a new one :)
564  m_playlistid = 0; // Be safe just in case we call load over the top
565  // of an existing playlist
566  rawSonglist.clear();
567  savePlaylist(a_name, a_host);
568  }
569 
570  fillSongsFromSonglist(rawSonglist);
571 
573 }
574 
575 void Playlist::loadPlaylistByID(int id, const QString& a_host)
576 {
577  QString rawSonglist;
579  query.prepare("SELECT playlist_id, playlist_name, playlist_songs "
580  "FROM music_playlists "
581  "WHERE playlist_id = :ID"
582  " AND (hostname = '' OR hostname = :HOST);");
583  query.bindValue(":ID", id);
584  query.bindValue(":HOST", a_host);
585 
586  if (!query.exec())
587  MythDB::DBError("Playlist::loadPlaylistByID", query);
588 
589  while (query.next())
590  {
591  m_playlistid = query.value(0).toInt();
592  m_name = query.value(1).toString();
593  rawSonglist = query.value(2).toString();
594  }
595 
596  if (m_name == "default_playlist_storage")
597  m_name = tr("Default Playlist");
598 
599  fillSongsFromSonglist(rawSonglist);
600 }
601 
604 {
605  bool needUpdate = false;
606 
607  for (int x = 0; x < m_songs.count(); x++)
608  {
609  MusicMetadata::IdType id = m_songs.at(x);
610  MusicMetadata *mdata = getRawSongAt(x);
611  if (!mdata)
612  {
613  m_songs.removeAll(id);
614  m_shuffledSongs.removeAll(id);
615  needUpdate = true;
616  }
617  }
618 
619  if (needUpdate)
620  {
621  changed();
622 
624 
625  // TODO check we actually need this
626  if (isActivePlaylist())
627  gPlayer->activePlaylistChanged(-1, false);
628  }
629 }
630 
631 void Playlist::fillSongsFromSonglist(const QString& songList)
632 {
633  bool badTrack = false;
634 
635 #if QT_VERSION < QT_VERSION_CHECK(5,14,0)
636  QStringList list = songList.split(",", QString::SkipEmptyParts);
637 #else
638  QStringList list = songList.split(",", Qt::SkipEmptyParts);
639 #endif
640  for (const auto & song : qAsConst(list))
641  {
642  MusicMetadata::IdType id = song.toUInt();
643  int repo = ID_TO_REPO(id);
644  if (repo == RT_Radio)
645  {
646  // check this is a valid stream ID
648  m_songs.push_back(id);
649  else
650  {
651  badTrack = true;
652  LOG(VB_GENERAL, LOG_ERR, LOC + QString("Got a bad track %1").arg(id));
653  }
654  }
655  else
656  {
657  // check this is a valid track ID
658  if (gMusicData->m_all_music->isValidID(id))
659  m_songs.push_back(id);
660  else
661  {
662  badTrack = true;
663  LOG(VB_GENERAL, LOG_ERR, LOC + QString("Got a bad track %1").arg(id));
664  }
665  }
666  }
667 
668  if (this == gPlayer->getCurrentPlaylist())
670  else
672 
673  if (badTrack)
674  changed();
675 
676  if (isActivePlaylist())
677  gPlayer->activePlaylistChanged(-1, false);
678 }
679 
680 void Playlist::fillSonglistFromQuery(const QString& whereClause,
681  bool removeDuplicates,
682  InsertPLOption insertOption,
683  int currentTrackID)
684 {
685  QString orig_songlist = toRawSonglist();
686  QString new_songlist;
687 
688  disableSaves();
689  removeAllTracks();
690 
692 
693  QString theQuery;
694 
695  theQuery = "SELECT song_id FROM music_songs "
696  "LEFT JOIN music_directories ON"
697  " music_songs.directory_id=music_directories.directory_id "
698  "LEFT JOIN music_artists ON"
699  " music_songs.artist_id=music_artists.artist_id "
700  "LEFT JOIN music_albums ON"
701  " music_songs.album_id=music_albums.album_id "
702  "LEFT JOIN music_genres ON"
703  " music_songs.genre_id=music_genres.genre_id "
704  "LEFT JOIN music_artists AS music_comp_artists ON "
705  "music_albums.artist_id=music_comp_artists.artist_id ";
706  if (whereClause.length() > 0)
707  theQuery += whereClause;
708 
709  if (!query.exec(theQuery))
710  {
711  MythDB::DBError("Load songlist from query", query);
712  new_songlist.clear();
713  fillSongsFromSonglist(new_songlist);
714  enableSaves();
715  changed();
716  return;
717  }
718 
719  while (query.next())
720  {
721  new_songlist += "," + query.value(0).toString();
722  }
723  new_songlist.remove(0, 1);
724 
725  if (removeDuplicates && insertOption != PL_REPLACE)
726  new_songlist = removeDuplicateTracks(orig_songlist, new_songlist);
727 
728  switch (insertOption)
729  {
730  case PL_REPLACE:
731  break;
732 
734  new_songlist = new_songlist + "," + orig_songlist;
735  break;
736 
737  case PL_INSERTATEND:
738  new_songlist = orig_songlist + "," + new_songlist;
739  break;
740 
742  {
743 #if QT_VERSION < QT_VERSION_CHECK(5,14,0)
744  QStringList list = orig_songlist.split(",", QString::SkipEmptyParts);
745 #else
746  QStringList list = orig_songlist.split(",", Qt::SkipEmptyParts);
747 #endif
748  bool bFound = false;
749  QString tempList;
750  for (const auto& song : qAsConst(list))
751  {
752  int an_int = song.toInt();
753  tempList += "," + song;
754  if (!bFound && an_int == currentTrackID)
755  {
756  bFound = true;
757  tempList += "," + new_songlist;
758  }
759  }
760 
761  if (!bFound)
762  tempList = orig_songlist + "," + new_songlist;
763 
764  new_songlist = tempList.remove(0, 1);
765 
766  break;
767  }
768 
769  default:
770  new_songlist = orig_songlist;
771  }
772 
773  fillSongsFromSonglist(new_songlist);
774 
775  enableSaves();
776  changed();
777 }
778 
779 // songList is a list of trackIDs to add
780 void Playlist::fillSonglistFromList(const QList<int> &songList,
781  bool removeDuplicates,
782  InsertPLOption insertOption,
783  int currentTrackID)
784 {
785  QString orig_songlist = toRawSonglist();
786  QString new_songlist;
787 
788  disableSaves();
789 
790  removeAllTracks();
791 
792  for (int x = 0; x < songList.count(); x++)
793  {
794  new_songlist += "," + QString::number(songList.at(x));
795  }
796  new_songlist.remove(0, 1);
797 
798  if (removeDuplicates && insertOption != PL_REPLACE)
799  new_songlist = removeDuplicateTracks(orig_songlist, new_songlist);
800 
801  switch (insertOption)
802  {
803  case PL_REPLACE:
804  break;
805 
807  new_songlist = new_songlist + "," + orig_songlist;
808  break;
809 
810  case PL_INSERTATEND:
811  new_songlist = orig_songlist + "," + new_songlist;
812  break;
813 
815  {
816 #if QT_VERSION < QT_VERSION_CHECK(5,14,0)
817  QStringList list = orig_songlist.split(",", QString::SkipEmptyParts);
818 #else
819  QStringList list = orig_songlist.split(",", Qt::SkipEmptyParts);
820 #endif
821  bool bFound = false;
822  QString tempList;
823  for (const auto & song : qAsConst(list))
824  {
825  int an_int = song.toInt();
826  tempList += "," + song;
827  if (!bFound && an_int == currentTrackID)
828  {
829  bFound = true;
830  tempList += "," + new_songlist;
831  }
832  }
833 
834  if (!bFound)
835  tempList = orig_songlist + "," + new_songlist;
836 
837  new_songlist = tempList.remove(0, 1);
838 
839  break;
840  }
841 
842  default:
843  new_songlist = orig_songlist;
844  }
845 
846  fillSongsFromSonglist(new_songlist);
847 
848  enableSaves();
849 
850  changed();
851 }
852 
853 QString Playlist::toRawSonglist(bool shuffled, bool tracksOnly)
854 {
855  QString rawList = "";
856 
857  if (shuffled)
858  {
859  for (int x = 0; x < m_shuffledSongs.count(); x++)
860  {
862  if (tracksOnly)
863  {
864  if (ID_TO_REPO(id) == RT_Database)
865  rawList += QString(",%1").arg(id);
866  }
867  else
868  rawList += QString(",%1").arg(id);
869  }
870  }
871  else
872  {
873  for (int x = 0; x < m_songs.count(); x++)
874  {
875  MusicMetadata::IdType id = m_songs.at(x);
876  if (tracksOnly)
877  {
878  if (ID_TO_REPO(id) == RT_Database)
879  rawList += QString(",%1").arg(id);
880  }
881  else
882  rawList += QString(",%1").arg(id);
883  }
884  }
885 
886  if (!rawList.isEmpty())
887  rawList = rawList.remove(0, 1);
888 
889  return rawList;
890 }
891 
892 void Playlist::fillSonglistFromSmartPlaylist(const QString& category, const QString& name,
893  bool removeDuplicates,
894  InsertPLOption insertOption,
895  int currentTrackID)
896 {
898 
899  // find the correct categoryid
901  if (categoryID == -1)
902  {
903  LOG(VB_GENERAL, LOG_WARNING, LOC +
904  QString("Cannot find Smartplaylist Category: %1") .arg(category));
905  return;
906  }
907 
908  // find smartplaylist
909  int ID = 0;
910  QString matchType;
911  QString orderBy;
912  int limitTo = 0;
913 
914  query.prepare("SELECT smartplaylistid, matchtype, orderby, limitto "
915  "FROM music_smartplaylists "
916  "WHERE categoryid = :CATEGORYID AND name = :NAME;");
917  query.bindValue(":NAME", name);
918  query.bindValue(":CATEGORYID", categoryID);
919 
920  if (query.exec())
921  {
922  if (query.isActive() && query.size() > 0)
923  {
924  query.first();
925  ID = query.value(0).toInt();
926  matchType = (query.value(1).toString() == "All") ? " AND " : " OR ";
927  orderBy = query.value(2).toString();
928  limitTo = query.value(3).toInt();
929  }
930  else
931  {
932  LOG(VB_GENERAL, LOG_WARNING, LOC +
933  QString("Cannot find smartplaylist: %1").arg(name));
934  return;
935  }
936  }
937  else
938  {
939  MythDB::DBError("Find SmartPlaylist", query);
940  return;
941  }
942 
943  // get smartplaylist items
944  QString whereClause = "WHERE ";
945 
946  query.prepare("SELECT field, operator, value1, value2 "
947  "FROM music_smartplaylist_items "
948  "WHERE smartplaylistid = :ID;");
949  query.bindValue(":ID", ID);
950  if (query.exec())
951  {
952  bool bFirst = true;
953  while (query.next())
954  {
955  QString fieldName = query.value(0).toString();
956  QString operatorName = query.value(1).toString();
957  QString value1 = query.value(2).toString();
958  QString value2 = query.value(3).toString();
959  if (!bFirst)
960  {
961  whereClause += matchType + getCriteriaSQL(fieldName,
962  operatorName, value1, value2);
963  }
964  else
965  {
966  bFirst = false;
967  whereClause += " " + getCriteriaSQL(fieldName, operatorName,
968  value1, value2);
969  }
970  }
971  }
972 
973  // add order by clause
974  whereClause += getOrderBySQL(orderBy);
975 
976  // add limit
977  if (limitTo > 0)
978  whereClause += " LIMIT " + QString::number(limitTo);
979 
980  fillSonglistFromQuery(whereClause, removeDuplicates,
981  insertOption, currentTrackID);
982 }
983 
985 {
986  m_changed = true;
987 
988  if (m_doSave)
990 }
991 
992 void Playlist::savePlaylist(const QString& a_name, const QString& a_host)
993 {
994  LOG(VB_GENERAL, LOG_DEBUG, LOC + "Saving playlist: " + a_name);
995 
996  m_name = a_name.simplified();
997  if (m_name.isEmpty())
998  {
999  LOG(VB_GENERAL, LOG_WARNING, LOC + "Not saving unnamed playlist");
1000  return;
1001  }
1002 
1003  if (a_host.isEmpty())
1004  {
1005  LOG(VB_GENERAL, LOG_WARNING, LOC +
1006  "Not saving playlist without a host name");
1007  return;
1008  }
1009 
1010  // get the shuffled list of tracks excluding any cd tracks and radio streams
1011  QString rawSonglist = toRawSonglist(true, true);
1012 
1014  uint songcount = 0;
1015  uint playtime = 0;
1016 
1017  getStats(&songcount, &playtime);
1018 
1019  bool save_host = ("default_playlist_storage" == a_name);
1020  if (m_playlistid > 0)
1021  {
1022  QString str_query = "UPDATE music_playlists SET "
1023  "playlist_songs = :LIST, "
1024  "playlist_name = :NAME, "
1025  "songcount = :SONGCOUNT, "
1026  "length = :PLAYTIME";
1027  if (save_host)
1028  str_query += ", hostname = :HOSTNAME";
1029  str_query += " WHERE playlist_id = :ID ;";
1030 
1031  query.prepare(str_query);
1032  query.bindValue(":ID", m_playlistid);
1033  }
1034  else
1035  {
1036  QString str_query = "INSERT INTO music_playlists"
1037  " (playlist_name, playlist_songs,"
1038  " songcount, length";
1039  if (save_host)
1040  str_query += ", hostname";
1041  str_query += ") VALUES(:NAME, :LIST, :SONGCOUNT, :PLAYTIME";
1042  if (save_host)
1043  str_query += ", :HOSTNAME";
1044  str_query += ");";
1045 
1046  query.prepare(str_query);
1047  }
1048  query.bindValue(":LIST", rawSonglist);
1049  query.bindValue(":NAME", a_name);
1050  query.bindValue(":SONGCOUNT", songcount);
1051  query.bindValue(":PLAYTIME", qlonglong(playtime));
1052  if (save_host)
1053  query.bindValue(":HOSTNAME", a_host);
1054 
1055  if (!query.exec() || (m_playlistid < 1 && query.numRowsAffected() < 1))
1056  {
1057  MythDB::DBError("Problem saving playlist", query);
1058  }
1059 
1060  if (m_playlistid < 1)
1061  m_playlistid = query.lastInsertId().toInt();
1062 
1063  m_changed = false;
1064 }
1065 
1066 QString Playlist::removeDuplicateTracks(const QString &orig_songlist, const QString &new_songlist)
1067 {
1068 #if QT_VERSION < QT_VERSION_CHECK(5,14,0)
1069  QStringList curList = orig_songlist.split(",", QString::SkipEmptyParts);
1070  QStringList newList = new_songlist.split(",", QString::SkipEmptyParts);
1071 #else
1072  QStringList curList = orig_songlist.split(",", Qt::SkipEmptyParts);
1073  QStringList newList = new_songlist.split(",", Qt::SkipEmptyParts);
1074 #endif
1075  QString songlist;
1076 
1077  for (const auto & song : qAsConst(newList))
1078  {
1079  if (curList.indexOf(song) == -1)
1080  songlist += "," + song;
1081  }
1082  songlist.remove(0, 1);
1083  return songlist;
1084 }
1085 
1087 {
1088  MusicMetadata *mdata = nullptr;
1089 
1090  if (pos >= 0 && pos < m_shuffledSongs.size())
1091  {
1093  int repo = ID_TO_REPO(id);
1094 
1095  if (repo == RT_Radio)
1096  mdata = gMusicData->m_all_streams->getMetadata(id);
1097  else
1098  mdata = gMusicData->m_all_music->getMetadata(id);
1099  }
1100 
1101  return mdata;
1102 }
1103 
1105 {
1106  MusicMetadata *mdata = nullptr;
1107 
1108  if (pos >= 0 && pos < m_songs.size())
1109  {
1110  MusicMetadata::IdType id = m_songs.at(pos);
1111  int repo = ID_TO_REPO(id);
1112 
1113  if (repo == RT_Radio)
1114  mdata = gMusicData->m_all_streams->getMetadata(id);
1115  else
1116  mdata = gMusicData->m_all_music->getMetadata(id);
1117  }
1118 
1119  return mdata;
1120 }
1121 
1122 // Here begins CD Writing things. ComputeSize, CreateCDMP3 & CreateCDAudio
1123 // FIXME none of this is currently used
1124 #ifdef CD_WRTITING_FIXED
1125 void Playlist::computeSize(double &size_in_MB, double &size_in_sec)
1126 {
1127  //double child_MB;
1128  //double child_sec;
1129 
1130  // Clear return values
1131  size_in_MB = 0.0;
1132  size_in_sec = 0.0;
1133 
1134  for (int x = 0; x < m_songs.size(); x++)
1135  {
1136  MusicMetadata *mdata = getRawSongAt(x);
1137  if (mdata)
1138  {
1139  if (mdata->isCDTrack())
1140  continue;
1141 
1142  // Normal track
1143  if (mdata->Length() > 0)
1144  size_in_sec += mdata->Length();
1145  else
1146  LOG(VB_GENERAL, LOG_ERR, "Computing track lengths. "
1147  "One track <=0");
1148 
1149  size_in_MB += mdata->FileSize() / 1000000;
1150  }
1151  }
1152 }
1153 
1154 void Playlist::cdrecordData(int fd)
1155 {
1156  if (!m_progress || !m_proc)
1157  return;
1158 
1159  QByteArray buf;
1160  if (fd == 1)
1161  {
1162  buf = m_proc->ReadAll();
1163 
1164  // I would just use the QTextStream::readLine(), but wodim uses \r
1165  // to update the same line, so I'm splitting it on \r or \n
1166  // Track 01: 6 of 147 MB written (fifo 100%) [buf 99%] 16.3x.
1167  QString data(buf);
1168 #if QT_VERSION < QT_VERSION_CHECK(5,14,0)
1169  QStringList list = data.split(QRegExp("[\\r\\n]"),
1170  QString::SkipEmptyParts);
1171 #else
1172  QStringList list = data.split(QRegExp("[\\r\\n]"),
1173  Qt::SkipEmptyParts);
1174 #endif
1175 
1176  for (int i = 0; i < list.size(); i++)
1177  {
1178  QString line = list.at(i);
1179 
1180  if (line.mid(15, 2) == "of")
1181  {
1182  int mbdone = line.mid(10, 5).trimmed().toInt();
1183  int mbtotal = line.mid(17, 5).trimmed().toInt();
1184 
1185  if (mbtotal > 0)
1186  {
1187  m_progress->setProgress((mbdone * 100) / mbtotal);
1188  }
1189  }
1190  }
1191  }
1192  else
1193  {
1194  buf = m_proc->ReadAllErr();
1195 
1196  QTextStream text(buf);
1197 
1198  while (!text.atEnd())
1199  {
1200  QString err = text.readLine();
1201  if (err.contains("Drive needs to reload the media") ||
1202  err.contains("Input/output error.") ||
1203  err.contains("No disk / Wrong disk!"))
1204  {
1205  LOG(VB_GENERAL, LOG_ERR, err);
1206  m_proc->Term();
1207  }
1208  }
1209  }
1210 }
1211 
1212 void Playlist::mkisofsData(int fd)
1213 {
1214  if (!m_progress || !m_proc)
1215  return;
1216 
1217  QByteArray buf;
1218  if (fd == 1)
1219  buf = m_proc->ReadAll();
1220  else
1221  {
1222  buf = m_proc->ReadAllErr();
1223 
1224  QTextStream text(buf);
1225 
1226  while (!text.atEnd())
1227  {
1228  QString line = text.readLine();
1229  if (line[6] == '%')
1230  {
1231  line = line.mid(0, 3);
1232  m_progress->setProgress(line.trimmed().toInt());
1233  }
1234  }
1235  }
1236 }
1237 
1238 void Playlist::processExit(uint retval)
1239 {
1240  m_procExitVal = retval;
1241 }
1242 
1243 void Playlist::processExit(void)
1244 {
1245  m_procExitVal = GENERIC_EXIT_OK;
1246 }
1247 
1248 // FIXME: this needs updating to work with storage groups
1249 int Playlist::CreateCDMP3(void)
1250 {
1251  // Check & get global settings
1252  if (!gCoreContext->GetNumSetting("CDWriterEnabled"))
1253  {
1254  LOG(VB_GENERAL, LOG_ERR, "CD Writer is not enabled.");
1255  return 1;
1256  }
1257 
1258  QString scsidev = MediaMonitor::defaultCDWriter();
1259  if (scsidev.isEmpty())
1260  {
1261  LOG(VB_GENERAL, LOG_ERR, "No CD Writer device defined.");
1262  return 1;
1263  }
1264 
1265  int disksize = gCoreContext->GetNumSetting("CDDiskSize", 2);
1266  QString writespeed = gCoreContext->GetSetting("CDWriteSpeed", "2");
1267  bool MP3_dir_flag = gCoreContext->GetNumSetting("CDCreateDir", 1);
1268 
1269  double size_in_MB = 0.0;
1270 
1271  QStringList reclist;
1272 
1273  for (int x = 0; x < m_shuffledSongs.count(); x++)
1274  {
1275  MusicMetadata *mdata = getRawSongAt(x);
1276 
1277  // Normal track
1278  if (mdata)
1279  {
1280  if (mdata->isCDTrack())
1281  continue;
1282 
1283  // check filename..
1284  QFileInfo testit(mdata->Filename());
1285  if (!testit.exists())
1286  continue;
1287  size_in_MB += testit.size() / 1000000.0;
1288  QString outline;
1289  if (MP3_dir_flag)
1290  {
1291  if (mdata->Artist().length() > 0)
1292  outline += mdata->Artist() + "/";
1293  if (mdata->Album().length() > 0)
1294  outline += mdata->Album() + "/";
1295  }
1296 
1297  outline += "=";
1298  outline += mdata->Filename();
1299 
1300  reclist += outline;
1301  }
1302  }
1303 
1304  int max_size;
1305  if (disksize == 0)
1306  max_size = 650;
1307  else
1308  max_size = 700;
1309 
1310  if (size_in_MB >= max_size)
1311  {
1312  LOG(VB_GENERAL, LOG_ERR, "MP3 CD creation aborted -- cd size too big.");
1313  return 1;
1314  }
1315 
1316  // probably should tie stdout of mkisofs to stdin of cdrecord sometime
1317  QString tmptemplate("/tmp/mythmusicXXXXXX");
1318 
1319  QString tmprecordlist = createTempFile(tmptemplate);
1320  if (tmprecordlist == tmptemplate)
1321  {
1322  LOG(VB_GENERAL, LOG_ERR, "Unable to open temporary file");
1323  return 1;
1324  }
1325 
1326  QString tmprecordisofs = createTempFile(tmptemplate);
1327  if (tmprecordisofs == tmptemplate)
1328  {
1329  LOG(VB_GENERAL, LOG_ERR, "Unable to open temporary file");
1330  return 1;
1331  }
1332 
1333  QFile reclistfile(tmprecordlist);
1334 
1335  if (!reclistfile.open(QIODevice::WriteOnly))
1336  {
1337  LOG(VB_GENERAL, LOG_ERR, "Unable to open temporary file");
1338  return 1;
1339  }
1340 
1341  QTextStream recstream(&reclistfile);
1342 
1343  QStringList::Iterator iter;
1344 
1345  for (iter = reclist.begin(); iter != reclist.end(); ++iter)
1346  {
1347  recstream << *iter << "\n";
1348  }
1349 
1350  reclistfile.close();
1351 
1352  m_progress = new MythProgressDialog(tr("Creating CD File System"),
1353  100);
1354  m_progress->setProgress(1);
1355 
1356  QStringList args;
1357  QString command;
1358 
1359  command = "mkisofs";
1360  args << "-graft-points";
1361  args << "-path-list";
1362  args << tmprecordlist;
1363  args << "-o";
1364  args << tmprecordisofs;
1365  args << "-J";
1366  args << "-R";
1367 
1368  uint flags = kMSRunShell | kMSStdErr |
1371 
1372  m_proc = new MythSystemLegacy(command, args, flags);
1373 
1374  connect(m_proc, &MythSystemLegacy::readDataReady, this, &Playlist::mkisofsData,
1375  Qt::DirectConnection);
1376  connect(m_proc, &MythSystemLegacy::inished, this, qOverload<>&Playlist::processExit,
1377  Qt::DirectConnection);
1378  connect(m_proc, &MythSystemLegacy::error, this, qOverload<uint>&Playlist::processExit),
1379  Qt::DirectConnection);
1380 
1381  m_procExitVal = GENERIC_EXIT_RUNNING;
1382  m_proc->Run();
1383 
1384  while( m_procExitVal == GENERIC_EXIT_RUNNING )
1385  usleep( 100000 );
1386 
1387  uint retval = m_procExitVal;
1388 
1389  m_progress->Close();
1390  m_progress->deleteLater();
1391  m_proc->disconnect();
1392  delete m_proc;
1393 
1394  if (retval)
1395  {
1396  LOG(VB_GENERAL, LOG_ERR, QString("Unable to run mkisofs: returns %1")
1397  .arg(retval));
1398  }
1399  else
1400  {
1401  m_progress = new MythProgressDialog(tr("Burning CD"), 100);
1402  m_progress->setProgress(2);
1403 
1404  command = "cdrecord";
1405  args = QStringList();
1406  args << "-v";
1407  //args << "-dummy";
1408  args << QString("dev=%1").arg(scsidev);
1409 
1410  if (writespeed.toInt() > 0)
1411  {
1412  args << "-speed=";
1413  args << writespeed;
1414  }
1415 
1416  args << "-data";
1417  args << tmprecordisofs;
1418 
1419  flags = kMSRunShell | kMSStdErr | kMSStdOut |
1422 
1423  m_proc = new MythSystemLegacy(command, args, flags);
1424  connect(m_proc, &MythSystemLegacy::readDataReady,
1425  this, &Playlist::cdrecordData, Qt::DirectConnection);
1426  connect(m_proc, &MythSystemLegacy::finished,
1427  this, qOverload<>&Playlist::processExit, Qt::DirectConnection);
1428  connect(m_proc, &MythSystemLegacy::error,
1429  this, qOverload<uint>&Playlist::processExit, Qt::DirectConnection);
1430  m_procExitVal = GENERIC_EXIT_RUNNING;
1431  m_proc->Run();
1432 
1433  while( m_procExitVal == GENERIC_EXIT_RUNNING )
1434  usleep( 100000 );
1435 
1436  retval = m_procExitVal;
1437 
1438  m_progress->Close();
1439  m_progress->deleteLater();
1440  m_proc->disconnect();
1441  delete m_proc;
1442 
1443  if (retval)
1444  {
1445  LOG(VB_GENERAL, LOG_ERR,
1446  QString("Unable to run cdrecord: returns %1") .arg(retval));
1447  }
1448  }
1449 
1450  QFile::remove(tmprecordlist);
1451  QFile::remove(tmprecordisofs);
1452 
1453  return retval;
1454 }
1455 
1456 int Playlist::CreateCDAudio(void)
1457 {
1458  return -1;
1459 }
1460 #endif
kMSStdErr
@ kMSStdErr
allow access to stderr
Definition: mythsystem.h:40
MSqlQuery::isActive
bool isActive(void) const
Definition: mythdbcon.h:204
MSqlQuery::next
bool next(void)
Wrap QSqlQuery::next() so we can display the query results.
Definition: mythdbcon.cpp:783
MusicPlayer::SHUFFLE_INTELLIGENT
@ SHUFFLE_INTELLIGENT
Definition: musicplayer.h:166
MSqlQuery
QSqlQuery wrapper that fetches a DB connection from the connection pool.
Definition: mythdbcon.h:125
build_compdb.args
args
Definition: build_compdb.py:11
playlistcontainer.h
PL_REPLACE
@ PL_REPLACE
Definition: playlist.h:24
MusicMetadata::Title
QString Title() const
Definition: musicmetadata.h:162
gPlayer
MusicPlayer * gPlayer
Definition: musicplayer.cpp:35
MSqlQuery::size
int size(void) const
Definition: mythdbcon.h:203
Playlist::getSongAt
MusicMetadata * getSongAt(int pos) const
Definition: playlist.cpp:1086
MusicMetadata::Filename
QString Filename(bool find=true)
Definition: musicmetadata.cpp:966
AllStream::isValidID
bool isValidID(MusicMetadata::IdType an_id)
Definition: musicmetadata.cpp:1732
SmartPlaylistEditor::lookupCategoryID
static int lookupCategoryID(const QString &category)
Definition: smartplaylist.cpp:1164
GENERIC_EXIT_OK
#define GENERIC_EXIT_OK
Exited with no error.
Definition: exitcodes.h:10
kMSDontBlockInputDevs
@ kMSDontBlockInputDevs
avoid blocking LIRC & Joystick Menu
Definition: mythsystem.h:34
mythdb.h
getOrderBySQL
QString getOrderBySQL(const QString &orderByFields)
Definition: smartplaylist.cpp:236
MythSystemLegacy
Definition: mythsystemlegacy.h:67
AllMusic::isValidID
bool isValidID(int an_id)
Definition: musicmetadata.cpp:1641
Playlist::enableSaves
void enableSaves(void)
Definition: playlist.h:103
Playlist::shuffleTracks
void shuffleTracks(MusicPlayer::ShuffleMode mode)
Definition: playlist.cpp:152
Playlist::loadPlaylistByID
void loadPlaylistByID(int id, const QString &a_host)
Definition: playlist.cpp:575
AllStream::getMetadata
MusicMetadata * getMetadata(MusicMetadata::IdType an_id)
Definition: musicmetadata.cpp:1743
Playlist
Definition: playlist.h:45
MSqlQuery::lastInsertId
QVariant lastInsertId()
Return the id of the last inserted row.
Definition: mythdbcon.cpp:888
Playlist::~Playlist
~Playlist() override
Definition: playlist.cpp:146
Playlist::removeAllCDTracks
void removeAllCDTracks(void)
Definition: playlist.cpp:92
MSqlQuery::value
QVariant value(int i) const
Definition: mythdbcon.h:198
arg
arg(title).arg(filename).arg(doDelete))
mythmediamonitor.h
MythSystemLegacy::finished
void finished(void)
Playlist::getRawSongAt
MusicMetadata * getRawSongAt(int pos) const
Definition: playlist.cpp:1104
MusicMetadata::ID
IdType ID() const
Definition: musicmetadata.h:217
MSqlQuery::exec
bool exec(void)
Wrap QSqlQuery::exec() so we can display SQL.
Definition: mythdbcon.cpp:603
SongList
QList< MusicMetadata::IdType > SongList
Definition: playlist.h:43
MusicMetadata::Track
int Track() const
Definition: musicmetadata.h:199
category
QString category
Definition: mythplugins/mytharchive/mytharchivehelper/main.cpp:1422
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:23
MusicMetadata
Definition: musicmetadata.h:80
MusicPlayer::getCurrentPlaylist
Playlist * getCurrentPlaylist(void)
Definition: musicplayer.cpp:1598
Playlist::fillSonglistFromSmartPlaylist
void fillSonglistFromSmartPlaylist(const QString &category, const QString &name, bool removeDuplicates=false, InsertPLOption insertOption=PL_REPLACE, int currentTrackID=0)
Definition: playlist.cpp:892
Playlist::Playlist
Playlist(void)
Definition: playlist.cpp:141
MusicMetadata::Artist
QString Artist() const
Definition: musicmetadata.h:126
RT_Database
@ RT_Database
Definition: musicmetadata.h:60
Playlist::toRawSonglist
QString toRawSonglist(bool shuffled=false, bool tracksOnly=false)
Definition: playlist.cpp:853
mythsystemlegacy.h
getCriteriaSQL
QString getCriteriaSQL(const QString &fieldName, const QString &operatorName, QString value1, QString value2)
Definition: smartplaylist.cpp:145
Playlist::m_shuffledSongs
SongList m_shuffledSongs
Definition: playlist.h:138
MusicPlayer::SHUFFLE_OFF
@ SHUFFLE_OFF
Definition: musicplayer.h:164
Playlist::fillSonglistFromQuery
void fillSonglistFromQuery(const QString &whereClause, bool removeDuplicates=false, InsertPLOption insertOption=PL_REPLACE, int currentTrackID=0)
Definition: playlist.cpp:680
PlaylistContainer::FillIntelliWeights
void FillIntelliWeights(int &rating, int &playcount, int &lastplay, int &random) const
Definition: playlistcontainer.cpp:60
Playlist::changed
void changed(void)
Definition: playlist.cpp:984
RT_Radio
@ RT_Radio
Definition: musicmetadata.h:62
Playlist::removeDuplicateTracks
static QString removeDuplicateTracks(const QString &orig_songlist, const QString &new_songlist)
Definition: playlist.cpp:1066
MSqlQuery::first
bool first(void)
Wrap QSqlQuery::first() so we can display the query results.
Definition: mythdbcon.cpp:793
Playlist::removeTrack
void removeTrack(MusicMetadata::IdType trackID)
Definition: playlist.cpp:114
MythSystemLegacy::error
void error(uint status)
MythSystemLegacy::readDataReady
void readDataReady(int fd)
MSqlQuery::InitCon
static MSqlQueryInfo InitCon(ConnectionReuse _reuse=kNormalConnection)
Only use this in combination with MSqlQuery constructor.
Definition: mythdbcon.cpp:535
compat.h
MythDB::DBError
static void DBError(const QString &where, const MSqlQuery &query)
Definition: mythdb.cpp:178
MusicData::m_all_streams
AllStream * m_all_streams
Definition: musicdata.h:56
MusicMetadata::getAlbumId
int getAlbumId()
Definition: musicmetadata.cpp:582
hardwareprofile.scan.rating
def rating(profile, smoonURL, gate)
Definition: scan.py:39
Playlist::resync
void resync(void)
make sure all tracks are still valid after a scan
Definition: playlist.cpp:603
createTempFile
QString createTempFile(QString name_template, bool dir)
Definition: mythmiscutil.cpp:369
MusicMetadata::isDBTrack
bool isDBTrack(void) const
Definition: musicmetadata.h:222
Playlist::addTrack
void addTrack(MusicMetadata::IdType trackID, bool update_display)
Given a tracks ID, add that track to this playlist.
Definition: playlist.cpp:60
InsertPLOption
InsertPLOption
Definition: playlist.h:22
Playlist::disableSaves
void disableSaves(void)
whether any changes should be saved to the DB
Definition: playlist.h:102
Playlist::m_name
QString m_name
Definition: playlist.h:135
PL_INSERTATBEGINNING
@ PL_INSERTATBEGINNING
Definition: playlist.h:25
MusicPlayer::getShuffleMode
ShuffleMode getShuffleMode(void)
Definition: musicplayer.h:184
MusicPlayer::SHUFFLE_ARTIST
@ SHUFFLE_ARTIST
Definition: musicplayer.h:168
Playlist::checkTrack
bool checkTrack(MusicMetadata::IdType trackID) const
Definition: playlist.cpp:35
MusicPlayer::playlistChanged
void playlistChanged(int playlistID)
Definition: musicplayer.cpp:1486
AllMusic::getMetadata
MusicMetadata * getMetadata(int an_id)
Definition: musicmetadata.cpp:1633
uint
unsigned int uint
Definition: compat.h:141
gCoreContext
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
Definition: mythcorecontext.cpp:60
smartplaylist.h
MythCoreContext::GetNumSetting
int GetNumSetting(const QString &key, int defaultval=0)
Definition: mythcorecontext.cpp:933
Playlist::loadPlaylist
void loadPlaylist(const QString &a_name, const QString &a_host)
Definition: playlist.cpp:519
musicdata.h
kMSRunShell
@ kMSRunShell
run process through shell
Definition: mythsystem.h:41
MusicPlayer::SHUFFLE_RANDOM
@ SHUFFLE_RANDOM
Definition: musicplayer.h:165
kMSRunBackground
@ kMSRunBackground
run child in the background
Definition: mythsystem.h:36
MusicMetadata::Album
QString Album() const
Definition: musicmetadata.h:150
gMusicData
MusicData * gMusicData
Definition: musicdata.cpp:20
Playlist::moveTrackUpDown
void moveTrackUpDown(bool flag, int where_its_at)
Definition: playlist.cpp:125
MusicMetadata::IdType
uint32_t IdType
Definition: musicmetadata.h:86
PL_INSERTATEND
@ PL_INSERTATEND
Definition: playlist.h:26
MusicMetadata::isCDTrack
bool isCDTrack(void) const
Definition: musicmetadata.h:221
Playlist::isActivePlaylist
bool isActivePlaylist(void)
Definition: playlist.h:109
MusicPlayer::activePlaylistChanged
void activePlaylistChanged(int trackID, bool deleted)
Definition: musicplayer.cpp:1423
mythmiscutil.h
Playlist::copyTracks
void copyTracks(Playlist *to_ptr, bool update_display)
Definition: playlist.cpp:40
Playlist::m_doSave
bool m_doSave
Definition: playlist.h:142
MusicMetadata::FileSize
uint64_t FileSize() const
Definition: musicmetadata.h:232
PL_INSERTAFTERCURRENT
@ PL_INSERTAFTERCURRENT
Definition: playlist.h:27
MusicPlayer::SHUFFLE_ALBUM
@ SHUFFLE_ALBUM
Definition: musicplayer.h:167
MSqlQuery::bindValue
void bindValue(const QString &placeholder, const QVariant &val)
Add a single binding.
Definition: mythdbcon.cpp:864
MusicMetadata::LastPlay
QDateTime LastPlay() const
Definition: musicmetadata.h:243
LOC
#define LOC
Definition: playlist.cpp:31
Playlist::m_parent
PlaylistContainer * m_parent
Definition: playlist.h:140
mythcontext.h
categoryID
int categoryID
Definition: mythplugins/mytharchive/mytharchivehelper/main.cpp:633
Playlist::getStats
void getStats(uint *trackCount, uint *totalLength, uint currentTrack=0, uint *playedLength=nullptr) const
Definition: playlist.cpp:492
MusicMetadata::PlayCount
int PlayCount() const
Definition: musicmetadata.h:247
Playlist::m_songs
SongList m_songs
Definition: playlist.h:137
MediaMonitor::defaultCDWriter
static QString defaultCDWriter()
CDWriterDeviceLocation, user-selected drive, or /dev/cdrom.
Definition: mythmediamonitor.cpp:927
Playlist::savePlaylist
void savePlaylist(const QString &a_name, const QString &a_host)
Definition: playlist.cpp:992
MSqlQuery::numRowsAffected
int numRowsAffected() const
Definition: mythdbcon.h:206
MusicData::m_all_music
AllMusic * m_all_music
Definition: musicdata.h:55
MythCoreContext::GetHostName
QString GetHostName(void)
Definition: mythcorecontext.cpp:859
MusicMetadata::Rating
int Rating() const
Definition: musicmetadata.h:238
Playlist::fillSongsFromSonglist
void fillSongsFromSonglist(const QString &songList)
Definition: playlist.cpp:631
Playlist::describeYourself
void describeYourself(void) const
Definition: playlist.cpp:472
Playlist::removeAllTracks
void removeAllTracks(void)
Definition: playlist.cpp:84
Playlist::m_changed
bool m_changed
Definition: playlist.h:141
GENERIC_EXIT_RUNNING
#define GENERIC_EXIT_RUNNING
Process is running.
Definition: exitcodes.h:25
playlist.h
Playlist::fillSonglistFromList
void fillSonglistFromList(const QList< int > &songList, bool removeDuplicates, InsertPLOption insertOption, int currentTrackID)
Definition: playlist.cpp:780
kMSDontDisableDrawing
@ kMSDontDisableDrawing
avoid disabling UI drawing
Definition: mythsystem.h:35
exitcodes.h
ID_TO_REPO
#define ID_TO_REPO(x)
Definition: musicmetadata.h:71
query
MSqlQuery query(MSqlQuery::InitCon())
kMSStdOut
@ kMSStdOut
allow access to stdout
Definition: mythsystem.h:39
MusicMetadata::Length
int Length() const
Definition: musicmetadata.h:205
Playlist::m_playlistid
int m_playlistid
Definition: playlist.h:134
MusicPlayer::ShuffleMode
ShuffleMode
Definition: musicplayer.h:163
MythCoreContext::GetSetting
QString GetSetting(const QString &key, const QString &defaultval="")
Definition: mythcorecontext.cpp:919
MSqlQuery::prepare
bool prepare(const QString &query)
QSqlQuery::prepare() is not thread safe in Qt <= 3.3.2.
Definition: mythdbcon.cpp:808
MusicMetadata::DiscNumber
int DiscNumber() const
Definition: musicmetadata.h:208
musicplayer.h