mirror of
https://github.com/beetbox/beets.git
synced 2025-12-06 08:39:17 +01:00
Removed unicode_literals from plugins
* fetchart * freedesktop * fromfilename * ftintitle
This commit is contained in:
parent
53d2c8d9db
commit
7d00ab3b50
4 changed files with 39 additions and 43 deletions
|
|
@ -15,8 +15,7 @@
|
||||||
|
|
||||||
"""Fetches album art.
|
"""Fetches album art.
|
||||||
"""
|
"""
|
||||||
from __future__ import (division, absolute_import, print_function,
|
from __future__ import (division, absolute_import, print_function)
|
||||||
unicode_literals)
|
|
||||||
|
|
||||||
from contextlib import closing
|
from contextlib import closing
|
||||||
import os
|
import os
|
||||||
|
|
@ -206,14 +205,14 @@ class ITunesStore(ArtSource):
|
||||||
try:
|
try:
|
||||||
results = itunes.search_album(search_string)
|
results = itunes.search_album(search_string)
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
self._log.debug('iTunes search failed: {0}', exc)
|
self._log.debug(u'iTunes search failed: {0}', exc)
|
||||||
return
|
return
|
||||||
|
|
||||||
# Get the first match.
|
# Get the first match.
|
||||||
if results:
|
if results:
|
||||||
itunes_album = results[0]
|
itunes_album = results[0]
|
||||||
else:
|
else:
|
||||||
self._log.debug('iTunes search for {:r} got no results',
|
self._log.debug(u'iTunes search for {:r} got no results',
|
||||||
search_string)
|
search_string)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
@ -276,9 +275,9 @@ class Wikipedia(ArtSource):
|
||||||
cover_filename = 'File:' + results[0]['coverFilename']['value']
|
cover_filename = 'File:' + results[0]['coverFilename']['value']
|
||||||
page_id = results[0]['pageId']['value']
|
page_id = results[0]['pageId']['value']
|
||||||
else:
|
else:
|
||||||
self._log.debug('wikipedia: album not found on dbpedia')
|
self._log.debug(u'wikipedia: album not found on dbpedia')
|
||||||
except (ValueError, KeyError, IndexError):
|
except (ValueError, KeyError, IndexError):
|
||||||
self._log.debug('wikipedia: error scraping dbpedia response: {}',
|
self._log.debug(u'wikipedia: error scraping dbpedia response: {}',
|
||||||
dbpedia_response.text)
|
dbpedia_response.text)
|
||||||
|
|
||||||
# Ensure we have a filename before attempting to query wikipedia
|
# Ensure we have a filename before attempting to query wikipedia
|
||||||
|
|
@ -293,8 +292,7 @@ class Wikipedia(ArtSource):
|
||||||
if ' .' in cover_filename and \
|
if ' .' in cover_filename and \
|
||||||
'.' not in cover_filename.split(' .')[-1]:
|
'.' not in cover_filename.split(' .')[-1]:
|
||||||
self._log.debug(
|
self._log.debug(
|
||||||
'wikipedia: dbpedia provided incomplete cover_filename'
|
u'wikipedia: dbpedia provided incomplete cover_filename')
|
||||||
)
|
|
||||||
lpart, rpart = cover_filename.rsplit(' .', 1)
|
lpart, rpart = cover_filename.rsplit(' .', 1)
|
||||||
|
|
||||||
# Query all the images in the page
|
# Query all the images in the page
|
||||||
|
|
@ -322,8 +320,7 @@ class Wikipedia(ArtSource):
|
||||||
break
|
break
|
||||||
except (ValueError, KeyError):
|
except (ValueError, KeyError):
|
||||||
self._log.debug(
|
self._log.debug(
|
||||||
'wikipedia: failed to retrieve a cover_filename'
|
u'wikipedia: failed to retrieve a cover_filename')
|
||||||
)
|
|
||||||
return
|
return
|
||||||
|
|
||||||
# Find the absolute url of the cover art on Wikipedia
|
# Find the absolute url of the cover art on Wikipedia
|
||||||
|
|
@ -347,7 +344,7 @@ class Wikipedia(ArtSource):
|
||||||
image_url = result['imageinfo'][0]['url']
|
image_url = result['imageinfo'][0]['url']
|
||||||
yield image_url
|
yield image_url
|
||||||
except (ValueError, KeyError, IndexError):
|
except (ValueError, KeyError, IndexError):
|
||||||
self._log.debug('wikipedia: error scraping imageinfo')
|
self._log.debug(u'wikipedia: error scraping imageinfo')
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -493,9 +490,10 @@ class FetchArtPlugin(plugins.BeetsPlugin, RequestMixin):
|
||||||
# Manual album art fetching.
|
# Manual album art fetching.
|
||||||
def commands(self):
|
def commands(self):
|
||||||
cmd = ui.Subcommand('fetchart', help='download album art')
|
cmd = ui.Subcommand('fetchart', help='download album art')
|
||||||
cmd.parser.add_option('-f', '--force', dest='force',
|
cmd.parser.add_option(
|
||||||
action='store_true', default=False,
|
u'-f', u'--force', dest='force',
|
||||||
help='re-download art when already present')
|
action='store_true', default=False,
|
||||||
|
help=u're-download art when already present')
|
||||||
|
|
||||||
def func(lib, opts, args):
|
def func(lib, opts, args):
|
||||||
self.batch_fetch_art(lib, lib.albums(ui.decargs(args)), opts.force)
|
self.batch_fetch_art(lib, lib.albums(ui.decargs(args)), opts.force)
|
||||||
|
|
@ -511,12 +509,12 @@ class FetchArtPlugin(plugins.BeetsPlugin, RequestMixin):
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
with closing(self.request(url, stream=True,
|
with closing(self.request(url, stream=True,
|
||||||
message='downloading image')) as resp:
|
message=u'downloading image')) as resp:
|
||||||
if 'Content-Type' not in resp.headers \
|
if 'Content-Type' not in resp.headers \
|
||||||
or resp.headers['Content-Type'] not in CONTENT_TYPES:
|
or resp.headers['Content-Type'] not in CONTENT_TYPES:
|
||||||
self._log.debug(
|
self._log.debug(
|
||||||
'not a supported image: {}',
|
u'not a supported image: {}',
|
||||||
resp.headers.get('Content-Type') or 'no content type',
|
resp.headers.get('Content-Type') or u'no content type',
|
||||||
)
|
)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
@ -532,7 +530,7 @@ class FetchArtPlugin(plugins.BeetsPlugin, RequestMixin):
|
||||||
except (IOError, requests.RequestException, TypeError) as exc:
|
except (IOError, requests.RequestException, TypeError) as exc:
|
||||||
# Handling TypeError works around a urllib3 bug:
|
# Handling TypeError works around a urllib3 bug:
|
||||||
# https://github.com/shazow/urllib3/issues/556
|
# https://github.com/shazow/urllib3/issues/556
|
||||||
self._log.debug('error fetching art: {}', exc)
|
self._log.debug(u'error fetching art: {}', exc)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def _is_valid_image_candidate(self, candidate):
|
def _is_valid_image_candidate(self, candidate):
|
||||||
|
|
@ -551,7 +549,7 @@ class FetchArtPlugin(plugins.BeetsPlugin, RequestMixin):
|
||||||
|
|
||||||
# get_size returns None if no local imaging backend is available
|
# get_size returns None if no local imaging backend is available
|
||||||
size = ArtResizer.shared.get_size(candidate)
|
size = ArtResizer.shared.get_size(candidate)
|
||||||
self._log.debug('image size: {}', size)
|
self._log.debug(u'image size: {}', size)
|
||||||
|
|
||||||
if not size:
|
if not size:
|
||||||
self._log.warning(u'Could not get size of image (please see '
|
self._log.warning(u'Could not get size of image (please see '
|
||||||
|
|
@ -562,19 +560,19 @@ class FetchArtPlugin(plugins.BeetsPlugin, RequestMixin):
|
||||||
|
|
||||||
# Check minimum size.
|
# Check minimum size.
|
||||||
if self.minwidth and size[0] < self.minwidth:
|
if self.minwidth and size[0] < self.minwidth:
|
||||||
self._log.debug('image too small ({} < {})',
|
self._log.debug(u'image too small ({} < {})',
|
||||||
size[0], self.minwidth)
|
size[0], self.minwidth)
|
||||||
return CANDIDATE_BAD
|
return CANDIDATE_BAD
|
||||||
|
|
||||||
# Check aspect ratio.
|
# Check aspect ratio.
|
||||||
if self.enforce_ratio and size[0] != size[1]:
|
if self.enforce_ratio and size[0] != size[1]:
|
||||||
self._log.debug('image is not square ({} != {})',
|
self._log.debug(u'image is not square ({} != {})',
|
||||||
size[0], size[1])
|
size[0], size[1])
|
||||||
return CANDIDATE_BAD
|
return CANDIDATE_BAD
|
||||||
|
|
||||||
# Check maximum size.
|
# Check maximum size.
|
||||||
if self.maxwidth and size[0] > self.maxwidth:
|
if self.maxwidth and size[0] > self.maxwidth:
|
||||||
self._log.debug('image needs resizing ({} > {})',
|
self._log.debug(u'image needs resizing ({} > {})',
|
||||||
size[0], self.maxwidth)
|
size[0], self.maxwidth)
|
||||||
return CANDIDATE_DOWNSCALE
|
return CANDIDATE_DOWNSCALE
|
||||||
|
|
||||||
|
|
@ -600,7 +598,7 @@ class FetchArtPlugin(plugins.BeetsPlugin, RequestMixin):
|
||||||
check = self._is_valid_image_candidate(candidate)
|
check = self._is_valid_image_candidate(candidate)
|
||||||
if check:
|
if check:
|
||||||
out = candidate
|
out = candidate
|
||||||
self._log.debug('found local image {}', out)
|
self._log.debug(u'found local image {}', out)
|
||||||
break
|
break
|
||||||
|
|
||||||
# Web art sources.
|
# Web art sources.
|
||||||
|
|
@ -613,7 +611,7 @@ class FetchArtPlugin(plugins.BeetsPlugin, RequestMixin):
|
||||||
check = self._is_valid_image_candidate(candidate)
|
check = self._is_valid_image_candidate(candidate)
|
||||||
if check:
|
if check:
|
||||||
out = candidate
|
out = candidate
|
||||||
self._log.debug('using remote image {}', out)
|
self._log.debug(u'using remote image {}', out)
|
||||||
break
|
break
|
||||||
|
|
||||||
if self.maxwidth and out and check == CANDIDATE_DOWNSCALE:
|
if self.maxwidth and out and check == CANDIDATE_DOWNSCALE:
|
||||||
|
|
@ -627,7 +625,7 @@ class FetchArtPlugin(plugins.BeetsPlugin, RequestMixin):
|
||||||
"""
|
"""
|
||||||
for album in albums:
|
for album in albums:
|
||||||
if album.artpath and not force and os.path.isfile(album.artpath):
|
if album.artpath and not force and os.path.isfile(album.artpath):
|
||||||
message = ui.colorize('text_highlight_minor', 'has album art')
|
message = ui.colorize('text_highlight_minor', u'has album art')
|
||||||
else:
|
else:
|
||||||
# In ordinary invocations, look for images on the
|
# In ordinary invocations, look for images on the
|
||||||
# filesystem. When forcing, however, always go to the Web
|
# filesystem. When forcing, however, always go to the Web
|
||||||
|
|
@ -638,9 +636,9 @@ class FetchArtPlugin(plugins.BeetsPlugin, RequestMixin):
|
||||||
if path:
|
if path:
|
||||||
album.set_art(path, False)
|
album.set_art(path, False)
|
||||||
album.store()
|
album.store()
|
||||||
message = ui.colorize('text_success', 'found album art')
|
message = ui.colorize('text_success', u'found album art')
|
||||||
else:
|
else:
|
||||||
message = ui.colorize('text_error', 'no art found')
|
message = ui.colorize('text_error', u'no art found')
|
||||||
|
|
||||||
self._log.info(u'{0}: {1}', album, message)
|
self._log.info(u'{0}: {1}', album, message)
|
||||||
|
|
||||||
|
|
@ -654,7 +652,7 @@ class FetchArtPlugin(plugins.BeetsPlugin, RequestMixin):
|
||||||
source_names = {v: k for k, v in ART_SOURCES.items()}
|
source_names = {v: k for k, v in ART_SOURCES.items()}
|
||||||
for source in self.sources:
|
for source in self.sources:
|
||||||
self._log.debug(
|
self._log.debug(
|
||||||
'trying source {0} for album {1.albumartist} - {1.album}',
|
u'trying source {0} for album {1.albumartist} - {1.album}',
|
||||||
source_names[type(source)],
|
source_names[type(source)],
|
||||||
album,
|
album,
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -16,8 +16,7 @@
|
||||||
"""Creates freedesktop.org-compliant .directory files on an album level.
|
"""Creates freedesktop.org-compliant .directory files on an album level.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from __future__ import (division, absolute_import, print_function,
|
from __future__ import (division, absolute_import, print_function)
|
||||||
unicode_literals)
|
|
||||||
|
|
||||||
from beets.plugins import BeetsPlugin
|
from beets.plugins import BeetsPlugin
|
||||||
from beets import ui
|
from beets import ui
|
||||||
|
|
@ -25,13 +24,14 @@ from beets import ui
|
||||||
|
|
||||||
class FreedesktopPlugin(BeetsPlugin):
|
class FreedesktopPlugin(BeetsPlugin):
|
||||||
def commands(self):
|
def commands(self):
|
||||||
deprecated = ui.Subcommand("freedesktop", help="Print a message to "
|
deprecated = ui.Subcommand(
|
||||||
"redirect to thumbnails --dolphin")
|
"freedesktop",
|
||||||
|
help=u"Print a message to redirect to thumbnails --dolphin")
|
||||||
deprecated.func = self.deprecation_message
|
deprecated.func = self.deprecation_message
|
||||||
return [deprecated]
|
return [deprecated]
|
||||||
|
|
||||||
def deprecation_message(self, lib, opts, args):
|
def deprecation_message(self, lib, opts, args):
|
||||||
ui.print_("This plugin is deprecated. Its functionality is superseded "
|
ui.print_(u"This plugin is deprecated. Its functionality is "
|
||||||
"by the 'thumbnails' plugin")
|
u"superseded by the 'thumbnails' plugin")
|
||||||
ui.print_("'thumbnails --dolphin' replaces freedesktop. See doc & "
|
ui.print_(u"'thumbnails --dolphin' replaces freedesktop. See doc & "
|
||||||
"changelog for more information")
|
u"changelog for more information")
|
||||||
|
|
|
||||||
|
|
@ -16,8 +16,7 @@
|
||||||
"""If the title is empty, try to extract track and title from the
|
"""If the title is empty, try to extract track and title from the
|
||||||
filename.
|
filename.
|
||||||
"""
|
"""
|
||||||
from __future__ import (division, absolute_import, print_function,
|
from __future__ import (division, absolute_import, print_function)
|
||||||
unicode_literals)
|
|
||||||
|
|
||||||
from beets import plugins
|
from beets import plugins
|
||||||
from beets.util import displayable_path
|
from beets.util import displayable_path
|
||||||
|
|
|
||||||
|
|
@ -15,8 +15,7 @@
|
||||||
|
|
||||||
"""Moves "featured" artists to the title from the artist field.
|
"""Moves "featured" artists to the title from the artist field.
|
||||||
"""
|
"""
|
||||||
from __future__ import (division, absolute_import, print_function,
|
from __future__ import (division, absolute_import, print_function)
|
||||||
unicode_literals)
|
|
||||||
|
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
|
@ -87,12 +86,12 @@ class FtInTitlePlugin(plugins.BeetsPlugin):
|
||||||
|
|
||||||
self._command = ui.Subcommand(
|
self._command = ui.Subcommand(
|
||||||
'ftintitle',
|
'ftintitle',
|
||||||
help='move featured artists to the title field')
|
help=u'move featured artists to the title field')
|
||||||
|
|
||||||
self._command.parser.add_option(
|
self._command.parser.add_option(
|
||||||
'-d', '--drop', dest='drop',
|
u'-d', u'--drop', dest='drop',
|
||||||
action='store_true', default=False,
|
action='store_true', default=False,
|
||||||
help='drop featuring from artists and ignore title update')
|
help=u'drop featuring from artists and ignore title update')
|
||||||
|
|
||||||
if self.config['auto']:
|
if self.config['auto']:
|
||||||
self.import_stages = [self.imported]
|
self.import_stages = [self.imported]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue