mirror of
https://github.com/beetbox/beets.git
synced 2026-01-08 00:45:55 +01:00
Merge branch 'fetchart-459' of git://github.com/KraYmer/beets
Conflicts: docs/plugins/fetchart.rst
This commit is contained in:
commit
a416e9b768
3 changed files with 33 additions and 21 deletions
|
|
@ -110,8 +110,7 @@ def aao_art(asin):
|
|||
|
||||
|
||||
# Art from the filesystem.
|
||||
|
||||
def art_in_path(path):
|
||||
def art_in_path(path, cover_names=COVER_NAMES):
|
||||
"""Look for album art files in a specified directory."""
|
||||
if not os.path.isdir(path):
|
||||
return
|
||||
|
|
@ -124,16 +123,17 @@ def art_in_path(path):
|
|||
images.append(fn)
|
||||
|
||||
# Look for "preferred" filenames.
|
||||
cover_pat = r"(\b|_)(%s)(\b|_)" % '|'.join(cover_names)
|
||||
for fn in images:
|
||||
for name in COVER_NAMES:
|
||||
if fn.lower().startswith(name):
|
||||
log.debug(u'fetchart: using well-named art file {0}'.format(
|
||||
util.displayable_path(fn)
|
||||
))
|
||||
return os.path.join(path, fn)
|
||||
if re.search(cover_pat, os.path.splitext(fn)[0], re.I):
|
||||
log.debug(u'fetchart: using well-named art file {0}'.format(
|
||||
util.displayable_path(fn)
|
||||
))
|
||||
return os.path.join(path, fn)
|
||||
|
||||
# Fall back to any image in the folder.
|
||||
if images:
|
||||
cautious = config['fetchart']['cautious'].get(bool)
|
||||
if not cautious and images:
|
||||
log.debug(u'fetchart: using fallback art file {0}'.format(
|
||||
util.displayable_path(images[0])
|
||||
))
|
||||
|
|
@ -172,9 +172,10 @@ def art_for_album(album, paths, maxwidth=None, local_only=False):
|
|||
out = None
|
||||
|
||||
# Local art.
|
||||
cover_names = config['fetchart']['cover_names'].as_str_seq()
|
||||
if paths:
|
||||
for path in paths:
|
||||
out = art_in_path(path)
|
||||
out = art_in_path(path, cover_names)
|
||||
if out:
|
||||
break
|
||||
|
||||
|
|
@ -221,6 +222,8 @@ class FetchArtPlugin(BeetsPlugin):
|
|||
'auto': True,
|
||||
'maxwidth': 0,
|
||||
'remote_priority': False,
|
||||
'cautious': True,
|
||||
'cover_names': COVER_NAMES
|
||||
})
|
||||
|
||||
# Holds paths to downloaded images between fetching them and
|
||||
|
|
|
|||
|
|
@ -67,10 +67,18 @@ Currently, this plugin searches for art in the local filesystem as well as on
|
|||
the Cover Art Archive, Amazon, and AlbumArt.org (in that order).
|
||||
|
||||
When looking for local album art, beets checks for image files located in the
|
||||
same folder as the music files you're importing. beets prefers to use an image
|
||||
file named "cover," "front," "art," "album," or "folder," but in the absence of
|
||||
those well-known names it will use any image file in the same folder as your
|
||||
music files.
|
||||
same folder as the music files you're importing. Beets prefers to use an image
|
||||
file whose name contains "cover", "front", "art", "album" or "folder", but in
|
||||
the absence of well-known names, it will use any image file in the same folder
|
||||
as your music files.
|
||||
|
||||
You can change the list of filename keywords using the ``server_names`` config
|
||||
option. Or, to use *only* filenames containing the keywords and not fall back
|
||||
to any image, set ``cautious`` to true. For example::
|
||||
|
||||
fetchart:
|
||||
cautious: false
|
||||
cover_names: front back
|
||||
|
||||
By default, remote (Web) art sources are only queried if no local art is found
|
||||
in the filesystem. To query remote sources every time, set the
|
||||
|
|
|
|||
|
|
@ -54,12 +54,13 @@ class FSArtTest(_common.TestCase):
|
|||
def setUp(self):
|
||||
super(FSArtTest, self).setUp()
|
||||
self.dpath = os.path.join(self.temp_dir, 'arttest')
|
||||
fetchart.FetchArtPlugin()
|
||||
os.mkdir(self.dpath)
|
||||
|
||||
def test_finds_jpg_in_directory(self):
|
||||
_common.touch(os.path.join(self.dpath, 'a.jpg'))
|
||||
_common.touch(os.path.join(self.dpath, 'art.jpg'))
|
||||
fn = fetchart.art_in_path(self.dpath)
|
||||
self.assertEqual(fn, os.path.join(self.dpath, 'a.jpg'))
|
||||
self.assertEqual(fn, os.path.join(self.dpath, 'art.jpg'))
|
||||
|
||||
def test_appropriately_named_file_takes_precedence(self):
|
||||
_common.touch(os.path.join(self.dpath, 'a.jpg'))
|
||||
|
|
@ -107,11 +108,11 @@ class CombinedTest(_common.TestCase):
|
|||
self.assertEqual(artpath, None)
|
||||
|
||||
def test_main_interface_gives_precedence_to_fs_art(self):
|
||||
_common.touch(os.path.join(self.dpath, 'a.jpg'))
|
||||
_common.touch(os.path.join(self.dpath, 'art.jpg'))
|
||||
fetchart.urllib.urlretrieve = MockUrlRetrieve('image/jpeg')
|
||||
album = _common.Bag(asin='xxxx')
|
||||
artpath = fetchart.art_for_album(album, [self.dpath])
|
||||
self.assertEqual(artpath, os.path.join(self.dpath, 'a.jpg'))
|
||||
self.assertEqual(artpath, os.path.join(self.dpath, 'art.jpg'))
|
||||
|
||||
def test_main_interface_falls_back_to_amazon(self):
|
||||
fetchart.urllib.urlretrieve = MockUrlRetrieve('image/jpeg')
|
||||
|
|
@ -150,12 +151,12 @@ class CombinedTest(_common.TestCase):
|
|||
self.assertFalse(mock_retrieve.fetched)
|
||||
|
||||
def test_local_only_gets_fs_image(self):
|
||||
_common.touch(os.path.join(self.dpath, 'a.jpg'))
|
||||
_common.touch(os.path.join(self.dpath, 'art.jpg'))
|
||||
mock_retrieve = MockUrlRetrieve('image/jpeg')
|
||||
fetchart.urllib.urlretrieve = mock_retrieve
|
||||
album = _common.Bag(mb_albumid='releaseid', asin='xxxx')
|
||||
artpath = fetchart.art_for_album(album, [self.dpath], local_only=True)
|
||||
self.assertEqual(artpath, os.path.join(self.dpath, 'a.jpg'))
|
||||
artpath = fetchart.art_for_album(album, [self.dpath], None, local_only=True)
|
||||
self.assertEqual(artpath, os.path.join(self.dpath, 'art.jpg'))
|
||||
self.assertFalse(self.urlopen_called)
|
||||
self.assertFalse(mock_retrieve.fetched)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue