aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWolfgang Müller2024-09-16 19:58:21 +0200
committerWolfgang Müller2024-09-16 20:48:58 +0200
commitbf3cece9b9de955c1df15bc1335dd96cd36a48c3 (patch)
tree10e24e79c954fa6f46cfd7f3c2bb780698d346f7
parent7d23c72319812790cd8d44d60d7e1acf653bb74e (diff)
downloadbeets-oriole-bf3cece9b9de955c1df15bc1335dd96cd36a48c3.tar.gz
lint: Format code with Black
-rw-r--r--beetsplug/__init__.py1
-rw-r--r--beetsplug/browse.py68
-rw-r--r--beetsplug/extras.py12
-rw-r--r--setup.py6
4 files changed, 57 insertions, 30 deletions
diff --git a/beetsplug/__init__.py b/beetsplug/__init__.py
index 3ad9513..b36383a 100644
--- a/beetsplug/__init__.py
+++ b/beetsplug/__init__.py
@@ -1,2 +1,3 @@
from pkgutil import extend_path
+
__path__ = extend_path(__path__, __name__)
diff --git a/beetsplug/browse.py b/beetsplug/browse.py
index 72999b9..bb06a91 100644
--- a/beetsplug/browse.py
+++ b/beetsplug/browse.py
@@ -5,8 +5,17 @@ import webbrowser
from beets.plugins import BeetsPlugin
from beets.ui import Subcommand, UserError
-MUSICBRAINZ_LOOKUP='https://musicbrainz.org/otherlookup/mbid?other-lookup.mbid='
-FIELD_NAMES = ['albumartist', 'album', 'artist', 'releasegroup', 'releasetrack', 'track', 'work']
+MUSICBRAINZ_LOOKUP = "https://musicbrainz.org/otherlookup/mbid?other-lookup.mbid="
+FIELD_NAMES = [
+ "albumartist",
+ "album",
+ "artist",
+ "releasegroup",
+ "releasetrack",
+ "track",
+ "work",
+]
+
class BrowsePlugin(BeetsPlugin):
@@ -16,29 +25,42 @@ class BrowsePlugin(BeetsPlugin):
def commands(self):
return [BrowseCommand(self.config)]
+
class BrowseCommand(Subcommand):
- explorer = 'thunar'
+ explorer = "thunar"
def __init__(self, config):
- super().__init__('browse', parser=None,
- help='browse items on MusicBrainz or the file system')
-
- self.parser.add_option('-f', '--field', type='string',
- help='which field to look up on MusicBrainz, '
- 'e.g. album, artist, track, work, ...')
- self.parser.add_option('-o', '--open', action='store_true',
- help='open in the file browser instead of MusicBrainz')
+ super().__init__(
+ "browse",
+ parser=None,
+ help="browse items on MusicBrainz or the file system",
+ )
+
+ self.parser.add_option(
+ "-f",
+ "--field",
+ type="string",
+ help="which field to look up on MusicBrainz, "
+ "e.g. album, artist, track, work, ...",
+ )
+
+ self.parser.add_option(
+ "-o",
+ "--open",
+ action="store_true",
+ help="open in the file browser instead of MusicBrainz",
+ )
+
self.parser.add_album_option()
- if 'explorer' in config:
- self.explorer = config['explorer'].get()
+ if "explorer" in config:
+ self.explorer = config["explorer"].get()
- # pylint: disable=no-self-use
def browse_musicbrainz(self, item, field):
- mbid = item.get(f'mb_{field}id')
+ mbid = item.get(f"mb_{field}id")
if not mbid:
- raise UserError(f'\'mb_{field}id\' not available for: {item}')
+ raise UserError(f"'mb_{field}id' not available for: {item}")
try:
uuid.UUID(mbid)
@@ -49,20 +71,22 @@ class BrowseCommand(Subcommand):
def browse_filesystem(self, item, _):
try:
- subprocess.Popen(self.explorer.split(' ') + [item.get('path')]) # pylint: disable=consider-using-with
+ subprocess.Popen(self.explorer.split(" ") + [item.get("path")])
except OSError as err:
raise UserError(err) from err
def func(self, lib, opts, args):
queryfun = lib.albums if opts.album else lib.items
browsefun = self.browse_filesystem if opts.open else self.browse_musicbrainz
- field = opts.field or ('album' if opts.album else 'track')
+ field = opts.field or ("album" if opts.album else "track")
if field not in FIELD_NAMES:
- raise UserError(f'invalid field "{field}", try one of: {", ".join(FIELD_NAMES)}')
+ raise UserError(
+ f'invalid field "{field}", try one of: {", ".join(FIELD_NAMES)}',
+ )
if not args:
- raise UserError('empty query, refusing')
+ raise UserError("empty query, refusing")
items = queryfun(args)
@@ -73,10 +97,10 @@ class BrowseCommand(Subcommand):
browsefun(items[0], field)
return
- print('Query returned multiple matches, please disambiguate:')
+ print("Query returned multiple matches, please disambiguate:")
for index, item in enumerate(items):
if index < 5:
print(item)
else:
- print(f'[{len(items) - index} more]')
+ print(f"[{len(items) - index} more]")
return
diff --git a/beetsplug/extras.py b/beetsplug/extras.py
index 8227064..ea394b6 100644
--- a/beetsplug/extras.py
+++ b/beetsplug/extras.py
@@ -1,22 +1,24 @@
import os
import shutil
+
import beets.plugins
+
class ExtrasPlugin(beets.plugins.BeetsPlugin):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
- self.register_listener('item_moved', self.on_item_moved)
- self.register_listener('item_copied', self.on_item_copied)
+ self.register_listener("item_moved", self.on_item_moved)
+ self.register_listener("item_copied", self.on_item_copied)
def on_item_moved(self, item, source, destination):
- for (sourcepath, destpath) in self.gather(source, destination):
+ for sourcepath, destpath in self.gather(source, destination):
# need to decode to str here as shutil.move (still) breaks on bytes
# arguments because of _destinsrc using str.endswith
shutil.move(sourcepath.decode(), destpath.decode())
def on_item_copied(self, item, source, destination):
- for (sourcepath, destpath) in self.gather(source, destination):
+ for sourcepath, destpath in self.gather(source, destination):
if os.path.isdir(sourcepath):
shutil.copytree(sourcepath, destpath)
else:
@@ -30,7 +32,7 @@ class ExtrasPlugin(beets.plugins.BeetsPlugin):
if sourcedir == destdir:
return []
- paths = [beets.util.bytestring_path(p) for p in self.config['paths'].get()]
+ paths = [beets.util.bytestring_path(p) for p in self.config["paths"].get()]
for path in paths:
sourcepath = os.path.join(sourcedir, path)
diff --git a/setup.py b/setup.py
index 024145e..69a4a3b 100644
--- a/setup.py
+++ b/setup.py
@@ -11,10 +11,10 @@ setuptools.setup(
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
],
- packages=['beetsplug'],
+ packages=["beetsplug"],
python_requires=">=3.8",
install_requires = [
- 'beets>=1.6.0',
- ]
+ "beets>=1.6.0",
+ ],
)