Permalink
Browse files

[musicdb] musicdb restructure for musicbrainz artist IDs - remove art…

…ist/album ID from CSong and place into artist/album
  • Loading branch information...
Jonathan Marshall authored and night199uk committed Jun 20, 2012
1 parent 5f38417 commit 5d87a9d748fa4d44fc3fa39089d98bdbb3a9b4fc
@@ -471,12 +471,6 @@ JSONRPC_STATUS CAudioLibrary::SetSongDetails(const CStdString &method, ITranspor
song.strComment = parameterObject["comment"].asString();
if (ParameterNotNull(parameterObject, "musicbrainztrackid"))
song.strMusicBrainzTrackID = parameterObject["musicbrainztrackid"].asString();
- if (ParameterNotNull(parameterObject, "musicbrainzartistid"))
- song.strMusicBrainzArtistID = parameterObject["musicbrainzartistid"].asString();
- if (ParameterNotNull(parameterObject, "musicbrainzalbumid"))
- song.strMusicBrainzAlbumID = parameterObject["musicbrainzalbumid"].asString();
- if (ParameterNotNull(parameterObject, "musicbrainzalbumartistid"))
- song.strMusicBrainzAlbumArtistID = parameterObject["musicbrainzalbumartistid"].asString();
if (musicdatabase.UpdateSong(song, id) <= 0)
return InternalError;
View
@@ -71,6 +71,7 @@ class CAlbum
long idAlbum;
CStdString strAlbum;
+ CStdString strMusicBrainzAlbumID;
std::vector<std::string> artist;
std::vector<std::string> genre;
CScraperUrl thumbURL;
View
@@ -66,6 +66,7 @@ class CArtist
bool Save(TiXmlNode *node, const CStdString &tag, const CStdString& strPath);
CStdString strArtist;
+ CStdString strMusicBrainzArtistID;
std::vector<std::string> genre;
CStdString strBiography;
std::vector<std::string> styles;
@@ -99,9 +99,9 @@ bool CMusicDatabase::CreateTables()
CDatabase::CreateTables();
CLog::Log(LOGINFO, "create artist table");
- m_pDS->exec("CREATE TABLE artist ( idArtist integer primary key, strArtist varchar(256))\n");
+ m_pDS->exec("CREATE TABLE artist ( idArtist integer primary key, strArtist varchar(256), strMusicBrainzArtistID text)\n");
CLog::Log(LOGINFO, "create album table");
- m_pDS->exec("CREATE TABLE album ( idAlbum integer primary key, strAlbum varchar(256), strArtists text, strGenres text, iYear integer, idThumb integer, bCompilation integer not null default '0' )\n");
+ m_pDS->exec("CREATE TABLE album ( idAlbum integer primary key, strAlbum varchar(256), strArtists text, strGenres text, iYear integer, idThumb integer, bCompilation integer not null default '0', strMusicBrainzAlbumID text )\n");
CLog::Log(LOGINFO, "create album_artist table");
m_pDS->exec("CREATE TABLE album_artist ( idArtist integer, idAlbum integer, boolFeatured integer, iOrder integer )\n");
CLog::Log(LOGINFO, "create album_genre table");
@@ -112,7 +112,7 @@ bool CMusicDatabase::CreateTables()
CLog::Log(LOGINFO, "create path table");
m_pDS->exec("CREATE TABLE path ( idPath integer primary key, strPath varchar(512), strHash text)\n");
CLog::Log(LOGINFO, "create song table");
- m_pDS->exec("CREATE TABLE song ( idSong integer primary key, idAlbum integer, idPath integer, strArtists text, strGenres text, strTitle varchar(512), iTrack integer, iDuration integer, iYear integer, dwFileNameCRC text, strFileName text, strMusicBrainzTrackID text, strMusicBrainzArtistID text, strMusicBrainzAlbumID text, strMusicBrainzAlbumArtistID text, strMusicBrainzTRMID text, iTimesPlayed integer, iStartOffset integer, iEndOffset integer, idThumb integer, lastplayed varchar(20) default NULL, rating char default '0', comment text)\n");
+ m_pDS->exec("CREATE TABLE song ( idSong integer primary key, idAlbum integer, idPath integer, strArtists text, strGenres text, strTitle varchar(512), iTrack integer, iDuration integer, iYear integer, dwFileNameCRC text, strFileName text, strMusicBrainzTrackID text, iTimesPlayed integer, iStartOffset integer, iEndOffset integer, idThumb integer, lastplayed varchar(20) default NULL, rating char default '0', comment text)\n");
CLog::Log(LOGINFO, "create song_artist table");
m_pDS->exec("CREATE TABLE song_artist ( idArtist integer, idSong integer, boolFeatured integer, iOrder integer )\n");
CLog::Log(LOGINFO, "create song_genre table");
@@ -151,6 +151,7 @@ bool CMusicDatabase::CreateTables()
m_pDS->exec("CREATE INDEX idxGenre ON genre(strGenre)");
CLog::Log(LOGINFO, "create artist index");
m_pDS->exec("CREATE INDEX idxArtist ON artist(strArtist)");
+ m_pDS->exec("CREATE UNIQUE INDEX idxArtist1 ON artist(strMusicBrainzArtistID(36))");
CLog::Log(LOGINFO, "create path index");
m_pDS->exec("CREATE INDEX idxPath ON path(strPath)");
@@ -224,8 +225,7 @@ void CMusicDatabase::CreateViews()
" song.strGenres AS strGenres,"
" strTitle, iTrack, iDuration,"
" song.iYear AS iYear, dwFileNameCRC, strFileName, strMusicBrainzTrackID,"
- " strMusicBrainzArtistID, strMusicBrainzAlbumID, strMusicBrainzAlbumArtistID,"
- " strMusicBrainzTRMID, iTimesPlayed, iStartOffset, iEndOffset, lastplayed,"
+ " iTimesPlayed, iStartOffset, iEndOffset, lastplayed,"
" rating, comment, song.idAlbum AS idAlbum, strAlbum, strPath,"
" iKaraNumber, iKaraDelay, strKaraEncoding,"
" album.bCompilation AS bCompilation "
@@ -241,6 +241,7 @@ void CMusicDatabase::CreateViews()
m_pDS->exec("DROP VIEW IF EXISTS albumview");
m_pDS->exec("CREATE VIEW albumview AS SELECT"
" album.idAlbum AS idAlbum, strAlbum, "
+ " album.strMusicBrainzAlbumID AS strMusicBrainzAlbumID, "
" album.strArtists AS strArtists,"
" album.strGenres AS strGenres, "
" album.iYear AS iYear,"
@@ -255,6 +256,7 @@ void CMusicDatabase::CreateViews()
m_pDS->exec("DROP VIEW IF EXISTS artistview");
m_pDS->exec("CREATE VIEW artistview AS SELECT"
" artist.idArtist AS idArtist, strArtist, "
+ " artist.strMusicBrainzArtistID AS strMusicBrainzArtistID, "
" strBorn, strFormed, strGenres,"
" strMoods, strStyles, strInstruments, "
" strBiography, strDied, strDisbanded, "
@@ -338,19 +340,15 @@ int CMusicDatabase::AddSong(const CSong& song, bool bCheck, int idAlbum)
// we use replace because it can handle both inserting a new song
// and replacing an existing song's record if the given idSong already exists
- strSQL=PrepareSQL("replace into song (idSong,idAlbum,idPath,strArtists,strGenres,strTitle,iTrack,iDuration,iYear,dwFileNameCRC,strFileName,strMusicBrainzTrackID,strMusicBrainzArtistID,strMusicBrainzAlbumID,strMusicBrainzAlbumArtistID,strMusicBrainzTRMID,iTimesPlayed,iStartOffset,iEndOffset,lastplayed,rating,comment) values (%s,%i,%i,'%s','%s','%s',%i,%i,%i,'%ul','%s','%s','%s','%s','%s','%s'",
+ strSQL=PrepareSQL("replace into song (idSong,idAlbum,idPath,strArtists,strGenres,strTitle,iTrack,iDuration,iYear,dwFileNameCRC,strFileName,strMusicBrainzTrackID,iTimesPlayed,iStartOffset,iEndOffset,idThumb,lastplayed,rating,comment) values (%s,%i,%i,'%s','%s','%s',%i,%i,%i,'%ul','%s','%s'",
strIdSong.c_str(),
idAlbum, idPath,
StringUtils::Join(song.artist, g_advancedSettings.m_musicItemSeparator).c_str(),
StringUtils::Join(song.genre, g_advancedSettings.m_musicItemSeparator).c_str(),
song.strTitle.c_str(),
song.iTrack, song.iDuration, song.iYear,
crc, strFileName.c_str(),
- song.strMusicBrainzTrackID.c_str(),
- song.strMusicBrainzArtistID.c_str(),
- song.strMusicBrainzAlbumID.c_str(),
- song.strMusicBrainzAlbumArtistID.c_str(),
- song.strMusicBrainzTRMID.c_str());
+ song.strMusicBrainzTrackID.c_str());
if (song.lastPlayed.IsValid())
strSQL1=PrepareSQL(",%i,%i,%i,'%s','%c','%s')",
@@ -851,10 +849,6 @@ CSong CMusicDatabase::GetSongFromDataset(bool bWithMusicDbPath/*=false*/)
song.iStartOffset = m_pDS->fv(song_iStartOffset).get_asInt();
song.iEndOffset = m_pDS->fv(song_iEndOffset).get_asInt();
song.strMusicBrainzTrackID = m_pDS->fv(song_strMusicBrainzTrackID).get_asString();
- song.strMusicBrainzArtistID = m_pDS->fv(song_strMusicBrainzArtistID).get_asString();
- song.strMusicBrainzAlbumID = m_pDS->fv(song_strMusicBrainzAlbumID).get_asString();
- song.strMusicBrainzAlbumArtistID = m_pDS->fv(song_strMusicBrainzAlbumArtistID).get_asString();
- song.strMusicBrainzTRMID = m_pDS->fv(song_strMusicBrainzTRMID).get_asString();
song.rating = m_pDS->fv(song_rating).get_asChar();
song.strComment = m_pDS->fv(song_comment).get_asString();
song.iKaraokeNumber = m_pDS->fv(song_iKarNumber).get_asInt();
@@ -901,10 +895,6 @@ void CMusicDatabase::GetFileItemFromDataset(const dbiplus::sql_record* const rec
item->SetProperty("item_start", item->m_lStartOffset);
item->m_lEndOffset = record->at(song_iEndOffset).get_asInt();
item->GetMusicInfoTag()->SetMusicBrainzTrackID(record->at(song_strMusicBrainzTrackID).get_asString());
- item->GetMusicInfoTag()->SetMusicBrainzArtistID(record->at(song_strMusicBrainzArtistID).get_asString());
- item->GetMusicInfoTag()->SetMusicBrainzAlbumID(record->at(song_strMusicBrainzAlbumID).get_asString());
- item->GetMusicInfoTag()->SetMusicBrainzAlbumArtistID(record->at(song_strMusicBrainzAlbumArtistID).get_asString());
- item->GetMusicInfoTag()->SetMusicBrainzTRMID(record->at(song_strMusicBrainzTRMID).get_asString());
item->GetMusicInfoTag()->SetRating(record->at(song_rating).get_asChar());
item->GetMusicInfoTag()->SetComment(record->at(song_comment).get_asString());
item->GetMusicInfoTag()->SetPlayCount(record->at(song_iTimesPlayed).get_asInt());
@@ -943,6 +933,7 @@ CAlbum CMusicDatabase::GetAlbumFromDataset(const dbiplus::sql_record* const reco
album.strAlbum = record->at(album_strAlbum).get_asString();
if (album.strAlbum.IsEmpty())
album.strAlbum = g_localizeStrings.Get(1050);
+ album.strMusicBrainzAlbumID = record->at(album_strMusicBrainzAlbumID).get_asString();
album.artist = StringUtils::Split(record->at(album_strArtists).get_asString(), g_advancedSettings.m_musicItemSeparator);
album.genre = StringUtils::Split(record->at(album_strGenres).get_asString(), g_advancedSettings.m_musicItemSeparator);
album.iYear = record->at(album_iYear).get_asInt();
@@ -970,6 +961,7 @@ CArtist CMusicDatabase::GetArtistFromDataset(const dbiplus::sql_record* const re
CArtist artist;
artist.idArtist = record->at(artist_idArtist).get_asInt();
artist.strArtist = record->at(artist_strArtist).get_asString();
+ artist.strMusicBrainzArtistID = record->at(artist_strMusicBrainzArtistID).get_asString();
artist.genre = StringUtils::Split(record->at(artist_strGenres).get_asString(), g_advancedSettings.m_musicItemSeparator);
artist.strBiography = record->at(artist_strBiography).get_asString();
artist.styles = StringUtils::Split(record->at(artist_strStyles).get_asString(), g_advancedSettings.m_musicItemSeparator);
@@ -3570,6 +3562,24 @@ bool CMusicDatabase::UpdateOldVersion(int version)
m_pDS->exec("CREATE UNIQUE INDEX idxSong6 on song( idPath, strFileName(255) )");
}
+ if (version < 30)
+ {
+ m_pDS->exec("ALTER TABLE artist ADD strMusicBrainzArtistID text\n");
+ m_pDS->exec("ALTER TABLE album ADD strMusicBrainzAlbumID text\n");
+ m_pDS->exec("CREATE TABLE song_new ( idSong integer primary key, idAlbum integer, idPath integer, strArtists text, strGenres text, strTitle varchar(512), iTrack integer, iDuration integer, iYear integer, dwFileNameCRC text, strFileName text, strMusicBrainzTrackID text, iTimesPlayed integer, iStartOffset integer, iEndOffset integer, idThumb integer, lastplayed varchar(20) default NULL, rating char default '0', comment text)\n");
+ m_pDS->exec("INSERT INTO song_new ( idSong, idAlbum, idPath, strArtists, strTitle, iTrack, iDuration, iYear, dwFileNameCRC, strFileName, strMusicBrainzTrackID, iTimesPlayed, iStartOffset, iEndOffset, idThumb, lastplayed, rating, comment) SELECT idSong, idAlbum, idPath, strArtists, strTitle, iTrack, iDuration, iYear, dwFileNameCRC, strFileName, strMusicBrainzTrackID, iTimesPlayed, iStartOffset, iEndOffset, idThumb, lastplayed, rating, comment FROM song");
+
+ m_pDS->exec("DROP TABLE song");
+ m_pDS->exec("ALTER TABLE song_new RENAME TO song");
+ m_pDS->exec("CREATE INDEX idxSong ON song(strTitle)");
+ m_pDS->exec("CREATE INDEX idxSong1 ON song(iTimesPlayed)");
+ m_pDS->exec("CREATE INDEX idxSong2 ON song(lastplayed)");
+ m_pDS->exec("CREATE INDEX idxSong3 ON song(idAlbum)");
+ m_pDS->exec("CREATE INDEX idxSong6 ON song(idPath)");
+
+ m_pDS->exec("CREATE UNIQUE INDEX idxArtist1 ON artist(strMusicBrainzArtistID(36))");
+ }
+
// always recreate the views after any table change
CreateViews();
@@ -290,7 +290,7 @@ class CMusicDatabase : public CDatabase
std::map<CStdString, CAlbum> m_albumCache;
virtual bool CreateTables();
- virtual int GetMinVersion() const { return 29; };
+ virtual int GetMinVersion() const { return 30; };
const char *GetBaseDBName() const { return "MyMusic"; };
int AddSong(const CSong& song, bool bCheck = true, int idAlbum = -1);
@@ -346,10 +346,6 @@ class CMusicDatabase : public CDatabase
song_dwFileNameCRC,
song_strFileName,
song_strMusicBrainzTrackID,
- song_strMusicBrainzArtistID,
- song_strMusicBrainzAlbumID,
- song_strMusicBrainzAlbumArtistID,
- song_strMusicBrainzTRMID,
song_iTimesPlayed,
song_iStartOffset,
song_iEndOffset,
@@ -371,6 +367,7 @@ class CMusicDatabase : public CDatabase
{
album_idAlbum=0,
album_strAlbum,
+ album_strMusicBrainzAlbumID,
album_strArtists,
album_strGenres,
album_iYear,
@@ -390,6 +387,7 @@ class CMusicDatabase : public CDatabase
{
artist_idArtist=0,
artist_strArtist,
+ artist_strMusicBrainzArtistID,
artist_strBorn,
artist_strFormed,
artist_strGenres,
View
@@ -36,10 +36,6 @@ CSong::CSong(CMusicInfoTag& tag)
strAlbum = tag.GetAlbum();
albumArtist = tag.GetAlbumArtist();
strMusicBrainzTrackID = tag.GetMusicBrainzTrackID();
- strMusicBrainzArtistID = tag.GetMusicBrainzArtistID();
- strMusicBrainzAlbumID = tag.GetMusicBrainzAlbumID();
- strMusicBrainzAlbumArtistID = tag.GetMusicBrainzAlbumArtistID();
- strMusicBrainzTRMID = tag.GetMusicBrainzTRMID();
strComment = tag.GetComment();
rating = tag.GetRating();
iYear = stTime.wYear;
@@ -74,10 +70,6 @@ void CSong::Serialize(CVariant& value)
value["track"] = iTrack;
value["year"] = iYear;
value["musicbrainztrackid"] = strMusicBrainzTrackID;
- value["musicbrainzartistid"] = strMusicBrainzArtistID;
- value["musicbrainzalbumid"] = strMusicBrainzAlbumID;
- value["musicbrainzalbumartistid"] = strMusicBrainzAlbumArtistID;
- value["musicbrainztrmid"] = strMusicBrainzTRMID;
value["comment"] = strComment;
value["rating"] = rating;
value["timesplayed"] = iTimesPlayed;
@@ -96,10 +88,6 @@ void CSong::Clear()
genre.clear();
strThumb.Empty();
strMusicBrainzTrackID.Empty();
- strMusicBrainzArtistID.Empty();
- strMusicBrainzAlbumID.Empty();
- strMusicBrainzAlbumArtistID.Empty();
- strMusicBrainzTRMID.Empty();
strComment.Empty();
rating = '0';
iTrack = 0;
View
@@ -87,10 +87,6 @@ class CSong: public ISerializable
CStdString strThumb;
MUSIC_INFO::EmbeddedArtInfo embeddedArt;
CStdString strMusicBrainzTrackID;
- CStdString strMusicBrainzArtistID;
- CStdString strMusicBrainzAlbumID;
- CStdString strMusicBrainzAlbumArtistID;
- CStdString strMusicBrainzTRMID;
CStdString strComment;
char rating;
int iTrack;
@@ -534,10 +534,6 @@ void CMusicInfoTag::SetSong(const CSong& song)
SetAlbum(song.strAlbum);
SetAlbumArtist(song.albumArtist);
SetMusicBrainzTrackID(song.strMusicBrainzTrackID);
- SetMusicBrainzArtistID(song.strMusicBrainzArtistID);
- SetMusicBrainzAlbumID(song.strMusicBrainzAlbumID);
- SetMusicBrainzAlbumArtistID(song.strMusicBrainzAlbumArtistID);
- SetMusicBrainzTRMID(song.strMusicBrainzTRMID);
SetComment(song.strComment);
SetPlayCount(song.iTimesPlayed);
SetLastPlayed(song.lastPlayed);

0 comments on commit 5d87a9d

Please sign in to comment.