Skip to content
This repository
Browse code

Merge pull request #2568 from night199uk/cosmetics

[musicdb] Cosmetics from the original MusicBrainz patch
  • Loading branch information...
commit 17411f251ab7695659e1bf560551f1acb5eaf94e 2 parents d1d4334 + 84506df
night199uk authored April 09, 2013
35  xbmc/music/MusicDatabase.cpp
@@ -166,7 +166,7 @@ bool CMusicDatabase::CreateTables()
166 166
     CLog::Log(LOGINFO, "create song index3");
167 167
     m_pDS->exec("CREATE INDEX idxSong3 ON song(idAlbum)");
168 168
     CLog::Log(LOGINFO, "create song index6");
169  
-    m_pDS->exec("CREATE INDEX idxSong6 ON song(idPath)");
  169
+    m_pDS->exec("CREATE UNIQUE INDEX idxSong6 ON song( idPath, strFileName(255) )");
170 170
 
171 171
     CLog::Log(LOGINFO, "create song_artist indexes");
172 172
     m_pDS->exec("CREATE UNIQUE INDEX idxSongArtist_1 ON song_artist ( idSong, idArtist )\n");
@@ -1310,16 +1310,7 @@ bool CMusicDatabase::GetArtistInfo(int idArtist, CArtist &info, bool needAll)
1310 1310
     if (idArtist == -1)
1311 1311
       return false; // not in the database
1312 1312
 
1313  
-    CStdString strSQL=PrepareSQL("SELECT artist.idArtist AS idArtist, strArtist, "
1314  
-                                 "  strBorn, strFormed, strGenres,"
1315  
-                                 "  strMoods, strStyles, strInstruments, "
1316  
-                                 "  strBiography, strDied, strDisbanded, "
1317  
-                                 "  strYearsActive, strImage, strFanart "
1318  
-                                 "  FROM artist "
1319  
-                                 "  JOIN artistinfo "
1320  
-                                 "    ON artist.idArtist = artistinfo.idArtist "
1321  
-                                 "  WHERE artistinfo.idArtist = %i"
1322  
-                                 , idArtist);
  1313
+    CStdString strSQL=PrepareSQL("SELECT * FROM artistview WHERE idArtist = %i", idArtist);
1323 1314
 
1324 1315
     if (!m_pDS2->query(strSQL.c_str())) return false;
1325 1316
     int iRowsFound = m_pDS2->num_rows();
@@ -1350,6 +1341,11 @@ bool CMusicDatabase::GetArtistInfo(int idArtist, CArtist &info, bool needAll)
1350 1341
   return false;
1351 1342
 }
1352 1343
 
  1344
+bool CMusicDatabase::HasArtistInfo(int idArtist)
  1345
+{
  1346
+  return strtol(GetSingleValue("artistinfo", "count(idArtist)", PrepareSQL("idArtist = %ld", idArtist)), NULL, 10) > 0;
  1347
+}
  1348
+
1353 1349
 bool CMusicDatabase::DeleteArtistInfo(int idArtist)
1354 1350
 {
1355 1351
   if (idArtist == -1)
@@ -1682,7 +1678,7 @@ void CMusicDatabase::IncrementPlayCount(const CFileItem& item)
1682 1678
   }
1683 1679
 }
1684 1680
 
1685  
-bool CMusicDatabase::GetSongsByPath(const CStdString& strPath1, CSongMap& songs, bool bAppendToMap)
  1681
+bool CMusicDatabase::GetSongsByPath(const CStdString& strPath1, MAPSONGS& songs, bool bAppendToMap)
1686 1682
 {
1687 1683
   CStdString strPath(strPath1);
1688 1684
   try
@@ -1691,7 +1687,7 @@ bool CMusicDatabase::GetSongsByPath(const CStdString& strPath1, CSongMap& songs,
1691 1687
       URIUtils::AddSlashAtEnd(strPath);
1692 1688
 
1693 1689
     if (!bAppendToMap)
1694  
-      songs.Clear();
  1690
+      songs.clear();
1695 1691
 
1696 1692
     if (NULL == m_pDB.get()) return false;
1697 1693
     if (NULL == m_pDS.get()) return false;
@@ -1707,7 +1703,7 @@ bool CMusicDatabase::GetSongsByPath(const CStdString& strPath1, CSongMap& songs,
1707 1703
     while (!m_pDS->eof())
1708 1704
     {
1709 1705
       CSong song = GetSongFromDataset();
1710  
-      songs.Add(song.strFileName, song);
  1706
+      songs.insert(make_pair(song.strFileName, song));
1711 1707
       m_pDS->next();
1712 1708
     }
1713 1709
 
@@ -3721,6 +3717,11 @@ bool CMusicDatabase::UpdateOldVersion(int version)
3721 3717
         m_pDS->exec(PrepareSQL("UPDATE song SET strFileName='%s' WHERE idSong=%d", filename.c_str(), i->first));
3722 3718
     }
3723 3719
   }
  3720
+  if (version < 33)
  3721
+  {
  3722
+    m_pDS->exec("DROP INDEX idxSong6 ON song");
  3723
+    m_pDS->exec("CREATE UNIQUE INDEX idxSong6 on song( idPath, strFileName(255) )");
  3724
+  }
3724 3725
   // always recreate the views after any table change
3725 3726
   CreateViews();
3726 3727
 
@@ -3729,7 +3730,7 @@ bool CMusicDatabase::UpdateOldVersion(int version)
3729 3730
 
3730 3731
 int CMusicDatabase::GetMinVersion() const
3731 3732
 {
3732  
-  return 32;
  3733
+  return 33;
3733 3734
 }
3734 3735
 
3735 3736
 unsigned int CMusicDatabase::GetSongIDs(const Filter &filter, vector<pair<int,int> > &songIDs)
@@ -4132,7 +4133,7 @@ bool CMusicDatabase::GetPathHash(const CStdString &path, CStdString &hash)
4132 4133
   return false;
4133 4134
 }
4134 4135
 
4135  
-bool CMusicDatabase::RemoveSongsFromPath(const CStdString &path1, CSongMap &songs, bool exact)
  4136
+bool CMusicDatabase::RemoveSongsFromPath(const CStdString &path1, MAPSONGS& songs, bool exact)
4136 4137
 {
4137 4138
   // We need to remove all songs from this path, as their tags are going
4138 4139
   // to be re-read.  We need to remove all songs from the song table + all links to them
@@ -4185,7 +4186,7 @@ bool CMusicDatabase::RemoveSongsFromPath(const CStdString &path1, CSongMap &song
4185 4186
       {
4186 4187
         CSong song = GetSongFromDataset();
4187 4188
         song.strThumb = GetArtForItem(song.idSong, "song", "thumb");
4188  
-        songs.Add(song.strFileName, song);
  4189
+        songs.insert(make_pair(song.strFileName, song));
4189 4190
         songIds += PrepareSQL("%i,", song.idSong);
4190 4191
         ids.push_back(song.idSong);
4191 4192
         m_pDS->next();
10  xbmc/music/MusicDatabase.h
@@ -117,12 +117,18 @@ class CMusicDatabase : public CDatabase
117 117
   bool GetAlbumInfo(int idAlbum, CAlbum &info, VECSONGS* songs, bool scrapedInfo = false);
118 118
   bool HasAlbumInfo(int idAlbum);
119 119
   bool GetArtistInfo(int idArtist, CArtist &info, bool needAll=true);
  120
+
  121
+  /*! \brief Check if an artist entity has additional metadata (scraped)
  122
+   \param idArtist the id of the Artist to check
  123
+   \return true or false - whether the artist has metadata
  124
+   */
  125
+  bool HasArtistInfo(int idArtist);
120 126
   bool GetSongByFileName(const CStdString& strFileName, CSong& song, int startOffset = 0);
121 127
   int GetAlbumIdByPath(const CStdString& path);
122 128
   bool GetSongById(int idSong, CSong& song);
123 129
   bool GetSongByKaraokeNumber( int number, CSong& song );
124 130
   bool SetKaraokeSongDelay( int idSong, int delay );
125  
-  bool GetSongsByPath(const CStdString& strPath, CSongMap& songs, bool bAppendToMap = false);
  131
+  bool GetSongsByPath(const CStdString& strPath, MAPSONGS& songs, bool bAppendToMap = false);
126 132
   bool Search(const CStdString& search, CFileItemList &items);
127 133
 
128 134
   bool GetAlbumFromSong(int idSong, CAlbum &album);
@@ -148,7 +154,7 @@ class CMusicDatabase : public CDatabase
148 154
    \param item CFileItem to increment the playcount for
149 155
    */
150 156
   void IncrementPlayCount(const CFileItem &item);
151  
-  bool RemoveSongsFromPath(const CStdString &path, CSongMap &songs, bool exact=true);
  157
+  bool RemoveSongsFromPath(const CStdString &path, MAPSONGS& songs, bool exact=true);
152 158
   bool CleanupOrphanedItems();
153 159
   bool GetPaths(std::set<CStdString> &paths);
154 160
   bool SetPathHash(const CStdString &path, const CStdString &hash);
13  xbmc/music/MusicInfoLoader.cpp
@@ -154,13 +154,12 @@ bool CMusicInfoLoader::LoadItem(CFileItem* pItem)
154 154
         m_databaseHits++;
155 155
       }
156 156
 
157  
-      CSong *song=NULL;
158  
-
159  
-      if ((song=m_songsMap.Find(pItem->GetPath()))!=NULL)
  157
+      MAPSONGS::iterator it = m_songsMap.find(pItem->GetPath());
  158
+      if (it != m_songsMap.end())
160 159
       {  // Have we loaded this item from database before
161  
-        pItem->GetMusicInfoTag()->SetSong(*song);
162  
-        if (!song->strThumb.empty())
163  
-          pItem->SetArt("thumb", song->strThumb);
  160
+        pItem->GetMusicInfoTag()->SetSong(it->second);
  161
+        if (!it->second.strThumb.empty())
  162
+          pItem->SetArt("thumb", it->second.strThumb);
164 163
       }
165 164
       else if (pItem->IsMusicDb())
166 165
       { // a music db item that doesn't have tag loaded - grab details from the database
@@ -198,7 +197,7 @@ bool CMusicInfoLoader::LoadItem(CFileItem* pItem)
198 197
 void CMusicInfoLoader::OnLoaderFinish()
199 198
 {
200 199
   // cleanup last loaded songs from database
201  
-  m_songsMap.Clear();
  200
+  m_songsMap.clear();
202 201
 
203 202
   // cleanup cache loaded from HD
204 203
   m_mapFileItems->Clear();
2  xbmc/music/MusicInfoLoader.h
@@ -44,7 +44,7 @@ class CMusicInfoLoader : public CBackgroundInfoLoader
44 44
 protected:
45 45
   CStdString m_strCacheFileName;
46 46
   CFileItemList* m_mapFileItems;
47  
-  CSongMap m_songsMap;
  47
+  MAPSONGS m_songsMap;
48 48
   CStdString m_strPrevPath;
49 49
   CMusicDatabase m_musicDatabase;
50 50
   unsigned int m_databaseHits;
42  xbmc/music/Song.cpp
@@ -130,45 +130,3 @@ bool CSong::ArtMatches(const CSong &right) const
130 130
   return (right.strThumb == strThumb &&
131 131
           embeddedArt.matches(right.embeddedArt));
132 132
 }
133  
-
134  
-CSongMap::CSongMap()
135  
-{
136  
-}
137  
-
138  
-std::map<CStdString, CSong>::const_iterator CSongMap::Begin()
139  
-{
140  
-  return m_map.begin();
141  
-}
142  
-
143  
-std::map<CStdString, CSong>::const_iterator CSongMap::End()
144  
-{
145  
-  return m_map.end();
146  
-}
147  
-
148  
-void CSongMap::Add(const CStdString &file, const CSong &song)
149  
-{
150  
-  CStdString lower = file;
151  
-  lower.ToLower();
152  
-  m_map.insert(pair<CStdString, CSong>(lower, song));
153  
-}
154  
-
155  
-CSong* CSongMap::Find(const CStdString &file)
156  
-{
157  
-  CStdString lower = file;
158  
-  lower.ToLower();
159  
-  map<CStdString, CSong>::iterator it = m_map.find(lower);
160  
-  if (it == m_map.end())
161  
-    return NULL;
162  
-  return &(*it).second;
163  
-}
164  
-
165  
-void CSongMap::Clear()
166  
-{
167  
-  m_map.erase(m_map.begin(), m_map.end());
168  
-}
169  
-
170  
-int CSongMap::Size()
171  
-{
172  
-  return (int)m_map.size();
173  
-}
174  
-
16  xbmc/music/Song.h
@@ -113,21 +113,7 @@ class CSong: public ISerializable
113 113
  \ingroup music
114 114
  \brief A map of CSong objects, used for CMusicDatabase
115 115
  */
116  
-class CSongMap
117  
-{
118  
-public:
119  
-  CSongMap();
120  
-
121  
-  std::map<CStdString, CSong>::const_iterator Begin();
122  
-  std::map<CStdString, CSong>::const_iterator End();
123  
-  CSong *Find(const CStdString &file);
124  
-  void Add(const CStdString &file, const CSong &song);
125  
-  void Clear();
126  
-  int Size();
127  
-
128  
-private:
129  
-  std::map<CStdString, CSong> m_map;
130  
-};
  116
+typedef std::map<std::string, CSong> MAPSONGS;
131 117
 
132 118
 /*!
133 119
  \ingroup music
182  xbmc/music/infoscanner/MusicInfoScanner.cpp
@@ -458,27 +458,17 @@ bool CMusicInfoScanner::DoScan(const CStdString& strDirectory)
458 458
   return !m_bStop;
459 459
 }
460 460
 
461  
-int CMusicInfoScanner::RetrieveMusicInfo(CFileItemList& items, const CStdString& strDirectory)
  461
+INFO_RET CMusicInfoScanner::ScanTags(const CFileItemList& items, CFileItemList& scannedItems)
462 462
 {
463  
-  CSongMap songsMap;
464  
-
465  
-  // get all information for all files in current directory from database, and remove them
466  
-  if (m_musicDatabase.RemoveSongsFromPath(strDirectory, songsMap))
467  
-    m_needsCleanup = true;
468  
-
469  
-  VECSONGS songsToAdd;
470  
-
471 463
   CStdStringArray regexps = g_advancedSettings.m_audioExcludeFromScanRegExps;
472 464
 
473 465
   // for every file found, but skip folder
474 466
   for (int i = 0; i < items.Size(); ++i)
475 467
   {
476 468
     CFileItemPtr pItem = items[i];
477  
-    CStdString strExtension;
478  
-    URIUtils::GetExtension(pItem->GetPath(), strExtension);
479 469
 
480 470
     if (m_bStop)
481  
-      return 0;
  471
+      return INFO_CANCELLED;
482 472
 
483 473
     // Discard all excluded files defined by m_musicExcludeRegExps
484 474
     if (CUtil::ExcludeFileOrFolder(pItem->GetPath(), regexps))
@@ -488,14 +478,11 @@ int CMusicInfoScanner::RetrieveMusicInfo(CFileItemList& items, const CStdString&
488 478
     if (!pItem->m_bIsFolder && !pItem->IsPlayList() && !pItem->IsPicture() && !pItem->IsLyrics() )
489 479
     {
490 480
       m_currentItem++;
491  
-//      CLog::Log(LOGDEBUG, "%s - Reading tag for: %s", __FUNCTION__, pItem->GetPath().c_str());
492  
-
493  
-      // grab info from the song
494  
-      CSong *dbSong = songsMap.Find(pItem->GetPath());
495 481
 
496 482
       CMusicInfoTag& tag = *pItem->GetMusicInfoTag();
497  
-      if (!tag.Loaded() )
498  
-      { // read the tag from a file
  483
+      if (!tag.Loaded())
  484
+      {
  485
+        // read the tag from a file
499 486
         auto_ptr<IMusicInfoTagLoader> pLoader (CMusicInfoTagLoaderFactory::CreateLoader(pItem->GetPath()));
500 487
         if (NULL != pLoader.get())
501 488
           pLoader->Load(pItem->GetPath(), tag);
@@ -507,43 +494,67 @@ int CMusicInfoScanner::RetrieveMusicInfo(CFileItemList& items, const CStdString&
507 494
         m_handle->SetPercentage(m_currentItem/(float)m_itemCount*100);
508 495
 
509 496
       if (tag.Loaded())
510  
-      {
511  
-        CSong song(tag);
  497
+        scannedItems.Add(pItem);
  498
+      else
  499
+        CLog::Log(LOGDEBUG, "%s - No tag found for: %s", __FUNCTION__, pItem->GetPath().c_str());
  500
+    }
  501
+  }
  502
+  return INFO_ADDED;
  503
+}
512 504
 
513  
-        // ensure our song has a valid filename or else it will assert in AddSong()
514  
-        if (song.strFileName.IsEmpty())
515  
-        {
516  
-          // copy filename from path in case UPnP or other tag loaders didn't specify one (FIXME?)
517  
-          song.strFileName = pItem->GetPath();
  505
+int CMusicInfoScanner::RetrieveMusicInfo(CFileItemList& items, const CStdString& strDirectory)
  506
+{
  507
+  MAPSONGS songsMap;
518 508
 
519  
-          // if we still don't have a valid filename, skip the song
520  
-          if (song.strFileName.IsEmpty())
521  
-          {
522  
-            // this shouldn't ideally happen!
523  
-            CLog::Log(LOGERROR, "Skipping song since it doesn't seem to have a filename");
524  
-            continue;
525  
-          }
526  
-        }
  509
+  // get all information for all files in current directory from database, and remove them
  510
+  if (m_musicDatabase.RemoveSongsFromPath(strDirectory, songsMap))
  511
+    m_needsCleanup = true;
527 512
 
528  
-        song.iStartOffset = pItem->m_lStartOffset;
529  
-        song.iEndOffset = pItem->m_lEndOffset;
530  
-        song.strThumb = pItem->GetUserMusicThumb(true);
531  
-        if (dbSong)
532  
-        { // keep the db-only fields intact on rescan...
533  
-          song.iTimesPlayed = dbSong->iTimesPlayed;
534  
-          song.lastPlayed = dbSong->lastPlayed;
535  
-          song.iKaraokeNumber = dbSong->iKaraokeNumber;
536  
-
537  
-          if (song.rating == '0') song.rating = dbSong->rating;
538  
-          if (song.strThumb.empty())
539  
-            song.strThumb = dbSong->strThumb;
540  
-        }
541  
-        songsToAdd.push_back(song);
542  
-//        CLog::Log(LOGDEBUG, "%s - Tag loaded for: %s", __FUNCTION__, pItem->GetPath().c_str());
  513
+  CFileItemList scannedItems;
  514
+  if (ScanTags(items, scannedItems) == INFO_CANCELLED)
  515
+    return 0;
  516
+
  517
+  VECSONGS songsToAdd;
  518
+  for (int i = 0; i < scannedItems.Size(); ++i)
  519
+  {
  520
+    CFileItemPtr pItem = scannedItems[i];
  521
+    CMusicInfoTag& tag = *pItem->GetMusicInfoTag();
  522
+    CSong song(tag);
  523
+
  524
+    // ensure our song has a valid filename or else it will assert in AddSong()
  525
+    if (song.strFileName.IsEmpty())
  526
+    {
  527
+      // copy filename from path in case UPnP or other tag loaders didn't specify one (FIXME?)
  528
+      song.strFileName = pItem->GetPath();
  529
+
  530
+      // if we still don't have a valid filename, skip the song
  531
+      if (song.strFileName.IsEmpty())
  532
+      {
  533
+        // this shouldn't ideally happen!
  534
+        CLog::Log(LOGERROR, "Skipping song since it doesn't seem to have a filename");
  535
+        continue;
543 536
       }
544  
-      else
545  
-        CLog::Log(LOGDEBUG, "%s - No tag found for: %s", __FUNCTION__, pItem->GetPath().c_str());
546 537
     }
  538
+
  539
+    song.iStartOffset = pItem->m_lStartOffset;
  540
+    song.iEndOffset = pItem->m_lEndOffset;
  541
+    song.strThumb = pItem->GetUserMusicThumb(true);
  542
+
  543
+    // grab info from the song
  544
+    MAPSONGS::iterator it = songsMap.find(pItem->GetPath());
  545
+    if (it != songsMap.end())
  546
+    {
  547
+      // keep the db-only fields intact on rescan...
  548
+      song.iTimesPlayed = it->second.iTimesPlayed;
  549
+      song.lastPlayed = it->second.lastPlayed;
  550
+      song.iKaraokeNumber = it->second.iKaraokeNumber;
  551
+
  552
+      if (song.rating == '0')
  553
+        song.rating = it->second.rating;
  554
+      if (song.strThumb.empty())
  555
+        song.strThumb = it->second.strThumb;
  556
+    }
  557
+    songsToAdd.push_back(song);
547 558
   }
548 559
 
549 560
   VECALBUMS albums;
@@ -996,14 +1007,13 @@ bool CMusicInfoScanner::DownloadAlbumInfo(const CStdString& strPath, const CStdS
996 1007
     }
997 1008
   }
998 1009
 
999  
-  CGUIDialogSelect *pDlg=NULL;
  1010
+  CGUIDialogSelect *pDlg = NULL;
1000 1011
   int iSelectedAlbum=0;
1001 1012
   if (result == CNfoFile::NO_NFO)
1002 1013
   {
1003 1014
     iSelectedAlbum = -1; // set negative so that we can detect a failure
1004 1015
     if (scraper.Succeeded() && scraper.GetAlbumCount() >= 1)
1005 1016
     {
1006  
-      int bestMatch = -1;
1007 1017
       double bestRelevance = 0;
1008 1018
       double minRelevance = THRESHOLD;
1009 1019
       if (scraper.GetAlbumCount() > 1) // score the matches
@@ -1029,7 +1039,7 @@ bool CMusicInfoScanner::DownloadAlbumInfo(const CStdString& strPath, const CStdS
1029 1039
           if (relevance >= max(minRelevance, bestRelevance))
1030 1040
           { // we auto-select the best of these
1031 1041
             bestRelevance = relevance;
1032  
-            bestMatch = i;
  1042
+            iSelectedAlbum = i;
1033 1043
           }
1034 1044
           if (pDialog)
1035 1045
           {
@@ -1043,6 +1053,35 @@ bool CMusicInfoScanner::DownloadAlbumInfo(const CStdString& strPath, const CStdS
1043 1053
           if (relevance > .99f) // we're so close, no reason to search further
1044 1054
             break;
1045 1055
         }
  1056
+
  1057
+        if (pDialog && bestRelevance < THRESHOLD)
  1058
+        {
  1059
+          pDlg->Sort(false);
  1060
+          pDlg->DoModal();
  1061
+
  1062
+          // and wait till user selects one
  1063
+          if (pDlg->GetSelectedLabel() < 0)
  1064
+          { // none chosen
  1065
+            if (!pDlg->IsButtonPressed())
  1066
+              return false;
  1067
+
  1068
+            // manual button pressed
  1069
+            CStdString strNewAlbum = album.strAlbum;
  1070
+            if (!CGUIKeyboardFactory::ShowAndGetInput(strNewAlbum, g_localizeStrings.Get(16011), false)) return false;
  1071
+            if (strNewAlbum == "") return false;
  1072
+
  1073
+            CStdString strNewArtist = StringUtils::Join(album.artist, g_advancedSettings.m_musicItemSeparator);
  1074
+            if (!CGUIKeyboardFactory::ShowAndGetInput(strNewArtist, g_localizeStrings.Get(16025), false)) return false;
  1075
+
  1076
+            pDialog->SetLine(0, strNewAlbum);
  1077
+            pDialog->SetLine(1, strNewArtist);
  1078
+            pDialog->Progress();
  1079
+
  1080
+            m_musicDatabase.Close();
  1081
+            return DownloadAlbumInfo(strPath,strNewArtist,strNewAlbum,bCanceled,albumInfo,pDialog);
  1082
+          }
  1083
+          iSelectedAlbum = pDlg->GetSelectedItem()->m_idepth;
  1084
+        }
1046 1085
       }
1047 1086
       else
1048 1087
       {
@@ -1055,40 +1094,7 @@ bool CMusicInfoScanner::DownloadAlbumInfo(const CStdString& strPath, const CStdS
1055 1094
           m_musicDatabase.Close();
1056 1095
           return false;
1057 1096
         }
1058  
-        bestRelevance = relevance;
1059  
-        bestMatch = 0;
1060  
-      }
1061  
-
1062  
-      iSelectedAlbum = bestMatch;
1063  
-      if (pDialog && bestRelevance < THRESHOLD)
1064  
-      {
1065  
-        pDlg->Sort(false);
1066  
-        pDlg->DoModal();
1067  
-
1068  
-        // and wait till user selects one
1069  
-        if (pDlg->GetSelectedLabel() < 0)
1070  
-        { // none chosen
1071  
-          if (!pDlg->IsButtonPressed())
1072  
-          {
1073  
-            bCanceled = true;
1074  
-            return false;
1075  
-          }
1076  
-          // manual button pressed
1077  
-          CStdString strNewAlbum = strAlbum;
1078  
-          if (!CGUIKeyboardFactory::ShowAndGetInput(strNewAlbum, g_localizeStrings.Get(16011), false)) return false;
1079  
-          if (strNewAlbum == "") return false;
1080  
-
1081  
-          CStdString strNewArtist = strArtist;
1082  
-          if (!CGUIKeyboardFactory::ShowAndGetInput(strNewArtist, g_localizeStrings.Get(16025), false)) return false;
1083  
-
1084  
-          pDialog->SetLine(0, strNewAlbum);
1085  
-          pDialog->SetLine(1, strNewArtist);
1086  
-          pDialog->Progress();
1087  
-
1088  
-          m_musicDatabase.Close();
1089  
-          return DownloadAlbumInfo(strPath,strNewArtist,strNewAlbum,bCanceled,albumInfo,pDialog);
1090  
-        }
1091  
-        iSelectedAlbum = pDlg->GetSelectedItem()->m_idepth;
  1097
+        iSelectedAlbum = 0;
1092 1098
       }
1093 1099
     }
1094 1100
 
@@ -1153,7 +1159,7 @@ bool CMusicInfoScanner::DownloadArtistInfo(const CStdString& strPath, const CStd
1153 1159
   bCanceled = false;
1154 1160
   CArtist artist;
1155 1161
   m_musicDatabase.Open();
1156  
-  if (m_musicDatabase.GetArtistInfo(params.GetArtistId(),artist)) // already got the info
  1162
+  if (m_musicDatabase.HasArtistInfo(params.GetArtistId()) && m_musicDatabase.GetArtistInfo(params.GetArtistId(),artist)) // already got the info
1157 1163
     return true;
1158 1164
 
1159 1165
   // find artist info
21  xbmc/music/infoscanner/MusicInfoScanner.h
@@ -28,6 +28,18 @@ class CGUIDialogProgressBarHandle;
28 28
 
29 29
 namespace MUSIC_INFO
30 30
 {
  31
+/*! \brief return values from the information lookup functions
  32
+ */
  33
+enum INFO_RET 
  34
+{ 
  35
+  INFO_CANCELLED,
  36
+  INFO_ERROR,
  37
+  INFO_NOT_NEEDED,
  38
+  INFO_HAVE_ALREADY,
  39
+  INFO_NOT_FOUND,
  40
+  INFO_ADDED 
  41
+};
  42
+
31 43
 class CMusicInfoScanner : CThread, public IRunnable
32 44
 {
33 45
 public:
@@ -97,6 +109,15 @@ class CMusicInfoScanner : CThread, public IRunnable
97 109
 protected:
98 110
   virtual void Process();
99 111
   int RetrieveMusicInfo(CFileItemList& items, const CStdString& strDirectory);
  112
+
  113
+  /*! \brief Scan in the ID3/Ogg/FLAC tags for a bunch of FileItems
  114
+    Given a list of FileItems, scan in the tags for those FileItems
  115
+   and populate a new FileItemList with the files that were successfully scanned.
  116
+   Any files which couldn't be scanned (no/bad tags) are discarded in the process.
  117
+   \param items [in] list of FileItems to scan
  118
+   \param scannedItems [in] list to populate with the scannedItems
  119
+   */
  120
+  INFO_RET ScanTags(const CFileItemList& items, CFileItemList& scannedItems);
100 121
   int GetPathHash(const CFileItemList &items, CStdString &hash);
101 122
   void GetAlbumArtwork(long id, const CAlbum &artist);
102 123
 
213  xbmc/music/windows/GUIWindowMusicBase.cpp
@@ -323,14 +323,11 @@ void CGUIWindowMusicBase::OnInfo(CFileItem *pItem, bool bShowInfo)
323 323
     CDirectoryNode::GetDatabaseInfo(pItem->GetPath(), params);
324 324
     if (params.GetAlbumId() == -1)
325 325
     { // artist lookup
326  
-      artist.idArtist = params.GetArtistId();
327  
-      artist.strArtist = StringUtils::Join(pItem->GetMusicInfoTag()->GetArtist(), g_advancedSettings.m_musicItemSeparator);
  326
+      m_musicdatabase.GetArtistInfo(params.GetArtistId(), artist);
328 327
     }
329 328
     else
330 329
     { // album lookup
331  
-      album.idAlbum = params.GetAlbumId();
332  
-      album.strAlbum = pItem->GetMusicInfoTag()->GetAlbum();
333  
-      album.artist = pItem->GetMusicInfoTag()->GetArtist();
  330
+      m_musicdatabase.GetAlbumInfo(params.GetAlbumId(), album, NULL);
334 331
 
335 332
       // we're going to need it's path as well (we assume that there's only one) - this is for
336 333
       // assigning thumbs to folders, and obtaining the local folder.jpg
@@ -392,9 +389,9 @@ void CGUIWindowMusicBase::OnInfo(CFileItem *pItem, bool bShowInfo)
392 389
   }
393 390
 
394 391
   if (album.idAlbum == -1 && foundAlbum == false)
395  
-    ShowArtistInfo(artist, pItem->GetPath(), false, bShowInfo);
  392
+    ShowArtistInfo(artist, pItem->GetPath(), bShowInfo);
396 393
   else
397  
-    ShowAlbumInfo(album, strPath, false, bShowInfo);
  394
+    ShowAlbumInfo(album, strPath, bShowInfo);
398 395
   m_musicdatabase.Close();
399 396
 }
400 397
 
@@ -412,183 +409,115 @@ void CGUIWindowMusicBase::OnManualAlbumInfo()
412 409
   ShowAlbumInfo(album,"",true);
413 410
 }
414 411
 
415  
-void CGUIWindowMusicBase::ShowArtistInfo(const CArtist& artist, const CStdString& path, bool bRefresh, bool bShowInfo)
  412
+void CGUIWindowMusicBase::ShowArtistInfo(const CArtist& artist, const CStdString& path, bool bShowInfo /* = true */)
416 413
 {
417 414
   bool saveDb = artist.idArtist != -1;
418 415
   if (!CProfilesManager::Get().GetCurrentProfile().canWriteDatabases() && !g_passwordManager.bMasterUser)
419 416
     saveDb = false;
420 417
 
421  
-  // check cache
422  
-  CArtist artistInfo;
423  
-  if (!bRefresh && m_musicdatabase.GetArtistInfo(artist.idArtist, artistInfo))
  418
+  CMusicArtistInfo artistInfo;
  419
+  while (1)
424 420
   {
425  
-    if (!bShowInfo)
426  
-      return;
427  
-
428  
-    CGUIDialogMusicInfo *pDlgArtistInfo = (CGUIDialogMusicInfo*)g_windowManager.GetWindow(WINDOW_DIALOG_MUSIC_INFO);
429  
-    if (pDlgArtistInfo)
  421
+    if (!m_musicdatabase.HasArtistInfo(artist.idArtist) ||
  422
+        !m_musicdatabase.GetArtistInfo(artist.idArtist, artistInfo.GetArtist()))
430 423
     {
431  
-      pDlgArtistInfo->SetArtist(artistInfo, path);
  424
+      if (g_application.IsMusicScanning())
  425
+      {
  426
+        CGUIDialogOK::ShowAndGetInput(189, 14057, 0, 0);
  427
+        break;
  428
+      }
432 429
 
433  
-      if (bShowInfo)
434  
-        pDlgArtistInfo->DoModal();
  430
+      if (!FindArtistInfo(artist.strArtist, artistInfo, bShowInfo ? SELECTION_ALLOWED : SELECTION_AUTO))
  431
+        break;
435 432
 
436  
-      if (!pDlgArtistInfo->NeedRefresh())
  433
+      if (!artistInfo.Loaded())
437 434
       {
438  
-        if (pDlgArtistInfo->HasUpdatedThumb())
439  
-          Refresh();
440  
-
441  
-        return;
  435
+        // Failed to download album info
  436
+        CGUIDialogOK::ShowAndGetInput(21889, 0, 20199, 0);
  437
+        break;
442 438
       }
443  
-      bRefresh = true;
444  
-      m_musicdatabase.DeleteArtistInfo(artistInfo.idArtist);
445  
-    }
446  
-  }
447 439
 
448  
-  // If we are scanning for music info in the background,
449  
-  // other writing access to the database is prohibited.
450  
-  if (g_application.IsMusicScanning())
451  
-  {
452  
-    CGUIDialogOK::ShowAndGetInput(189, 14057, 0, 0);
453  
-    return;
454  
-  }
  440
+      if (saveDb)
  441
+        m_musicdatabase.SetArtistInfo(artist.idArtist, artistInfo.GetArtist());
  442
+    }
455 443
 
456  
-  CMusicArtistInfo info;
457  
-  if (FindArtistInfo(artist.strArtist, info, bShowInfo ? (bRefresh ? SELECTION_FORCED : SELECTION_ALLOWED) : SELECTION_AUTO))
458  
-  {
459  
-    // download the album info
460  
-    if ( info.Loaded() )
  444
+    CGUIDialogMusicInfo *pDlgArtistInfo = (CGUIDialogMusicInfo*)g_windowManager.GetWindow(WINDOW_DIALOG_MUSIC_INFO);
  445
+    if (pDlgArtistInfo)
461 446
     {
462  
-      if (saveDb)
463  
-      {
464  
-        // save to database
465  
-        m_musicdatabase.SetArtistInfo(artist.idArtist, info.GetArtist());
466  
-      }
467  
-      if (m_dlgProgress && bShowInfo)
468  
-        m_dlgProgress->Close();
  447
+      pDlgArtistInfo->SetArtist(artistInfo.GetArtist(), path);
  448
+      pDlgArtistInfo->DoModal();
469 449
 
470  
-      // ok, show album info
471  
-      CGUIDialogMusicInfo *pDlgArtistInfo = (CGUIDialogMusicInfo*)g_windowManager.GetWindow(WINDOW_DIALOG_MUSIC_INFO);
472  
-      if (pDlgArtistInfo)
  450
+      if (pDlgArtistInfo->NeedRefresh())
473 451
       {
474  
-        pDlgArtistInfo->SetArtist(info.GetArtist(), path);
475  
-        if (bShowInfo)
476  
-          pDlgArtistInfo->DoModal();
477  
-
478  
-        CArtist artistInfo = info.GetArtist();
479  
-        artistInfo.idArtist = artist.idArtist;
480  
-/*
481  
-        if (pDlgAlbumInfo->HasUpdatedThumb())
482  
-          UpdateThumb(artistInfo, path);
483  
-*/
484  
-        // just update for now
485  
-        Refresh();
486  
-        if (pDlgArtistInfo->NeedRefresh())
487  
-        {
488  
-          m_musicdatabase.DeleteArtistInfo(artistInfo.idArtist);
489  
-          ShowArtistInfo(artist, path, true, bShowInfo);
490  
-          return;
491  
-        }
  452
+        m_musicdatabase.DeleteArtistInfo(artist.idArtist);
  453
+        continue;
  454
+      } 
  455
+      else if (pDlgArtistInfo->HasUpdatedThumb()) 
  456
+      {
  457
+        Update(m_vecItems->GetPath());
492 458
       }
493 459
     }
494  
-    else
495  
-    {
496  
-      // failed 2 download album info
497  
-      CGUIDialogOK::ShowAndGetInput(21889, 0, 20199, 0);
498  
-    }
  460
+    break;
499 461
   }
500  
-
501  
-  if (m_dlgProgress && bShowInfo)
  462
+  if (m_dlgProgress)
502 463
     m_dlgProgress->Close();
503 464
 }
504 465
 
505  
-void CGUIWindowMusicBase::ShowAlbumInfo(const CAlbum& album, const CStdString& path, bool bRefresh, bool bShowInfo)
  466
+void CGUIWindowMusicBase::ShowAlbumInfo(const CAlbum& album, const CStdString& path, bool bShowInfo /* = true */)
506 467
 {
507 468
   bool saveDb = album.idAlbum != -1;
508 469
   if (!CProfilesManager::Get().GetCurrentProfile().canWriteDatabases() && !g_passwordManager.bMasterUser)
509 470
     saveDb = false;
510 471
 
511  
-  // check cache
512  
-  CAlbum albumInfo;
513  
-  if (!bRefresh && m_musicdatabase.GetAlbumInfo(album.idAlbum, albumInfo, &albumInfo.songs))
  472
+  CMusicAlbumInfo albumInfo;
  473
+  while (1)
514 474
   {
515  
-    if (!bShowInfo)
516  
-      return;
517  
-
518  
-    CGUIDialogMusicInfo *pDlgAlbumInfo = (CGUIDialogMusicInfo*)g_windowManager.GetWindow(WINDOW_DIALOG_MUSIC_INFO);
519  
-    if (pDlgAlbumInfo)
  475
+    if (!m_musicdatabase.HasAlbumInfo(album.idAlbum) || 
  476
+        !m_musicdatabase.GetAlbumInfo(album.idAlbum, albumInfo.GetAlbum(), &albumInfo.GetAlbum().songs))
520 477
     {
521  
-      pDlgAlbumInfo->SetAlbum(albumInfo, path);
522  
-      if (bShowInfo)
523  
-        pDlgAlbumInfo->DoModal();
  478
+      if (g_application.IsMusicScanning())
  479
+      {
  480
+        CGUIDialogOK::ShowAndGetInput(189, 14057, 0, 0);
  481
+        break;
  482
+      }
524 483
 
525  
-      if (!pDlgAlbumInfo->NeedRefresh())
  484
+      if (!FindAlbumInfo(album.strAlbum, 
  485
+                         StringUtils::Join(album.artist, g_advancedSettings.m_musicItemSeparator),
  486
+                         albumInfo,
  487
+                         bShowInfo ? SELECTION_ALLOWED : SELECTION_AUTO))
  488
+        break;
  489
+      
  490
+      if (!albumInfo.Loaded())
526 491
       {
527  
-        if (pDlgAlbumInfo->HasUpdatedThumb())
528  
-          UpdateThumb(albumInfo, path);
529  
-        return;
  492
+        CGUIDialogOK::ShowAndGetInput(185, 0, 500, 0);
  493
+        break;
530 494
       }
531  
-      bRefresh = true;
532  
-      m_musicdatabase.DeleteAlbumInfo(albumInfo.idAlbum);
533  
-    }
534  
-  }
535 495
 
536  
-  // If we are scanning for music info in the background,
537  
-  // other writing access to the database is prohibited.
538  
-  if (g_application.IsMusicScanning())
539  
-  {
540  
-    CGUIDialogOK::ShowAndGetInput(189, 14057, 0, 0);
541  
-    return;
542  
-  }
  496
+      albumInfo.GetAlbum().strAlbum = album.strAlbum;
543 497
 
544  
-  CMusicAlbumInfo info;
545  
-  if (FindAlbumInfo(album.strAlbum, StringUtils::Join(album.artist, g_advancedSettings.m_musicItemSeparator), info, bShowInfo ? (bRefresh ? SELECTION_FORCED : SELECTION_ALLOWED) : SELECTION_AUTO))
546  
-  {
547  
-    // download the album info
548  
-    if ( info.Loaded() )
  498
+      if (saveDb)
  499
+        m_musicdatabase.SetAlbumInfo(album.idAlbum, albumInfo.GetAlbum(), albumInfo.GetSongs());
  500
+    }
  501
+
  502
+    CGUIDialogMusicInfo *pDlgAlbumInfo = (CGUIDialogMusicInfo*)g_windowManager.GetWindow(WINDOW_DIALOG_MUSIC_INFO);
  503
+    if (pDlgAlbumInfo)
549 504
     {
550  
-      // set album title from musicinfotag, not the one we got from allmusic.com
551  
-      info.SetTitle(album.strAlbum);
  505
+      pDlgAlbumInfo->SetAlbum(albumInfo.GetAlbum(), path);
  506
+      pDlgAlbumInfo->DoModal();
552 507
 
553  
-      if (saveDb)
  508
+      if (pDlgAlbumInfo->NeedRefresh())
554 509
       {
555  
-        // save to database
556  
-        m_musicdatabase.SetAlbumInfo(album.idAlbum, info.GetAlbum(), info.GetSongs());
  510
+        m_musicdatabase.DeleteAlbumInfo(album.idAlbum);
  511
+        continue;
557 512
       }
558  
-      if (m_dlgProgress && bShowInfo)
559  
-        m_dlgProgress->Close();
560  
-
561  
-      UpdateThumb(album, path);
562  
-
563  
-      // ok, show album info
564  
-      CGUIDialogMusicInfo *pDlgAlbumInfo = (CGUIDialogMusicInfo*)g_windowManager.GetWindow(WINDOW_DIALOG_MUSIC_INFO);
565  
-      if (pDlgAlbumInfo)
  513
+      else if (pDlgAlbumInfo->HasUpdatedThumb())
566 514
       {
567  
-        pDlgAlbumInfo->SetAlbum(info.GetAlbum(), path);
568  
-        if (bShowInfo)
569  
-          pDlgAlbumInfo->DoModal();
570  
-
571  
-        CAlbum albumInfo = info.GetAlbum();
572  
-        albumInfo.idAlbum = album.idAlbum;
573  
-        if (pDlgAlbumInfo->HasUpdatedThumb())
574  
-          UpdateThumb(albumInfo, path);
575  
-
576  
-        if (pDlgAlbumInfo->NeedRefresh())
577  
-        {
578  
-          m_musicdatabase.DeleteAlbumInfo(albumInfo.idAlbum);
579  
-          ShowAlbumInfo(album, path, true, bShowInfo);
580  
-          return;
581  
-        }
  515
+        UpdateThumb(album, path);
582 516
       }
583 517
     }
584  
-    else
585  
-    {
586  
-      // failed 2 download album info
587  
-      CGUIDialogOK::ShowAndGetInput(185, 0, 500, 0);
588  
-    }
  518
+    break;
589 519
   }
590  
-
591  
-  if (m_dlgProgress && bShowInfo)
  520
+  if (m_dlgProgress)
592 521
     m_dlgProgress->Close();
593 522
 }
594 523
 
4  xbmc/music/windows/GUIWindowMusicBase.h
@@ -88,8 +88,8 @@ class CGUIWindowMusicBase : public CGUIMediaWindow
88 88
   bool FindAlbumInfo(const CStdString& strAlbum, const CStdString& strArtist, MUSIC_GRABBER::CMusicAlbumInfo& album, ALLOW_SELECTION allowSelection);
89 89
   bool FindArtistInfo(const CStdString& strArtist, MUSIC_GRABBER::CMusicArtistInfo& artist, ALLOW_SELECTION allowSelection);
90 90
 
91  
-  void ShowAlbumInfo(const CAlbum &album, const CStdString &strPath, bool bRefresh, bool bShowInfo = true);
92  
-  void ShowArtistInfo(const CArtist &artist, const CStdString &strPath, bool bRefresh, bool bShowInfo = true);
  91
+  void ShowAlbumInfo(const CAlbum& album, const CStdString& path, bool bShowInfo = true);
  92
+  void ShowArtistInfo(const CArtist& artist, const CStdString& path, bool bShowInfo = true);
93 93
   void ShowSongInfo(CFileItem* pItem);
94 94
   void UpdateThumb(const CAlbum &album, const CStdString &path);
95 95
 
2  xbmc/music/windows/GUIWindowMusicSongs.cpp
@@ -483,7 +483,7 @@ void CGUIWindowMusicSongs::OnRemoveSource(int iItem)
483 483
   bool bCanceled;
484 484
   if (CGUIDialogYesNo::ShowAndGetInput(522,20340,20341,20022,bCanceled))
485 485
   {
486  
-    CSongMap songs;
  486
+    MAPSONGS songs;
487 487
     CMusicDatabase database;
488 488
     database.Open();
489 489
     database.RemoveSongsFromPath(m_vecItems->Get(iItem)->GetPath(),songs,false);

0 notes on commit 17411f2

Please sign in to comment.
Something went wrong with that request. Please try again.