Skip to content

Commit

Permalink
Merge pull request xbmc#2568 from night199uk/cosmetics
Browse files Browse the repository at this point in the history
[musicdb] Cosmetics from the original MusicBrainz patch
  • Loading branch information
night199uk committed Apr 9, 2013
2 parents d1d4334 + 84506df commit 17411f2
Show file tree
Hide file tree
Showing 11 changed files with 223 additions and 317 deletions.
35 changes: 18 additions & 17 deletions xbmc/music/MusicDatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ bool CMusicDatabase::CreateTables()
CLog::Log(LOGINFO, "create song index3");
m_pDS->exec("CREATE INDEX idxSong3 ON song(idAlbum)");
CLog::Log(LOGINFO, "create song index6");
m_pDS->exec("CREATE INDEX idxSong6 ON song(idPath)");
m_pDS->exec("CREATE UNIQUE INDEX idxSong6 ON song( idPath, strFileName(255) )");

CLog::Log(LOGINFO, "create song_artist indexes");
m_pDS->exec("CREATE UNIQUE INDEX idxSongArtist_1 ON song_artist ( idSong, idArtist )\n");
Expand Down Expand Up @@ -1310,16 +1310,7 @@ bool CMusicDatabase::GetArtistInfo(int idArtist, CArtist &info, bool needAll)
if (idArtist == -1)
return false; // not in the database

CStdString strSQL=PrepareSQL("SELECT artist.idArtist AS idArtist, strArtist, "
" strBorn, strFormed, strGenres,"
" strMoods, strStyles, strInstruments, "
" strBiography, strDied, strDisbanded, "
" strYearsActive, strImage, strFanart "
" FROM artist "
" JOIN artistinfo "
" ON artist.idArtist = artistinfo.idArtist "
" WHERE artistinfo.idArtist = %i"
, idArtist);
CStdString strSQL=PrepareSQL("SELECT * FROM artistview WHERE idArtist = %i", idArtist);

if (!m_pDS2->query(strSQL.c_str())) return false;
int iRowsFound = m_pDS2->num_rows();
Expand Down Expand Up @@ -1350,6 +1341,11 @@ bool CMusicDatabase::GetArtistInfo(int idArtist, CArtist &info, bool needAll)
return false;
}

bool CMusicDatabase::HasArtistInfo(int idArtist)
{
return strtol(GetSingleValue("artistinfo", "count(idArtist)", PrepareSQL("idArtist = %ld", idArtist)), NULL, 10) > 0;
}

bool CMusicDatabase::DeleteArtistInfo(int idArtist)
{
if (idArtist == -1)
Expand Down Expand Up @@ -1682,7 +1678,7 @@ void CMusicDatabase::IncrementPlayCount(const CFileItem& item)
}
}

bool CMusicDatabase::GetSongsByPath(const CStdString& strPath1, CSongMap& songs, bool bAppendToMap)
bool CMusicDatabase::GetSongsByPath(const CStdString& strPath1, MAPSONGS& songs, bool bAppendToMap)
{
CStdString strPath(strPath1);
try
Expand All @@ -1691,7 +1687,7 @@ bool CMusicDatabase::GetSongsByPath(const CStdString& strPath1, CSongMap& songs,
URIUtils::AddSlashAtEnd(strPath);

if (!bAppendToMap)
songs.Clear();
songs.clear();

if (NULL == m_pDB.get()) return false;
if (NULL == m_pDS.get()) return false;
Expand All @@ -1707,7 +1703,7 @@ bool CMusicDatabase::GetSongsByPath(const CStdString& strPath1, CSongMap& songs,
while (!m_pDS->eof())
{
CSong song = GetSongFromDataset();
songs.Add(song.strFileName, song);
songs.insert(make_pair(song.strFileName, song));
m_pDS->next();
}

Expand Down Expand Up @@ -3721,6 +3717,11 @@ bool CMusicDatabase::UpdateOldVersion(int version)
m_pDS->exec(PrepareSQL("UPDATE song SET strFileName='%s' WHERE idSong=%d", filename.c_str(), i->first));
}
}
if (version < 33)
{
m_pDS->exec("DROP INDEX idxSong6 ON song");
m_pDS->exec("CREATE UNIQUE INDEX idxSong6 on song( idPath, strFileName(255) )");
}
// always recreate the views after any table change
CreateViews();

Expand All @@ -3729,7 +3730,7 @@ bool CMusicDatabase::UpdateOldVersion(int version)

int CMusicDatabase::GetMinVersion() const
{
return 32;
return 33;
}

unsigned int CMusicDatabase::GetSongIDs(const Filter &filter, vector<pair<int,int> > &songIDs)
Expand Down Expand Up @@ -4132,7 +4133,7 @@ bool CMusicDatabase::GetPathHash(const CStdString &path, CStdString &hash)
return false;
}

bool CMusicDatabase::RemoveSongsFromPath(const CStdString &path1, CSongMap &songs, bool exact)
bool CMusicDatabase::RemoveSongsFromPath(const CStdString &path1, MAPSONGS& songs, bool exact)
{
// We need to remove all songs from this path, as their tags are going
// to be re-read. We need to remove all songs from the song table + all links to them
Expand Down Expand Up @@ -4185,7 +4186,7 @@ bool CMusicDatabase::RemoveSongsFromPath(const CStdString &path1, CSongMap &song
{
CSong song = GetSongFromDataset();
song.strThumb = GetArtForItem(song.idSong, "song", "thumb");
songs.Add(song.strFileName, song);
songs.insert(make_pair(song.strFileName, song));
songIds += PrepareSQL("%i,", song.idSong);
ids.push_back(song.idSong);
m_pDS->next();
Expand Down
10 changes: 8 additions & 2 deletions xbmc/music/MusicDatabase.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,18 @@ class CMusicDatabase : public CDatabase
bool GetAlbumInfo(int idAlbum, CAlbum &info, VECSONGS* songs, bool scrapedInfo = false);
bool HasAlbumInfo(int idAlbum);
bool GetArtistInfo(int idArtist, CArtist &info, bool needAll=true);

/*! \brief Check if an artist entity has additional metadata (scraped)
\param idArtist the id of the Artist to check
\return true or false - whether the artist has metadata
*/
bool HasArtistInfo(int idArtist);
bool GetSongByFileName(const CStdString& strFileName, CSong& song, int startOffset = 0);
int GetAlbumIdByPath(const CStdString& path);
bool GetSongById(int idSong, CSong& song);
bool GetSongByKaraokeNumber( int number, CSong& song );
bool SetKaraokeSongDelay( int idSong, int delay );
bool GetSongsByPath(const CStdString& strPath, CSongMap& songs, bool bAppendToMap = false);
bool GetSongsByPath(const CStdString& strPath, MAPSONGS& songs, bool bAppendToMap = false);
bool Search(const CStdString& search, CFileItemList &items);

bool GetAlbumFromSong(int idSong, CAlbum &album);
Expand All @@ -148,7 +154,7 @@ class CMusicDatabase : public CDatabase
\param item CFileItem to increment the playcount for
*/
void IncrementPlayCount(const CFileItem &item);
bool RemoveSongsFromPath(const CStdString &path, CSongMap &songs, bool exact=true);
bool RemoveSongsFromPath(const CStdString &path, MAPSONGS& songs, bool exact=true);
bool CleanupOrphanedItems();
bool GetPaths(std::set<CStdString> &paths);
bool SetPathHash(const CStdString &path, const CStdString &hash);
Expand Down
13 changes: 6 additions & 7 deletions xbmc/music/MusicInfoLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,12 @@ bool CMusicInfoLoader::LoadItem(CFileItem* pItem)
m_databaseHits++;
}

CSong *song=NULL;

if ((song=m_songsMap.Find(pItem->GetPath()))!=NULL)
MAPSONGS::iterator it = m_songsMap.find(pItem->GetPath());
if (it != m_songsMap.end())
{ // Have we loaded this item from database before
pItem->GetMusicInfoTag()->SetSong(*song);
if (!song->strThumb.empty())
pItem->SetArt("thumb", song->strThumb);
pItem->GetMusicInfoTag()->SetSong(it->second);
if (!it->second.strThumb.empty())
pItem->SetArt("thumb", it->second.strThumb);
}
else if (pItem->IsMusicDb())
{ // a music db item that doesn't have tag loaded - grab details from the database
Expand Down Expand Up @@ -198,7 +197,7 @@ bool CMusicInfoLoader::LoadItem(CFileItem* pItem)
void CMusicInfoLoader::OnLoaderFinish()
{
// cleanup last loaded songs from database
m_songsMap.Clear();
m_songsMap.clear();

// cleanup cache loaded from HD
m_mapFileItems->Clear();
Expand Down
2 changes: 1 addition & 1 deletion xbmc/music/MusicInfoLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class CMusicInfoLoader : public CBackgroundInfoLoader
protected:
CStdString m_strCacheFileName;
CFileItemList* m_mapFileItems;
CSongMap m_songsMap;
MAPSONGS m_songsMap;
CStdString m_strPrevPath;
CMusicDatabase m_musicDatabase;
unsigned int m_databaseHits;
Expand Down
42 changes: 0 additions & 42 deletions xbmc/music/Song.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,45 +130,3 @@ bool CSong::ArtMatches(const CSong &right) const
return (right.strThumb == strThumb &&
embeddedArt.matches(right.embeddedArt));
}

CSongMap::CSongMap()
{
}

std::map<CStdString, CSong>::const_iterator CSongMap::Begin()
{
return m_map.begin();
}

std::map<CStdString, CSong>::const_iterator CSongMap::End()
{
return m_map.end();
}

void CSongMap::Add(const CStdString &file, const CSong &song)
{
CStdString lower = file;
lower.ToLower();
m_map.insert(pair<CStdString, CSong>(lower, song));
}

CSong* CSongMap::Find(const CStdString &file)
{
CStdString lower = file;
lower.ToLower();
map<CStdString, CSong>::iterator it = m_map.find(lower);
if (it == m_map.end())
return NULL;
return &(*it).second;
}

void CSongMap::Clear()
{
m_map.erase(m_map.begin(), m_map.end());
}

int CSongMap::Size()
{
return (int)m_map.size();
}

16 changes: 1 addition & 15 deletions xbmc/music/Song.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,21 +113,7 @@ class CSong: public ISerializable
\ingroup music
\brief A map of CSong objects, used for CMusicDatabase
*/
class CSongMap
{
public:
CSongMap();

std::map<CStdString, CSong>::const_iterator Begin();
std::map<CStdString, CSong>::const_iterator End();
CSong *Find(const CStdString &file);
void Add(const CStdString &file, const CSong &song);
void Clear();
int Size();

private:
std::map<CStdString, CSong> m_map;
};
typedef std::map<std::string, CSong> MAPSONGS;

/*!
\ingroup music
Expand Down
Loading

0 comments on commit 17411f2

Please sign in to comment.