Permalink
Browse files

[musicscanner] Separate tag scanning into a separate function

  • Loading branch information...
1 parent add311a commit 7ede3d51f752cacad847dc12f7d8297d62d018c5 @night199uk committed Jul 3, 2012
Showing with 80 additions and 51 deletions.
  1. +67 −51 xbmc/music/infoscanner/MusicInfoScanner.cpp
  2. +13 −0 xbmc/music/infoscanner/MusicInfoScanner.h
View
118 xbmc/music/infoscanner/MusicInfoScanner.cpp
@@ -435,27 +435,17 @@ bool CMusicInfoScanner::DoScan(const CStdString& strDirectory)
return !m_bStop;
}
-int CMusicInfoScanner::RetrieveMusicInfo(CFileItemList& items, const CStdString& strDirectory)
+INFO_RET CMusicInfoScanner::ScanTags(const CFileItemList& items, CFileItemList& scannedItems)
{
- MAPSONGS songsMap;
-
- // get all information for all files in current directory from database, and remove them
- if (m_musicDatabase.RemoveSongsFromPath(strDirectory, songsMap))
- m_needsCleanup = true;
-
- VECSONGS songsToAdd;
-
CStdStringArray regexps = g_advancedSettings.m_audioExcludeFromScanRegExps;
// for every file found, but skip folder
for (int i = 0; i < items.Size(); ++i)
{
CFileItemPtr pItem = items[i];
- CStdString strExtension;
- URIUtils::GetExtension(pItem->GetPath(), strExtension);
if (m_bStop)
- return 0;
+ return INFO_CANCELLED;
// Discard all excluded files defined by m_musicExcludeRegExps
if (CUtil::ExcludeFileOrFolder(pItem->GetPath(), regexps))
@@ -465,16 +455,9 @@ int CMusicInfoScanner::RetrieveMusicInfo(CFileItemList& items, const CStdString&
if (!pItem->m_bIsFolder && !pItem->IsPlayList() && !pItem->IsPicture() && !pItem->IsLyrics() )
{
m_currentItem++;
-// CLog::Log(LOGDEBUG, "%s - Reading tag for: %s", __FUNCTION__, pItem->GetPath().c_str());
-
- // grab info from the song
- CSong *dbSong = NULL;
- MAPSONGS::iterator it = songsMap.find(pItem->GetPath());
- if (it != songsMap.end())
- dbSong = &it->second;
CMusicInfoTag& tag = *pItem->GetMusicInfoTag();
- if (!tag.Loaded() )
+ if (!tag.Loaded())
{ // read the tag from a file
auto_ptr<IMusicInfoTagLoader> pLoader (CMusicInfoTagLoaderFactory::CreateLoader(pItem->GetPath()));
if (NULL != pLoader.get())
@@ -487,43 +470,76 @@ int CMusicInfoScanner::RetrieveMusicInfo(CFileItemList& items, const CStdString&
m_pObserver->OnSetProgress(m_currentItem, m_itemCount);
if (tag.Loaded())
- {
- CSong song(tag);
+ scannedItems.Add(pItem);
+ else
+ CLog::Log(LOGDEBUG, "%s - No tag found for: %s", __FUNCTION__, pItem->GetPath().c_str());
+ }
+ }
+ return INFO_ADDED;
+}
- // ensure our song has a valid filename or else it will assert in AddSong()
- if (song.strFileName.IsEmpty())
- {
- // copy filename from path in case UPnP or other tag loaders didn't specify one (FIXME?)
- song.strFileName = pItem->GetPath();
+int CMusicInfoScanner::RetrieveMusicInfo(CFileItemList& items, const CStdString& strDirectory)
+{
+ MAPSONGS songsMap;
- // if we still don't have a valid filename, skip the song
- if (song.strFileName.IsEmpty())
- {
- // this shouldn't ideally happen!
- CLog::Log(LOGERROR, "Skipping song since it doesn't seem to have a filename");
- continue;
- }
- }
+ // get all information for all files in current directory from database, and remove them
+ if (m_musicDatabase.RemoveSongsFromPath(strDirectory, songsMap))
+ m_needsCleanup = true;
- song.iStartOffset = pItem->m_lStartOffset;
- song.iEndOffset = pItem->m_lEndOffset;
- song.strThumb = pItem->GetUserMusicThumb(true);
- if (dbSong)
- { // keep the db-only fields intact on rescan...
- song.iTimesPlayed = dbSong->iTimesPlayed;
- song.lastPlayed = dbSong->lastPlayed;
- song.iKaraokeNumber = dbSong->iKaraokeNumber;
-
- if (song.rating == '0') song.rating = dbSong->rating;
- if (song.strThumb.empty())
- song.strThumb = dbSong->strThumb;
+ VECSONGS songsToAdd;
+
+ CFileItemList scannedItems;
+ if (ScanTags(items, scannedItems) == INFO_CANCELLED)
+ return 0;
+
+ for (int i = 0; i < scannedItems.Size(); ++i)
+ {
+ CFileItemPtr pItem = scannedItems[i];
+ // grab info from the song
+ CSong *dbSong = NULL;
+ MAPSONGS::iterator it = songsMap.find(pItem->GetPath());
+ if (it != songsMap.end())
+ dbSong = &it->second;
+
+ CMusicInfoTag& tag = *pItem->GetMusicInfoTag();
+
+ if (tag.Loaded())
+ {
+ CSong song(tag);
+
+ // ensure our song has a valid filename or else it will assert in AddSong()
+ if (song.strFileName.IsEmpty())
+ {
+ // copy filename from path in case UPnP or other tag loaders didn't specify one (FIXME?)
+ song.strFileName = pItem->GetPath();
+
+ // if we still don't have a valid filename, skip the song
+ if (song.strFileName.IsEmpty())
+ {
+ // this shouldn't ideally happen!
+ CLog::Log(LOGERROR, "Skipping song since it doesn't seem to have a filename");
+ continue;
}
- songsToAdd.push_back(song);
-// CLog::Log(LOGDEBUG, "%s - Tag loaded for: %s", __FUNCTION__, pItem->GetPath().c_str());
}
- else
- CLog::Log(LOGDEBUG, "%s - No tag found for: %s", __FUNCTION__, pItem->GetPath().c_str());
+
+ song.iStartOffset = pItem->m_lStartOffset;
+ song.iEndOffset = pItem->m_lEndOffset;
+ song.strThumb = pItem->GetUserMusicThumb(true);
+ if (dbSong)
+ { // keep the db-only fields intact on rescan...
+ song.iTimesPlayed = dbSong->iTimesPlayed;
+ song.lastPlayed = dbSong->lastPlayed;
+ song.iKaraokeNumber = dbSong->iKaraokeNumber;
+
+ if (song.rating == '0') song.rating = dbSong->rating;
+ if (song.strThumb.empty())
+ song.strThumb = dbSong->strThumb;
+ }
+ songsToAdd.push_back(song);
+ // CLog::Log(LOGDEBUG, "%s - Tag loaded for: %s", __FUNCTION__, pItem->GetPath().c_str());
}
+ else
+ CLog::Log(LOGDEBUG, "%s - No tag found for: %s", __FUNCTION__, pItem->GetPath().c_str());
}
VECALBUMS albums;
View
13 xbmc/music/infoscanner/MusicInfoScanner.h
@@ -40,6 +40,18 @@ class IMusicInfoScannerObserver
virtual void OnFinished() = 0;
};
+/*! \brief return values from the information lookup functions
+ */
+enum INFO_RET
+{
+ INFO_CANCELLED,
+ INFO_ERROR,
+ INFO_NOT_NEEDED,
+ INFO_HAVE_ALREADY,
+ INFO_NOT_FOUND,
+ INFO_ADDED
+};
+
@jmarshallnz
jmarshallnz Oct 13, 2012

Move this inside the class perhaps?

class CMusicInfoScanner : CThread, public IRunnable
{
public:
@@ -107,6 +119,7 @@ class CMusicInfoScanner : CThread, public IRunnable
protected:
virtual void Process();
int RetrieveMusicInfo(CFileItemList& items, const CStdString& strDirectory);
+ INFO_RET ScanTags(const CFileItemList& items, CFileItemList& scannedItems);
int GetPathHash(const CFileItemList &items, CStdString &hash);
void GetAlbumArtwork(long id, const CAlbum &artist);

0 comments on commit 7ede3d5

Please sign in to comment.