Skip to content
This repository
Browse code

[musicdb] cosmetic: separate tag scanning out into a separate function

  • Loading branch information...
commit 84506dfcdc979d38ce75fda6870637a3263d55e2 1 parent 8983723
night199uk authored April 09, 2013
111  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  
-  MAPSONGS 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,11 +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 481
 
493 482
       CMusicInfoTag& tag = *pItem->GetMusicInfoTag();
494  
-      if (!tag.Loaded() )
495  
-      { // read the tag from a file
  483
+      if (!tag.Loaded())
  484
+      {
  485
+        // read the tag from a file
496 486
         auto_ptr<IMusicInfoTagLoader> pLoader (CMusicInfoTagLoaderFactory::CreateLoader(pItem->GetPath()));
497 487
         if (NULL != pLoader.get())
498 488
           pLoader->Load(pItem->GetPath(), tag);
@@ -504,46 +494,67 @@ int CMusicInfoScanner::RetrieveMusicInfo(CFileItemList& items, const CStdString&
504 494
         m_handle->SetPercentage(m_currentItem/(float)m_itemCount*100);
505 495
 
506 496
       if (tag.Loaded())
507  
-      {
508  
-        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
+}
509 504
 
510  
-        // ensure our song has a valid filename or else it will assert in AddSong()
511  
-        if (song.strFileName.IsEmpty())
512  
-        {
513  
-          // copy filename from path in case UPnP or other tag loaders didn't specify one (FIXME?)
514  
-          song.strFileName = pItem->GetPath();
  505
+int CMusicInfoScanner::RetrieveMusicInfo(CFileItemList& items, const CStdString& strDirectory)
  506
+{
  507
+  MAPSONGS songsMap;
515 508
 
516  
-          // if we still don't have a valid filename, skip the song
517  
-          if (song.strFileName.IsEmpty())
518  
-          {
519  
-            // this shouldn't ideally happen!
520  
-            CLog::Log(LOGERROR, "Skipping song since it doesn't seem to have a filename");
521  
-            continue;
522  
-          }
523  
-        }
  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;
524 512
 
525  
-        song.iStartOffset = pItem->m_lStartOffset;
526  
-        song.iEndOffset = pItem->m_lEndOffset;
527  
-        song.strThumb = pItem->GetUserMusicThumb(true);
528  
-        
529  
-        // grab info from the song
530  
-        MAPSONGS::iterator it = songsMap.find(pItem->GetPath());
531  
-        if (it != songsMap.end())
532  
-        { // keep the db-only fields intact on rescan...
533  
-          song.iTimesPlayed = it->second.iTimesPlayed;
534  
-          song.lastPlayed = it->second.lastPlayed;
535  
-          song.iKaraokeNumber = it->second.iKaraokeNumber;
536  
-
537  
-          if (song.rating == '0') song.rating = it->second.rating;
538  
-          if (song.strThumb.empty())
539  
-            song.strThumb = it->second.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;
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
 

0 notes on commit 84506df

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