Permalink
Browse files

Ensure all songs and albums have an artist. This removes need for LEFT

JOIN and avoids the SQLite optimiser limitations whereby it can not
flatten a left join on view and results in slow queries. The invented
"Missing artist" is unique and different from any other artist that could
be scanned from music file tags. It always exists with fixed artist ID =
1.

Use temp indices during db update for speed. Move any existsing record
with ID = 1.

Add AudioLibrary.GetProperties to generically return the missing artist tag artist ID. This could be extended in the future with other music library properties.
  • Loading branch information...
DaveTBlake committed Feb 15, 2016
1 parent 90a1bd5 commit a97aa2a3987e668e68597e8a9c00319f524267e4
@@ -18561,3 +18561,9 @@ msgstr ""
msgctxt "#38041"
msgid "Mixer"
msgstr ""

#. Missing artist name
#: music/MusicDatabase.cpp
msgctxt "#38042"
msgid "[Missing]"
msgstr ""
@@ -41,6 +41,23 @@ using namespace JSONRPC;
using namespace XFILE;
using namespace KODI::MESSAGING;

JSONRPC_STATUS CAudioLibrary::GetProperties(const std::string &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result)
{
CVariant properties = CVariant(CVariant::VariantTypeObject);
for (CVariant::const_iterator_array it = parameterObject["properties"].begin_array(); it != parameterObject["properties"].end_array(); it++)
{
std::string propertyName = it->asString();
CVariant property;
if (propertyName == "missingartistid")
property = (int)BLANKARTIST_ID;

properties[propertyName] = property;
}

result = properties;
return OK;
}

JSONRPC_STATUS CAudioLibrary::GetArtists(const std::string &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result)
{
CMusicDatabase musicdatabase;
@@ -86,6 +103,7 @@ JSONRPC_STATUS CAudioLibrary::GetArtists(const std::string &method, ITransportLa
return InvalidParams;

CFileItemList items;
musicdatabase.SetTranslateBlankArtist(false);
if (!musicdatabase.GetArtistsNav(musicUrl.ToString(), items, albumArtistsOnly, genreID, albumID, songID, CDatabase::Filter(), sorting))
return InternalError;

@@ -32,6 +32,7 @@ namespace JSONRPC
class CAudioLibrary : public CFileItemHandler
{
public:
static JSONRPC_STATUS GetProperties(const std::string &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result);
static JSONRPC_STATUS GetArtists(const std::string &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result);
static JSONRPC_STATUS GetArtistDetails(const std::string &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result);
static JSONRPC_STATUS GetAlbums(const std::string &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result);
@@ -100,6 +100,7 @@ JsonRpcMethodMap CJSONServiceDescription::m_methodMaps[] = {
{ "Files.Download", CFileOperations::Download },

// Music Library
{ "AudioLibrary.GetProperties", CAudioLibrary::GetProperties },
{ "AudioLibrary.GetArtists", CAudioLibrary::GetArtists },
{ "AudioLibrary.GetArtistDetails", CAudioLibrary::GetArtistDetails },
{ "AudioLibrary.GetAlbums", CAudioLibrary::GetAlbums },
@@ -639,6 +639,16 @@
}
}
},
"AudioLibrary.GetProperties": {
"type": "method",
"description": "Retrieves the values of the music library properties",
"transport": "Response",
"permission": "ReadData",
"params": [
{ "name": "properties", "type": "array", "uniqueItems": true, "required": true, "items": { "$ref": "Audio.Property.Name" } }
],
"returns": { "$ref": "Audio.Property.Value", "required": true }
},
"AudioLibrary.GetArtists": {
"type": "method",
"description": "Retrieve all artists",
@@ -551,6 +551,16 @@
"displaylyricist": { "type": "string"}
}
},
"Audio.Property.Name": {
"type": "string",
"enum": [ "missingartistid" ]
},
"Audio.Property.Value": {
"type": "object",
"properties": {
"missingartistid": { "$ref": "Library.Id" }
}
},
"Video.Fields.Movie": {
"extends": "Item.Fields.Base",
"items": { "type": "string",
@@ -1 +1 @@
7.8.1
7.9.0
@@ -146,6 +146,10 @@ class CArtistCredit
typedef std::vector<CArtist> VECARTISTS;
typedef std::vector<CArtistCredit> VECARTISTCREDITS;

const std::string BLANKARTIST_FAKEMUSICBRAINZID = "Artist Tag Missing";
const std::string BLANKARTIST_NAME = "[Missing Tag]";
const long BLANKARTIST_ID = 1;

#define ROLE_ARTIST 1 //Default role

class CMusicRole

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -257,6 +257,7 @@ class CMusicDatabase : public CDatabase

int AddArtist(const std::string& strArtist, const std::string& strMusicBrainzArtistID);
bool GetArtist(int idArtist, CArtist& artist, bool fetchAll = true);
bool GetArtistExists(int idArtist);
int UpdateArtist(int idArtist,
const std::string& strArtist, const std::string& strMusicBrainzArtistID,
const std::string& strBorn, const std::string& strFormed,
@@ -265,6 +266,8 @@ class CMusicDatabase : public CDatabase
const std::string& strBiography, const std::string& strDied,
const std::string& strDisbanded, const std::string& strYearsActive,
const std::string& strImage, const std::string& strFanart);
bool GetTranslateBlankArtist() { return m_translateBlankArtist; }
void SetTranslateBlankArtist(bool translate) { m_translateBlankArtist = translate; }
bool HasArtistBeenScraped(int idArtist);
bool ClearArtistLastScrapedTime(int idArtist);
int AddArtistDiscography(int idArtist, const std::string& strAlbum, const std::string& strYear);
@@ -529,6 +532,8 @@ class CMusicDatabase : public CDatabase
bool SearchSongs(const std::string& strSearch, CFileItemList &songs);
int GetSongIDFromPath(const std::string &filePath);

bool m_translateBlankArtist;

// Fields should be ordered as they
// appear in the songview
static enum _SongFields
@@ -200,7 +200,7 @@ const std::string CMusicInfoTag::GetArtistString() const
else if (!m_artist.empty())
return StringUtils::Join(m_artist, g_advancedSettings.m_musicItemSeparator);
else
return std::string();
return StringUtils::Empty;
}

const std::string& CMusicInfoTag::GetAlbum() const
@@ -225,7 +225,7 @@ const std::string CMusicInfoTag::GetAlbumArtistString() const
if (!m_albumArtist.empty())
return StringUtils::Join(m_albumArtist, g_advancedSettings.m_musicItemSeparator);
else
return std::string();
return StringUtils::Empty;
}


0 comments on commit a97aa2a

Please sign in to comment.