aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDave Blake <oak99sky@yahoo.co.uk>2019-04-05 07:49:01 +0100
committerGitHub <noreply@github.com>2019-04-05 07:49:01 +0100
commit782b38287c46b5dd764dc30d04f874cc398e2ba1 (patch)
treecdf52773c89bb3faf9b197841546d3a8879cfebf
parent20a5b591cfb3e67cc572530ea95839ca9d165cab (diff)
parent7bb91d94bf075d1e22b4addee30dcc3821eac7a2 (diff)
Merge pull request #15805 from rmrector/fill-music-arttypes
Include user config and available artwork in music "Choose art type" dialog
-rw-r--r--xbmc/music/MusicDatabase.cpp42
-rw-r--r--xbmc/music/MusicDatabase.h8
-rw-r--r--xbmc/music/MusicUtils.cpp100
-rw-r--r--xbmc/music/MusicUtils.h7
-rw-r--r--xbmc/music/infoscanner/MusicInfoScanner.cpp24
-rw-r--r--xbmc/music/infoscanner/MusicInfoScanner.h8
6 files changed, 142 insertions, 47 deletions
diff --git a/xbmc/music/MusicDatabase.cpp b/xbmc/music/MusicDatabase.cpp
index 48c7bdb98e..4367a08f14 100644
--- a/xbmc/music/MusicDatabase.cpp
+++ b/xbmc/music/MusicDatabase.cpp
@@ -10251,6 +10251,48 @@ bool CMusicDatabase::GetArtTypes(const MediaType &mediaType, std::vector<std::st
return false;
}
+std::vector<std::string> CMusicDatabase::GetAvailableArtTypesForItem(int mediaId,
+ const MediaType& mediaType)
+{
+ std::vector<std::string> result;
+ if (mediaType == MediaTypeArtist)
+ {
+ CArtist artist;
+ if (GetArtist(mediaId, artist))
+ {
+ //! @todo artwork: fanart stored separately, doesn't need to be
+ if (artist.fanart.GetNumFanarts())
+ result.push_back("fanart");
+
+ // all other images
+ for (const auto& urlEntry : artist.thumbURL.m_url)
+ {
+ std::string artType = urlEntry.m_aspect;
+ if (artType.empty())
+ artType = "thumb";
+ if (std::find(result.begin(), result.end(), artType) == result.end())
+ result.push_back(artType);
+ }
+ }
+ }
+ else if (mediaType == MediaTypeAlbum)
+ {
+ CAlbum album;
+ if (GetAlbum(mediaId, album))
+ {
+ for (const auto& urlEntry : album.thumbURL.m_url)
+ {
+ std::string artType = urlEntry.m_aspect;
+ if (artType.empty())
+ artType = "thumb";
+ if (std::find(result.begin(), result.end(), artType) == result.end())
+ result.push_back(artType);
+ }
+ }
+ }
+ return result;
+}
+
bool CMusicDatabase::GetFilter(CDbUrl &musicUrl, Filter &filter, SortDescription &sorting)
{
if (!musicUrl.IsValid())
diff --git a/xbmc/music/MusicDatabase.h b/xbmc/music/MusicDatabase.h
index 20092b8a7b..3ef778d6d4 100644
--- a/xbmc/music/MusicDatabase.h
+++ b/xbmc/music/MusicDatabase.h
@@ -596,6 +596,14 @@ public:
*/
bool GetArtTypes(const MediaType &mediaType, std::vector<std::string> &artTypes);
+ /*! \brief Fetch the distinct types of available-but-unassigned art held in the
+ database for a specific media item.
+ \param mediaId the id in the media (artist/album) table.
+ \param mediaType the type of media, which corresponds to the table the item resides in (artist/album).
+ \return the types of art e.g. "thumb", "fanart", etc.
+ */
+ std::vector<std::string> GetAvailableArtTypesForItem(int mediaId, const MediaType& mediaType);
+
/////////////////////////////////////////////////
// Tag Scan Version
/////////////////////////////////////////////////
diff --git a/xbmc/music/MusicUtils.cpp b/xbmc/music/MusicUtils.cpp
index 38d925a807..8a7efaaf7a 100644
--- a/xbmc/music/MusicUtils.cpp
+++ b/xbmc/music/MusicUtils.cpp
@@ -18,6 +18,9 @@
#include "PlayListPlayer.h"
#include "playlists/PlayList.h"
#include "ServiceBroker.h"
+#include "settings/AdvancedSettings.h"
+#include "settings/Settings.h"
+#include "settings/SettingsComponent.h"
#include "utils/JobManager.h"
using namespace MUSIC_INFO;
@@ -177,42 +180,84 @@ namespace MUSIC_UTILS
CJobManager::GetInstance().AddJob(job, NULL);
}
- bool FillArtTypesList(CFileItem& musicitem, CFileItemList& artlist)
+ // Add art types required in Kodi
+ void AddHardCodedArtTypes(std::vector<std::string>& artTypes, const CMusicInfoTag& tag)
{
- CMusicInfoTag &tag = *musicitem.GetMusicInfoTag();
- if (tag.GetDatabaseId() < 1 || tag.GetType().empty())
- return false;
- if (tag.GetType() != MediaTypeArtist && tag.GetType() != MediaTypeAlbum && tag.GetType() != MediaTypeSong)
- return false;
-
- artlist.Clear();
- // Songs, albums and artists all have thumbs by default
- std::vector<std::string> artTypes = { "thumb" };
+ artTypes.emplace_back("thumb");
if (tag.GetType() == MediaTypeArtist)
{
artTypes.emplace_back("fanart");
}
+ }
- CMusicDatabase db;
- db.Open();
+ // Add art types configured by the user
+ void AddExtendedArtTypes(std::vector<std::string>& artTypes, const CMusicInfoTag& tag)
+ {
+ for (const auto& artType : GetArtTypesToScan(tag.GetType()))
+ {
+ if (find(artTypes.begin(), artTypes.end(), artType) == artTypes.end())
+ artTypes.push_back(artType);
+ }
+ }
- // Add in any stored art for this item that is non-empty.
+ // Add art types currently assigned to to the media item
+ void AddCurrentArtTypes(std::vector<std::string>& artTypes, const CMusicInfoTag& tag,
+ CMusicDatabase& db)
+ {
std::map<std::string, std::string> currentArt;
db.GetArtForItem(tag.GetDatabaseId(), tag.GetType(), currentArt);
- for (const auto art : currentArt)
+ for (const auto& art : currentArt)
{
if (!art.second.empty() && find(artTypes.begin(), artTypes.end(), art.first) == artTypes.end())
artTypes.push_back(art.first);
}
+ }
- // Add any art types that exist for other media items of the same type
+ // Add art types that exist for other media items of the same type
+ void AddMediaTypeArtTypes(std::vector<std::string>& artTypes, const CMusicInfoTag& tag,
+ CMusicDatabase& db)
+ {
std::vector<std::string> dbArtTypes;
db.GetArtTypes(tag.GetType(), dbArtTypes);
- for (const auto it : dbArtTypes)
+ for (const auto& artType : dbArtTypes)
{
- if (find(artTypes.begin(), artTypes.end(), it) == artTypes.end())
- artTypes.push_back(it);
+ if (find(artTypes.begin(), artTypes.end(), artType) == artTypes.end())
+ artTypes.push_back(artType);
}
+ }
+
+ // Add art types from available but unassigned artwork for this media item
+ void AddAvailableArtTypes(std::vector<std::string>& artTypes, const CMusicInfoTag& tag,
+ CMusicDatabase& db)
+ {
+ for (const auto& artType : db.GetAvailableArtTypesForItem(tag.GetDatabaseId(), tag.GetType()))
+ {
+ if (find(artTypes.begin(), artTypes.end(), artType) == artTypes.end())
+ artTypes.push_back(artType);
+ }
+ }
+
+ bool FillArtTypesList(CFileItem& musicitem, CFileItemList& artlist)
+ {
+ CMusicInfoTag &tag = *musicitem.GetMusicInfoTag();
+ if (tag.GetDatabaseId() < 1 || tag.GetType().empty())
+ return false;
+ if (tag.GetType() != MediaTypeArtist && tag.GetType() != MediaTypeAlbum && tag.GetType() != MediaTypeSong)
+ return false;
+
+ artlist.Clear();
+
+ CMusicDatabase db;
+ db.Open();
+
+ std::vector<std::string> artTypes;
+
+ AddHardCodedArtTypes(artTypes, tag);
+ AddExtendedArtTypes(artTypes, tag);
+ AddCurrentArtTypes(artTypes, tag, db);
+ AddMediaTypeArtTypes(artTypes, tag, db);
+ AddAvailableArtTypes(artTypes, tag, db);
+
db.Close();
for (const auto type : artTypes)
@@ -305,4 +350,23 @@ namespace MUSIC_UTILS
job = new CSetSongRatingJob(pItem->GetPath(), userrating);
CJobManager::GetInstance().AddJob(job, NULL);
}
+
+ std::vector<std::string> GetArtTypesToScan(const MediaType& mediaType)
+ {
+ std::vector<std::string> arttypes;
+ // Get default types of art that are to be automatically fetched during scanning
+ if (mediaType == MediaTypeArtist)
+ {
+ arttypes = CServiceBroker::GetSettingsComponent()->GetAdvancedSettings()->m_musicArtistExtraArt;
+ arttypes.emplace_back("thumb");
+ arttypes.emplace_back("fanart");
+ }
+ else if (mediaType == MediaTypeAlbum)
+ {
+ arttypes = CServiceBroker::GetSettingsComponent()->GetAdvancedSettings()->m_musicAlbumExtraArt;
+ arttypes.emplace_back("thumb");
+ }
+
+ return arttypes;
+ }
}
diff --git a/xbmc/music/MusicUtils.h b/xbmc/music/MusicUtils.h
index 9b5323c2e1..97415f7fb3 100644
--- a/xbmc/music/MusicUtils.h
+++ b/xbmc/music/MusicUtils.h
@@ -56,4 +56,11 @@ namespace MUSIC_UTILS
\param userrating the userrating 0 = no rating, 1 to 10
*/
void UpdateSongRatingJob(const CFileItemPtr pItem, int userrating);
+
+ /*! \brief Get the types of art for an artist or album that are to be
+ automatically fetched from local files during scanning
+ \param mediaType [in] artist or album
+ \return vector of art types that are to be fetched during scanning
+ */
+ std::vector<std::string> GetArtTypesToScan(const MediaType& mediaType);
}
diff --git a/xbmc/music/infoscanner/MusicInfoScanner.cpp b/xbmc/music/infoscanner/MusicInfoScanner.cpp
index 71902d19d4..c8c9ef4531 100644
--- a/xbmc/music/infoscanner/MusicInfoScanner.cpp
+++ b/xbmc/music/infoscanner/MusicInfoScanner.cpp
@@ -36,6 +36,7 @@
#include "interfaces/AnnouncementManager.h"
#include "music/MusicLibraryQueue.h"
#include "music/MusicThumbLoader.h"
+#include "music/MusicUtils.h"
#include "music/tags/MusicInfoTag.h"
#include "music/tags/MusicInfoTagLoaderFactory.h"
#include "MusicAlbumInfo.h"
@@ -1924,31 +1925,12 @@ void CMusicInfoScanner::ScannerWait(unsigned int milliseconds)
XbmcThreads::ThreadSleep(milliseconds);
}
-std::vector<std::string> CMusicInfoScanner::GetArtTypesToScan(const MediaType& mediaType)
-{
- std::vector<std::string> arttypes;
- // Get default types of art that are to be automatically fetched during scanning
- if (mediaType == MediaTypeArtist)
- {
- arttypes = CServiceBroker::GetSettingsComponent()->GetAdvancedSettings()->m_musicArtistExtraArt;
- arttypes.emplace_back("thumb");
- arttypes.emplace_back("fanart");
- }
- else if (mediaType == MediaTypeAlbum)
- {
- arttypes = CServiceBroker::GetSettingsComponent()->GetAdvancedSettings()->m_musicAlbumExtraArt;
- arttypes.emplace_back("thumb");
- }
-
- return arttypes;
-}
-
std::vector<std::string> CMusicInfoScanner::GetMissingArtTypes(const MediaType& mediaType, const std::map<std::string, std::string>& art)
{
std::vector<std::string> missing;
std::vector<std::string> arttypes;
// Get default types of art that are automatically fetched during scanning
- arttypes = GetArtTypesToScan(mediaType);
+ arttypes = MUSIC_UTILS::GetArtTypesToScan(mediaType);
// Find the types which are missing from the given art
if (art.empty())
@@ -2150,7 +2132,7 @@ void CMusicInfoScanner::SetDiscSetArtwork(CAlbum& album, const std::vector<std::
// Get default types of art that are to be automatically fetched during scanning
std::vector<std::string> arttypes;
- arttypes = GetArtTypesToScan(MediaTypeAlbum);
+ arttypes = MUSIC_UTILS::GetArtTypesToScan(MediaTypeAlbum);
// Check that there are art types other than thumb to process
bool extratype = !CServiceBroker::GetSettingsComponent()->GetAdvancedSettings()->m_musicAlbumExtraArt.empty();
diff --git a/xbmc/music/infoscanner/MusicInfoScanner.h b/xbmc/music/infoscanner/MusicInfoScanner.h
index b6f34d8f41..bb1fa084c9 100644
--- a/xbmc/music/infoscanner/MusicInfoScanner.h
+++ b/xbmc/music/infoscanner/MusicInfoScanner.h
@@ -143,14 +143,6 @@ protected:
*/
INFO_RET DownloadArtistInfo(const CArtist& artist, const ADDON::ScraperPtr& scraper, MUSIC_GRABBER::CMusicArtistInfo& artistInfo, bool bUseScrapedMBID, CGUIDialogProgress* pDialog = NULL);
-
- /*! \brief Get the types of art for an artist or album that are to be
- automatically fetched from local files during scanning
- \param mediaType [in] artist or album
- \return vector of art types that are to be fetched during scanning
- */
- std::vector<std::string> GetArtTypesToScan(const MediaType& mediaType);
-
/*! \brief Get the types of art for an artist or album that can be
automatically found during scanning, and are not in the provided set of art
\param mediaType [in] artist or album