Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_flex_field_type(self):
class RatingPlugin(plugins.BeetsPlugin):
item_types = {'rating': types.Float()}
self.register_plugin(RatingPlugin)
self.config['plugins'] = 'rating'
item = Item(path=u'apath', artist=u'aaa')
item.add(self.lib)
# Do not match unset values
out = self.run_with_output(u'ls', u'rating:1..3')
self.assertNotIn(u'aaa', out)
self.run_command(u'modify', u'rating=2', u'--yes')
# Match in range
out = self.run_with_output(u'ls', u'rating:1..3')
def test_extended_field_write(self):
plugin = BeetsPlugin()
plugin.add_media_field('customtag', field_extension)
try:
mf = self._mediafile_fixture('empty')
mf.customtag = u'F#'
mf.save()
mf = mediafile.MediaFile(mf.path)
self.assertEqual(mf.customtag, u'F#')
finally:
delattr(mediafile.MediaFile, 'customtag')
Item._media_fields.remove('customtag')
Attributes:
checker: Checker command name.
path: Path to the file being validated.
errno: Error number from the checker execution error.
msg: Message from the checker execution error.
"""
def __init__(self, cmd, oserror):
self.checker = cmd[0]
self.path = cmd[-1]
self.errno = oserror.errno
self.msg = str(oserror)
class BadFiles(BeetsPlugin):
def run_command(self, cmd):
self._log.debug(u"running command: {}",
displayable_path(list2cmdline(cmd)))
try:
output = check_output(cmd, stderr=STDOUT)
errors = 0
status = 0
except CalledProcessError as e:
output = e.output
errors = 1
status = e.returncode
except OSError as e:
raise CheckerCommandException(cmd, e)
output = output.decode(sys.getfilesystemencoding())
return status, errors, [line for line in output.split("\n") if line]
"""Adds support for ipfs. Requires go-ipfs and a running ipfs daemon
"""
from __future__ import division, absolute_import, print_function
from beets import ui, util, library, config
from beets.plugins import BeetsPlugin
import subprocess
import shutil
import os
import tempfile
class IPFSPlugin(BeetsPlugin):
def __init__(self):
super(IPFSPlugin, self).__init__()
self.config.add({
'auto': True,
'nocopy': False,
})
if self.config['auto']:
self.import_stages = [self.auto_add]
def commands(self):
cmd = ui.Subcommand('ipfs',
help='interact with ipfs')
cmd.parser.add_option('-a', '--add', dest='add',
action='store_true',
raise ui.UserError(u'MusicBrainz credentials missing')
def submit_albums(collection_id, release_ids):
"""Add all of the release IDs to the indicated collection. Multiple
requests are made if there are many release IDs to submit.
"""
for i in range(0, len(release_ids), SUBMISSION_CHUNK_SIZE):
chunk = release_ids[i:i + SUBMISSION_CHUNK_SIZE]
mb_call(
musicbrainzngs.add_releases_to_collection,
collection_id, chunk
)
class MusicBrainzCollectionPlugin(BeetsPlugin):
def __init__(self):
super(MusicBrainzCollectionPlugin, self).__init__()
config['musicbrainz']['pass'].redact = True
musicbrainzngs.auth(
config['musicbrainz']['user'].get(unicode),
config['musicbrainz']['pass'].get(unicode),
)
self.config.add({'auto': False})
if self.config['auto']:
self.import_stages = [self.imported]
def commands(self):
mbupdate = Subcommand('mbupdate',
help=u'Update MusicBrainz collection')
mbupdate.func = self.update_collection
return [mbupdate]
# included in all copies or substantial portions of the Software.
from __future__ import division, absolute_import, print_function
import pylast
from pylast import TopItem, _extract, _number
from beets import ui
from beets import dbcore
from beets import config
from beets import plugins
from beets.dbcore import types
API_URL = 'http://ws.audioscrobbler.com/2.0/'
class LastImportPlugin(plugins.BeetsPlugin):
def __init__(self):
super(LastImportPlugin, self).__init__()
config['lastfm'].add({
'user': '',
'api_key': plugins.LASTFM_KEY,
})
config['lastfm']['api_key'].redact = True
self.config.add({
'per_page': 500,
'retry_limit': 3,
})
self.item_types = {
'play_count': types.INTEGER,
}
def commands(self):
def apply_item_changes(lib, item, move, pretend, write):
"""Store, move and write the item according to the arguments.
"""
if not pretend:
# Move the item if it's in the library.
if move and lib.directory in util.ancestry(item.path):
item.move(with_album=False)
if write:
item.try_write()
item.store()
class MBSyncPlugin(BeetsPlugin):
def __init__(self):
super(MBSyncPlugin, self).__init__()
def commands(self):
cmd = ui.Subcommand('mbsync',
help=u'update metadata from musicbrainz')
cmd.parser.add_option(
u'-p', u'--pretend', action='store_true',
help=u'show all changes but do nothing')
cmd.parser.add_option(
u'-m', u'--move', action='store_true', dest='move',
help=u"move files in the library directory")
cmd.parser.add_option(
u'-M', u'--nomove', action='store_false', dest='move',
help=u"don't move files in library")
cmd.parser.add_option(
"""Adds Deezer release and track search support to the autotagger
"""
from __future__ import absolute_import, print_function, division
import collections
import six
import unidecode
import requests
from beets import ui
from beets.autotag import AlbumInfo, TrackInfo
from beets.plugins import MetadataSourcePlugin, BeetsPlugin
class DeezerPlugin(MetadataSourcePlugin, BeetsPlugin):
data_source = 'Deezer'
# Base URLs for the Deezer API
# Documentation: https://developers.deezer.com/api/
search_url = 'https://api.deezer.com/search/'
album_url = 'https://api.deezer.com/album/'
track_url = 'https://api.deezer.com/track/'
id_regex = {
'pattern': r'(^|deezer\.com/)([a-z]*/)?({}/)?(\d+)',
'match_group': 4,
}
def __init__(self):
super(DeezerPlugin, self).__init__()
SOURCES_ALL = [u'coverart', u'itunes', u'amazon', u'albumart', u'google',
u'wikipedia']
ART_SOURCES = {
u'coverart': CoverArtArchive,
u'itunes': ITunesStore,
u'albumart': AlbumArtOrg,
u'amazon': Amazon,
u'google': GoogleImages,
u'wikipedia': Wikipedia,
}
# PLUGIN LOGIC ###############################################################
class FetchArtPlugin(plugins.BeetsPlugin, RequestMixin):
def __init__(self):
super(FetchArtPlugin, self).__init__()
self.config.add({
'auto': True,
'minwidth': 0,
'maxwidth': 0,
'enforce_ratio': False,
'remote_priority': False,
'cautious': False,
'cover_names': ['cover', 'front', 'art', 'album', 'folder'],
'sources': ['coverart', 'itunes', 'amazon', 'albumart'],
})
# Holds paths to downloaded images between fetching them and
# placing them in the filesystem.
self._stop_sync()
gpod.itdb_write(self.db._itdb, None)
def load(self, item, load_id=None):
raise NotImplementedError
def store(self, item, store_id=None, store_all=False):
raise NotImplementedError
def remove(self, item):
raise NotImplementedError
# Plugin hook.
class DevicePlugin(BeetsPlugin):
def commands(self):
cmd = beets.ui.Subcommand('dadd', help='add files to a device')
def func(lib, config, opts, args):
if not args:
raise beets.ui.UserError('no device name specified')
name = args.pop(0)
items = lib.items(query=beets.ui.make_query(args))
pod = PodLibrary.by_name(name)
for item in items:
pod.add(item)
pod.save()
cmd.func = func
return [cmd]