Skip to content

Commit

Permalink
Merge pull request #2906 from arnova/music_db_fixes
Browse files Browse the repository at this point in the history
Music info/db (regression) fixes
  • Loading branch information
arnova committed Jun 26, 2013
2 parents bc7b563 + 4026ea3 commit ec3589e
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 25 deletions.
2 changes: 1 addition & 1 deletion xbmc/music/Album.cpp
Expand Up @@ -50,7 +50,7 @@ CStdString CAlbum::GetArtistString() const

CStdString CAlbum::GetGenreString() const
{
return StringUtils::Join(artist, g_advancedSettings.m_musicItemSeparator);
return StringUtils::Join(genre, g_advancedSettings.m_musicItemSeparator);
}

bool CAlbum::operator<(const CAlbum &a) const
Expand Down
18 changes: 9 additions & 9 deletions xbmc/music/MusicDatabase.cpp
Expand Up @@ -440,13 +440,13 @@ int CMusicDatabase::AddSong(const int idAlbum,
return idSong;
}

int CMusicDatabase::UpdateSong(int idSong,
const CStdString& strTitle, const CStdString& strMusicBrainzTrackID,
const CStdString& strPathAndFileName, const CStdString& strComment, const CStdString& strThumb,
const std::vector<std::string>& artists, const std::vector<std::string>& genres,
int iTrack, int iDuration, int iYear,
int iTimesPlayed, int iStartOffset, int iEndOffset,
const CDateTime& dtLastPlayed, char rating, int iKaraokeNumber)
int CMusicDatabase::UpdateSong(int idSong,
const CStdString& strTitle, const CStdString& strMusicBrainzTrackID,
const CStdString& strPathAndFileName, const CStdString& strComment, const CStdString& strThumb,
const std::vector<std::string>& artists, const std::vector<std::string>& genres,
int iTrack, int iDuration, int iYear,
int iTimesPlayed, int iStartOffset, int iEndOffset,
const CDateTime& dtLastPlayed, char rating, int iKaraokeNumber)
{
CStdString sql;
if (idSong < 0)
Expand Down Expand Up @@ -3902,9 +3902,9 @@ bool CMusicDatabase::SaveAlbumThumb(int idAlbum, const CStdString& strThumb)
SetArtForItem(idAlbum, "album", "thumb", strThumb);
// TODO: We should prompt the user to update the art for songs
CStdString sql = PrepareSQL("UPDATE art"
" SET art_url='-'"
" SET url='-'"
" WHERE media_type='song'"
" AND art_type='thumb'"
" AND type='thumb'"
" AND media_id IN"
" (SELECT idSong FROM song WHERE idAlbum=%ld)", idAlbum);
ExecuteQuery(sql);
Expand Down
25 changes: 17 additions & 8 deletions xbmc/music/infoscanner/MusicInfoScanner.cpp
Expand Up @@ -618,7 +618,7 @@ int CMusicInfoScanner::RetrieveMusicInfo(const CStdString& strDirectory, CFileIt
// No - download the information
CMusicAlbumInfo albumInfo;
INFO_RET albumDownloadStatus = INFO_NOT_FOUND;
if (m_flags & SCAN_ONLINE)
if ((m_flags & SCAN_ONLINE) && albumScraper)
albumDownloadStatus = DownloadAlbumInfo(*album, albumScraper, albumInfo);

if (albumDownloadStatus == INFO_ADDED || albumDownloadStatus == INFO_HAVE_ALREADY)
Expand All @@ -640,14 +640,18 @@ int CMusicInfoScanner::RetrieveMusicInfo(const CStdString& strDirectory, CFileIt
}
else if (albumDownloadStatus == INFO_CANCELLED)
break;
else // Cache the lookup failure so we don't retry
else
{
// No download info, fallback to already gathered (eg. local) information/art (if any)
album->idAlbum = m_musicDatabase.AddAlbum(album->strAlbum,
album->strMusicBrainzAlbumID,
album->GetArtistString(),
album->GetGenreString(),
album->iYear,
album->bCompilation);
if (!album->art.empty())
m_musicDatabase.SetArtForItem(album->idAlbum,
"album", album->art);
m_albumCache.insert(make_pair(*album, *album));
}

Expand Down Expand Up @@ -676,7 +680,7 @@ int CMusicInfoScanner::RetrieveMusicInfo(const CStdString& strDirectory, CFileIt
// No - download the information
CMusicArtistInfo artistInfo;
INFO_RET artistDownloadStatus = INFO_NOT_FOUND;
if (m_flags & SCAN_ONLINE)
if ((m_flags & SCAN_ONLINE) && artistScraper)
artistDownloadStatus = DownloadArtistInfo(artistTmp, artistScraper, artistInfo);

if (artistDownloadStatus == INFO_ADDED || artistDownloadStatus == INFO_HAVE_ALREADY)
Expand Down Expand Up @@ -747,7 +751,7 @@ int CMusicInfoScanner::RetrieveMusicInfo(const CStdString& strDirectory, CFileIt
// No - download the information
CMusicArtistInfo artistInfo;
INFO_RET artistDownloadStatus = INFO_NOT_FOUND;
if (m_flags & SCAN_ONLINE)
if ((m_flags & SCAN_ONLINE) && artistScraper)
artistDownloadStatus = DownloadArtistInfo(artistTmp, artistScraper, artistInfo);

if (artistDownloadStatus == INFO_ADDED || artistDownloadStatus == INFO_HAVE_ALREADY)
Expand Down Expand Up @@ -1009,8 +1013,10 @@ void CMusicInfoScanner::FindArtForAlbums(VECALBUMS &albums, const CStdString &pa
}
}
if (albums.size() == 1 && !albumArt.empty())
{ // assign to folder thumb as well
CMusicThumbLoader::SetCachedImage(path, "thumb", albumArt);
{
// assign to folder thumb as well
CFileItem albumItem(path, true);
CMusicThumbLoader::SetCachedImage(albumItem, "thumb", albumArt);
}
}

Expand Down Expand Up @@ -1048,10 +1054,13 @@ INFO_RET CMusicInfoScanner::UpdateDatabaseAlbumInfo(const CStdString& strPath, C

// find album info
ADDON::ScraperPtr scraper;
if (!m_musicDatabase.GetScraperForPath(strPath, scraper, ADDON::ADDON_SCRAPER_ALBUMS) || !scraper)
return INFO_ERROR;
bool result = m_musicDatabase.GetScraperForPath(strPath, scraper, ADDON::ADDON_SCRAPER_ALBUMS);

m_musicDatabase.Close();

if (!result || !scraper)
return INFO_ERROR;

loop:
CLog::Log(LOGDEBUG, "%s downloading info for: %s", __FUNCTION__, album.strAlbum.c_str());
INFO_RET albumDownloadStatus = DownloadAlbumInfo(album, scraper, albumInfo, pDialog);
Expand Down
26 changes: 20 additions & 6 deletions xbmc/music/windows/GUIWindowMusicBase.cpp
Expand Up @@ -339,17 +339,21 @@ void CGUIWindowMusicBase::OnInfo(CFileItem *pItem, bool bShowInfo)
}
}

// check the first song we find in the folder, and grab it's album info
// check the first song we find in the folder, and grab its album info
for (int i = 0; i < items.Size(); i++)
{
CFileItemPtr pItem = items[i];
pItem->LoadMusicTag();
if (pItem->HasMusicInfoTag() && pItem->GetMusicInfoTag()->Loaded() &&
!pItem->GetMusicInfoTag()->GetAlbum().IsEmpty())
{
ShowAlbumInfo(pItem.get());
bool result = ShowAlbumInfo(pItem.get());

if (m_dlgProgress && bShowInfo)
m_dlgProgress->Close();

if (!result) // Something went wrong, so bail for the rest
break;
}
}

Expand Down Expand Up @@ -420,7 +424,7 @@ void CGUIWindowMusicBase::ShowArtistInfo(const CFileItem *pItem, bool bShowInfo
m_dlgProgress->Close();
}

void CGUIWindowMusicBase::ShowAlbumInfo(const CFileItem *pItem, bool bShowInfo /* = true */)
bool CGUIWindowMusicBase::ShowAlbumInfo(const CFileItem *pItem, bool bShowInfo /* = true */)
{
CQueryParams params;
CDirectoryNode::GetDatabaseInfo(pItem->GetPath(), params);
Expand All @@ -431,12 +435,19 @@ void CGUIWindowMusicBase::ShowAlbumInfo(const CFileItem *pItem, bool bShowInfo /
!m_musicdatabase.GetAlbumInfo(params.GetAlbumId(), albumInfo.GetAlbum(), &albumInfo.GetAlbum().songs))
{
if (!CProfilesManager::Get().GetCurrentProfile().canWriteDatabases() && !g_passwordManager.bMasterUser)
break; // should display a dialog saying no permissions
{
// TODO: should display a dialog saying no permissions
if (m_dlgProgress)
m_dlgProgress->Close();
return false;
}

if (g_application.IsMusicScanning())
{
CGUIDialogOK::ShowAndGetInput(189, 14057, 0, 0);
break;
if (m_dlgProgress)
m_dlgProgress->Close();
return false;
}

// show dialog box indicating we're searching the album
Expand All @@ -453,7 +464,9 @@ void CGUIWindowMusicBase::ShowAlbumInfo(const CFileItem *pItem, bool bShowInfo /
if (scanner.UpdateDatabaseAlbumInfo(pItem->GetPath(), albumInfo, bShowInfo) != INFO_ADDED || !albumInfo.Loaded())
{
CGUIDialogOK::ShowAndGetInput(185, 0, 500, 0);
break;
if (m_dlgProgress)
m_dlgProgress->Close();
return false;
}
}

Expand All @@ -479,6 +492,7 @@ void CGUIWindowMusicBase::ShowAlbumInfo(const CFileItem *pItem, bool bShowInfo /
}
if (m_dlgProgress)
m_dlgProgress->Close();
return true;
}

void CGUIWindowMusicBase::ShowSongInfo(CFileItem* pItem)
Expand Down
2 changes: 1 addition & 1 deletion xbmc/music/windows/GUIWindowMusicBase.h
Expand Up @@ -88,7 +88,7 @@ class CGUIWindowMusicBase : public CGUIMediaWindow
bool FindAlbumInfo(const CFileItem* album, MUSIC_GRABBER::CMusicAlbumInfo& albumInfo, ALLOW_SELECTION allowSelection);
bool FindArtistInfo(const CFileItem* artist, MUSIC_GRABBER::CMusicArtistInfo& artistInfo, ALLOW_SELECTION allowSelection);

void ShowAlbumInfo(const CFileItem *pItem, bool bShowInfo = true);
bool ShowAlbumInfo(const CFileItem *pItem, bool bShowInfo = true);
void ShowArtistInfo(const CFileItem *pItem, bool bShowInfo = true);
void ShowSongInfo(CFileItem* pItem);
void UpdateThumb(const CAlbum &album, const CStdString &path);
Expand Down

0 comments on commit ec3589e

Please sign in to comment.