Permalink
Browse files

multi-CD albums: prevent multiple entries, improve art search

Improve handling of multi-CD albums:

 - revert 8cb4b55 that fixes the problem
   with showing multi-CD albums multiple times, but it breaks artwork
   caching for album view. As the album path is ignored we search artwork
   with path=None and as the result when Artwork.artwork_get_local_image
   is called with songpath=None it looks for artwork in the directory of
   current song. So all the albums get the same artwork and the art_cache
   is broken.

 - add Base.get_multicd_album_root_dir method to get album root directory
   for tracks from multi-CD albums. For example, if track is located in
   'artist/album/CD 2' directory than the method returns 'artist/album'.
   This method is used in artwork search algorithm (to look for artwork
   in album root directory but not in CD's subdirectory) and while
   populating album view (to merge all CDs into single album entry).
  • Loading branch information...
1 parent b4ce54f commit 01917ad22a10babdc49e762653cd3c2408953e44 Kirill Lashuk committed Jul 18, 2010
Showing with 27 additions and 7 deletions.
  1. +12 −6 sonata/library.py
  2. +15 −1 sonata/main.py
View
@@ -45,11 +45,11 @@ def library_get_data(data, *args):
class Library(object):
-
def __init__(self, config, client, artwork, TAB_LIBRARY, album_filename,
settings_save, filtering_entry_make_red,
filtering_entry_revert_color, filter_key_pressed,
- on_add_item, connected, on_library_button_press, new_tab):
+ on_add_item, connected, on_library_button_press, new_tab,
+ get_multicd_album_root_dir):
self.artwork = artwork
self.config = config
self.client = client
@@ -62,6 +62,7 @@ def __init__(self, config, client, artwork, TAB_LIBRARY, album_filename,
self.on_add_item = on_add_item
self.connected = connected
self.on_library_button_press = on_library_button_press
+ self.get_multicd_album_root_dir = get_multicd_album_root_dir
self.NOTAG = _("Untagged")
self.VAstr = _("Various Artists")
@@ -630,8 +631,10 @@ def library_populate_toplevel_data(self, genreview=False, artistview=False,
album = mpdh.get(item, 'album')
artist = mpdh.get(item, 'artist', self.NOTAG)
year = mpdh.get(item, 'date', self.NOTAG)
+ path = self.get_multicd_album_root_dir(
+ os.path.dirname(mpdh.get(item, 'file')))
data = self.library_set_data(album=album, artist=artist,
- year=year)
+ year=year, path=path)
albums.append(data)
if album == self.NOTAG:
untagged_found = True
@@ -640,14 +643,17 @@ def library_populate_toplevel_data(self, genreview=False, artistview=False,
albums = misc.remove_list_duplicates(albums, case=False)
albums = self.list_identify_VA_albums(albums)
for item in albums:
- album, artist, year = self.library_get_data(item, 'album',
- 'artist', 'year')
+ album, artist, year, path = self.library_get_data(item,
+ 'album',
+ 'artist',
+ 'year',
+ 'path')
playtime, num_songs = self.library_return_count(artist=artist,
album=album,
year=year)
if num_songs > 0:
data = self.library_set_data(artist=artist, album=album,
- year=year)
+ year=year, path=path)
display = misc.escape_html(album)
if artist and year and len(artist) > 0 and len(year) > 0 \
and artist != self.NOTAG and year != self.NOTAG:
View
@@ -528,7 +528,8 @@ def __init__(self, args, window=None, _sugar=False):
self.current.filtering_entry_make_red,
self.current.filtering_entry_revert_color,
self.current.filter_key_pressed, self.on_add_item, self.connected,
- self.on_library_button_press, self.new_tab)
+ self.on_library_button_press, self.new_tab,
+ self.get_multicd_album_root_dir)
self.library_treeview = self.library.get_treeview()
self.library_selection = self.library.get_selection()
@@ -2375,6 +2376,7 @@ def target_image_filename(self, force_location=None, songpath=None,
artist = artist.replace("/", "")
if songpath is None:
songpath = os.path.dirname(mpdh.get(self.songinfo, 'file'))
+ songpath = self.get_multicd_album_root_dir(songpath)
# Return target filename:
if force_location is not None:
art_loc = force_location
@@ -2402,6 +2404,18 @@ def target_image_filename(self, force_location=None, songpath=None,
targetfile = misc.file_exists_insensitive(targetfile)
return misc.file_from_utf8(targetfile)
+ def get_multicd_album_root_dir(self, albumpath):
+ """Go one dir upper for multicd albums
+ Examples:
+ 'Moonspell/1995 - Wolfheart/cd 2' -> 'Moonspell/1995 - Wolfheart'
+ '2007 - Dark Passion Play/CD3' -> '2007 - Dark Passion Play'
+ 'Ayreon/2008 - 01011001/CD 1 - Y' -> 'Ayreon/2008 - 01011001'
+ """
+
+ if re.compile(r'(?i)cd\s*\d+').match(os.path.split(albumpath)[1]):
+ albumpath = os.path.split(albumpath)[0]
+ return albumpath
+
def album_return_artist_and_tracks(self):
# Includes logic for Various Artists albums to determine
# the tracks.

0 comments on commit 01917ad

Please sign in to comment.