Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

  • Loading branch information...
commit 84506dfcdc979d38ce75fda6870637a3263d55e2 1 parent 8983723
@night199uk night199uk authored
View
111 xbmc/music/infoscanner/MusicInfoScanner.cpp
@@ -458,27 +458,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))
@@ -488,11 +478,11 @@ 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());
CMusicInfoTag& tag = *pItem->GetMusicInfoTag();
- if (!tag.Loaded() )
- { // read the tag from a file
+ if (!tag.Loaded())
+ {
+ // read the tag from a file
auto_ptr<IMusicInfoTagLoader> pLoader (CMusicInfoTagLoaderFactory::CreateLoader(pItem->GetPath()));
if (NULL != pLoader.get())
pLoader->Load(pItem->GetPath(), tag);
@@ -504,46 +494,67 @@ int CMusicInfoScanner::RetrieveMusicInfo(CFileItemList& items, const CStdString&
m_handle->SetPercentage(m_currentItem/(float)m_itemCount*100);
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);
-
- // grab info from the song
- MAPSONGS::iterator it = songsMap.find(pItem->GetPath());
- if (it != songsMap.end())
- { // keep the db-only fields intact on rescan...
- song.iTimesPlayed = it->second.iTimesPlayed;
- song.lastPlayed = it->second.lastPlayed;
- song.iKaraokeNumber = it->second.iKaraokeNumber;
-
- if (song.rating == '0') song.rating = it->second.rating;
- if (song.strThumb.empty())
- song.strThumb = it->second.strThumb;
- }
- songsToAdd.push_back(song);
-// CLog::Log(LOGDEBUG, "%s - Tag loaded for: %s", __FUNCTION__, pItem->GetPath().c_str());
+ CFileItemList scannedItems;
+ if (ScanTags(items, scannedItems) == INFO_CANCELLED)
+ return 0;
+
+ VECSONGS songsToAdd;
+ for (int i = 0; i < scannedItems.Size(); ++i)
+ {
+ CFileItemPtr pItem = scannedItems[i];
+ CMusicInfoTag& tag = *pItem->GetMusicInfoTag();
+ 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;
}
- 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);
+
+ // grab info from the song
+ MAPSONGS::iterator it = songsMap.find(pItem->GetPath());
+ if (it != songsMap.end())
+ {
+ // keep the db-only fields intact on rescan...
+ song.iTimesPlayed = it->second.iTimesPlayed;
+ song.lastPlayed = it->second.lastPlayed;
+ song.iKaraokeNumber = it->second.iKaraokeNumber;
+
+ if (song.rating == '0')
+ song.rating = it->second.rating;
+ if (song.strThumb.empty())
+ song.strThumb = it->second.strThumb;
+ }
+ songsToAdd.push_back(song);
}
VECALBUMS albums;
View
21 xbmc/music/infoscanner/MusicInfoScanner.h
@@ -28,6 +28,18 @@ class CGUIDialogProgressBarHandle;
namespace MUSIC_INFO
{
+/*! \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
+};
+
class CMusicInfoScanner : CThread, public IRunnable
{
public:
@@ -97,6 +109,15 @@ class CMusicInfoScanner : CThread, public IRunnable
protected:
virtual void Process();
int RetrieveMusicInfo(CFileItemList& items, const CStdString& strDirectory);
+
+ /*! \brief Scan in the ID3/Ogg/FLAC tags for a bunch of FileItems
+ Given a list of FileItems, scan in the tags for those FileItems
+ and populate a new FileItemList with the files that were successfully scanned.
+ Any files which couldn't be scanned (no/bad tags) are discarded in the process.
+ \param items [in] list of FileItems to scan
+ \param scannedItems [in] list to populate with the scannedItems
+ */
+ INFO_RET ScanTags(const CFileItemList& items, CFileItemList& scannedItems);
int GetPathHash(const CFileItemList &items, CStdString &hash);
void GetAlbumArtwork(long id, const CAlbum &artist);
Please sign in to comment.
Something went wrong with that request. Please try again.