Skip to content

Commit

Permalink
some fixes to musicartwork
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelveldt committed Nov 27, 2016
1 parent 32e6b41 commit 0c7fa47
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 21 deletions.
2 changes: 1 addition & 1 deletion addon.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="script.module.skin.helper.artutils"
name="Skin Helper Artwork and metadata Module"
version="1.0.6"
version="1.0.7"
provider-name="marcelveldt">
<requires>
<import addon="xbmc.python" version="2.24.0"/>
Expand Down
11 changes: 6 additions & 5 deletions lib/artutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,10 @@ class ArtUtils(object):
'''
close_called = False

def __init__(self, cache=None):
def __init__(self):
'''Initialize and load all our helpers'''
self._studiologos_path = ""
if cache:
self.cache = cache
else:
self.cache = SimpleCache()
self.cache = SimpleCache()
self.addon = xbmcaddon.Addon(ADDON_ID)
self.kodidb = KodiDb()
self.omdb = Omdb(self.cache)
Expand Down Expand Up @@ -101,6 +98,7 @@ def music_artwork_options(self, artist, album="", track="", disc=""):
@use_cache(14)
def get_extended_artwork(self, imdb_id="", tvdb_id="", media_type=""):
'''get extended artwork for the given imdbid or tvdbid'''
from urllib import quote_plus
result = {}
if "movie" in media_type and imdb_id:
result["art"] = self.fanarttv.movie(imdb_id)
Expand All @@ -112,6 +110,9 @@ def get_extended_artwork(self, imdb_id="", tvdb_id="", media_type=""):
tvdb_id = self.thetvdb.get_series_by_imdb_id(imdb_id).get("tvdb_id")
if tvdb_id:
result["art"] = self.fanarttv.tvshow(tvdb_id)
if result["art"].get("fanarts") and len(result["art"]["fanarts"]) > 1:
result["art"]["extrafanart"] = "plugin://script.skin.helper.service/"\
"?action=extrafanart&fanarts=%s" % quote_plus(repr(result["art"]["fanarts"]))
return result

@use_cache(14)
Expand Down
39 changes: 24 additions & 15 deletions lib/helpers/musicartwork.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def get_music_artwork(self, artist, album, track, disc, ignore_cache=False):
album_details = self.get_album_metadata(artist, album, track, disc, ignore_cache=ignore_cache)
if details.get("plot") and album_details.get("plot"):
details["plot"] = "%s -- %s" % (album_details["plot"], details["plot"])
extend_dict(details, album_details)
details = extend_dict(details, album_details)
return details

def manual_set_music_artwork(self, artist, album, track, disc):
Expand Down Expand Up @@ -163,18 +163,18 @@ def get_artist_metadata(self, artist, album, track, ignore_cache=False):
local_path = ""
local_path_custom = ""
# get metadata from kodi db
extend_dict(details, self.get_artist_kodi_metadata(artist))
details = extend_dict(details, self.get_artist_kodi_metadata(artist))
# get artwork from songlevel path
if details.get("diskpath") and self.artutils.addon.getSetting("music_art_musicfolders") == "true":
extend_dict(details["art"], self.lookup_artistart_in_folder(details["diskpath"]))
details["art"] = extend_dict(details["art"], self.lookup_artistart_in_folder(details["diskpath"]))
local_path = details["diskpath"]
# get artwork from custom folder
if self.artutils.addon.getSetting("music_art_custom") == "true":
custom_path = self.artutils.addon.getSetting("music_art_custom_path").decode("utf-8")
if custom_path:
diskpath = self.get_customfolder_path(custom_path, artist)
if diskpath:
extend_dict(details["art"], self.lookup_artistart_in_folder(diskpath))
details["art"] = extend_dict(details["art"], self.lookup_artistart_in_folder(diskpath))
local_path_custom = diskpath
# lookup online metadata
if self.artutils.addon.getSetting("music_art_scraper") == "true":
Expand All @@ -184,11 +184,11 @@ def get_artist_metadata(self, artist, album, track, ignore_cache=False):
mb_artistid = self.get_mb_artist_id(artist, album, track)
if mb_artistid:
# get artwork from fanarttv
extend_dict(details["art"], self.artutils.fanarttv.artist(mb_artistid))
details["art"] = extend_dict(details["art"], self.artutils.fanarttv.artist(mb_artistid))
# get metadata from theaudiodb
extend_dict(details, self.audiodb.artist_info(mb_artistid))
details = extend_dict(details, self.audiodb.artist_info(mb_artistid))
# get metadata from lastfm
extend_dict(details, self.lastfm.artist_info(mb_artistid))
details = extend_dict(details, self.lastfm.artist_info(mb_artistid))

# download artwork to music folder
if local_path and self.artutils.addon.getSetting("music_art_download") == "true":
Expand Down Expand Up @@ -224,29 +224,29 @@ def get_album_metadata(self, artist, album, track, disc, ignore_cache=False):
local_path = ""
local_path_custom = ""
# get metadata from kodi db
extend_dict(details, self.get_album_kodi_metadata(artist, album, track, disc))
details = extend_dict(details, self.get_album_kodi_metadata(artist, album, track, disc))
# get artwork from songlevel path
if details.get("diskpath") and self.artutils.addon.getSetting("music_art_musicfolders") == "true":
extend_dict(details["art"], self.lookup_albumart_in_folder(details["diskpath"]))
details["art"] = extend_dict(details["art"], self.lookup_albumart_in_folder(details["diskpath"]))
local_path = details["diskpath"]
# get artwork from custom folder
if self.artutils.addon.getSetting("music_art_custom") == "true":
custom_path = self.artutils.addon.getSetting("music_art_custom_path").decode("utf-8")
if custom_path:
diskpath = self.get_custom_album_path(custom_path, artist, album, disc)
if diskpath:
extend_dict(details["art"], self.lookup_albumart_in_folder(diskpath))
details["art"] = extend_dict(details["art"], self.lookup_albumart_in_folder(diskpath))
local_path_custom = diskpath
# lookup online metadata
if self.artutils.addon.getSetting("music_art_scraper") == "true":
mb_albumid = self.get_mb_album_id(artist, album, track)
if mb_albumid:
# get artwork from fanarttv
extend_dict(details["art"], self.artutils.fanarttv.album(mb_albumid))
details["art"] = extend_dict(details["art"], self.artutils.fanarttv.album(mb_albumid))
# get metadata from theaudiodb
extend_dict(details, self.audiodb.album_info(mb_albumid))
details = extend_dict(details, self.audiodb.album_info(mb_albumid))
# get metadata from lastfm
extend_dict(details, self.lastfm.album_info(mb_albumid))
details = extend_dict(details, self.lastfm.album_info(mb_albumid))
# musicbrainz thumb as last resort
if not details["art"].get("thumb"):
details["art"]["thumb"] = self.mbrainz.get_albumthumb(mb_albumid)
Expand Down Expand Up @@ -319,14 +319,23 @@ def get_album_kodi_metadata(self, artist, album, track, disc):
filters = [{"albumid": details["albumid"]}]
album_tracks = self.artutils.kodidb.songs(filters=filters)
details["tracks"] = []
bullet = "•".decode("utf-8")
details["tracks.formatted"] = u""
details["tracks.formatted2"] = ""
for item in album_tracks:
details["tracks"].append(item["title"])
details["tracks.formatted"] += u"%s %s [CR]" % (bullet, item["title"])
duration = item["duration"]
total_seconds = int(duration)
minutes = total_seconds / 60
seconds = total_seconds - (minutes * 60)
duration = "%s:%s" % (minutes, str(seconds).zfill(2))
details["tracks.formatted2"] += u"%s %s (%s)[CR]" % (bullet, item["title"], duration)
if not details.get("diskpath"):
if not disc or item["disc"] == int(disc):
details["diskpath"] = self.get_albumpath_by_songpath(item["file"])
joinchar = "[CR]• ".decode("utf-8")
details["tracks.formatted"] = joinchar.join(details["tracks"])
details["art"] = {}
details["songcount"] = len(album_tracks)
fanart = get_clean_image(details["fanart"])
if xbmcvfs.exists(fanart):
details["art"]["fanart"] = fanart
Expand Down

0 comments on commit 0c7fa47

Please sign in to comment.