From 94c268d17e1153cbd201d6ee3874acae8fd590de Mon Sep 17 00:00:00 2001 From: Angel Alonso Date: Sat, 1 Nov 2014 18:41:39 +0100 Subject: [PATCH 1/3] convert: copy album art when copying or transcoding. Only implemented to work when matching albums instead of tracks (-a option). Disabled by default in the configuration of 'convert'. fix indentation. Fix Travis nagging over indentation (hopefully). Finally pep8 conforming. --- beetsplug/convert.py | 50 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/beetsplug/convert.py b/beetsplug/convert.py index 90def8400..25ea695a4 100644 --- a/beetsplug/convert.py +++ b/beetsplug/convert.py @@ -248,6 +248,49 @@ def convert_on_import(lib, item): item.store() +def copy_album_art(album, dest_dir, path_formats, pretend=False): + """Copies the associated cover art of the album. Album must have at least + one track. + """ + if not album or not album.artpath: + return + + album_item = album.items().get() + # Album shouldn't be empty. + if not album_item: + return + + # Get the destination of the first item (track) of the album, we use this + # function to format the path accordingly to path_formats. + dest = album_item.destination(basedir=dest_dir, path_formats=path_formats) + + # Remove item from the path. + dest = os.path.join(*util.components(dest)[:-1]) + + dest = album.art_destination(album.artpath, item_dir=dest) + if album.artpath == dest: + return + + if not pretend: + util.mkdirall(dest) + + if os.path.exists(util.syspath(dest)): + log.info(u'Skipping {0} (target file exists)'.format( + util.displayable_path(album.artpath) + )) + return + + if pretend: + log.info(u'cp {0} {1}'.format( + util.displayable_path(album.artpath), + util.displayable_path(dest), + )) + else: + log.info(u'Copying cover art to {0}'.format( + util.displayable_path(dest))) + util.copy(album.artpath, dest) + + def convert_func(lib, opts, args): if not opts.dest: opts.dest = config['convert']['dest'].get() @@ -276,7 +319,11 @@ def convert_func(lib, opts, args): return if opts.album: - items = (i for a in lib.albums(ui.decargs(args)) for i in a.items()) + albums = lib.albums(ui.decargs(args)) + items = (i for a in albums for i in a.items()) + if config['convert']['copy_album_art']: + for album in albums: + copy_album_art(album, opts.dest, path_formats, pretend) else: items = iter(lib.items(ui.decargs(args))) convert = [convert_item(opts.dest, @@ -322,6 +369,7 @@ class ConvertPlugin(BeetsPlugin): u'embed': True, u'paths': {}, u'never_convert_lossy_files': False, + u'copy_album_art': False }) self.import_stages = [self.auto_convert] From ad9786ce81789289130cfcee626e323e69f9151c Mon Sep 17 00:00:00 2001 From: Angel Alonso Date: Sun, 2 Nov 2014 10:58:46 +0100 Subject: [PATCH 2/3] convert: update documentation and add a trailing comma. --- beetsplug/convert.py | 2 +- docs/plugins/convert.rst | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/beetsplug/convert.py b/beetsplug/convert.py index 25ea695a4..480295fd3 100644 --- a/beetsplug/convert.py +++ b/beetsplug/convert.py @@ -369,7 +369,7 @@ class ConvertPlugin(BeetsPlugin): u'embed': True, u'paths': {}, u'never_convert_lossy_files': False, - u'copy_album_art': False + u'copy_album_art': False, }) self.import_stages = [self.auto_convert] diff --git a/docs/plugins/convert.rst b/docs/plugins/convert.rst index 81b9af7da..88a2d159c 100644 --- a/docs/plugins/convert.rst +++ b/docs/plugins/convert.rst @@ -79,6 +79,8 @@ file. The available options are: - ``threads``: The number of threads to use for parallel encoding. By default, the plugin will detect the number of processors available and use them all. +- ``copy_album_art``: Copy album art when copying or transcoding albums matched + using the ``-a`` option. Default: ``no``. You can also configure the format to use for transcoding. From d45b213bad58d09cc1a242b2128c5cc97784e239 Mon Sep 17 00:00:00 2001 From: Adrian Sampson Date: Sun, 2 Nov 2014 09:58:59 -0800 Subject: [PATCH 3/3] Changelog for #1055, fix #1050 --- docs/changelog.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/changelog.rst b/docs/changelog.rst index 246c1313c..92f8757e4 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -73,6 +73,8 @@ Fixes: * The output of the :ref:`stats-cmd` command is slightly different: the approximate size is now marked as such, and the total number of seconds only appears in exact mode. +* :doc:`/plugins/convert`: A new ``copy_album_art`` option puts images + alongside converted files. Thanks to Ángel Alonso. :bug:`1050`, :bug:`1055` 1.3.8 (September 17, 2014)