Example #1
0
 def __init__(self):
     super().__init__()
     musicbrainzngs.set_rate_limit()
     musicbrainzngs.set_useragent(BRAINZ_APP, VERSION,
                                  "*****@*****.**")
     musicbrainzngs.auth(plugin_config.get("username"),
                         plugin_config.get("password"))
Example #2
0
    def configure_musicbrainz(self) -> None:
        """
        Configure the MusicBrainz library global settings using the values
        from this RipperConfig instance.
        """
        interval = 1.0 / self.musicbrainz_rate_limit
        log.info("Setting MusicBrainz ratelimit to interval=%g calls=1",
                 interval)
        mb.set_rate_limit(interval, 1)

        m = USER_AGENT_RE.match(self.musicbrainz_user_agent)
        if not m:
            raise ValueError(
                f"Invalid useragent format: expected app/version "
                f"( email@ domain ): {repr(self.musicbrainz_user_agent)}")
        app = m.group("app")
        ver = m.group("ver")
        contact: Optional[str] = m.group("contact")
        contact = contact if contact else None

        log.info("Setting MusicBrainz user-agent to app=%r ver=%r contact=%r",
                 app, ver, contact)
        mb.set_useragent(app, ver, contact)

        if self.musicbrainz_username and self.musicbrainz_password:
            mb.auth(self.musicbrainz_username, self.musicbrainz_password)
Example #3
0
File: mb.py Project: jwyant/beets
def configure():
    """Set up the python-musicbrainz-ngs module according to settings
    from the beets configuration. This should be called at startup.
    """
    musicbrainzngs.set_hostname(config["musicbrainz"]["host"].get(unicode))
    musicbrainzngs.set_rate_limit(
        config["musicbrainz"]["ratelimit_interval"].as_number(), config["musicbrainz"]["ratelimit"].get(int)
    )
Example #4
0
    def __init__(self):
        log = logging.getLogger('util.importer.Importer.__init__')

        musicbrainzngs.set_useragent("NRG Processor", "0.01", "http://anorg.net/")
        musicbrainzngs.set_rate_limit(MUSICBRAINZ_RATE_LIMIT)
        
        if MUSICBRAINZ_HOST:
            musicbrainzngs.set_hostname(MUSICBRAINZ_HOST)
def musicbrainzngs_setup():
    musicbrainzngs.set_useragent(
        "AnChain",
        "0.1",
        "https://github.com/GiovanniGabbolini/",
    )
    # musicbrainzngs.set_hostname('192.168.1.4:5000')
    musicbrainzngs.set_rate_limit(limit_or_interval=False)
Example #6
0
def config():
    mb_host = os.getenv("MUSICBRAINZ_HOST", None)
    if not mb_host:
        mb_host = MB_HOST_MBDOTORG
    mb.set_useragent("python-metadb-musicbrainz-scrape", "0.1",
                     "https://github.com/MTG/metadb")
    mb.set_hostname(mb_host)
    if mb_host != MB_HOST_MBDOTORG:
        mb.set_rate_limit(False)
Example #7
0
    def __init__(self):
        log = logging.getLogger('util.importer.Importer.__init__')

        musicbrainzngs.set_useragent("NRG Processor", "0.01",
                                     "http://anorg.net/")
        musicbrainzngs.set_rate_limit(MUSICBRAINZ_RATE_LIMIT)

        if MUSICBRAINZ_HOST:
            musicbrainzngs.set_hostname(MUSICBRAINZ_HOST)
Example #8
0
def configure():
    """Set up the python-musicbrainz-ngs module according to settings
    from the beets configuration. This should be called at startup.
    """
    musicbrainzngs.set_hostname(config['musicbrainz']['host'].get(unicode))
    musicbrainzngs.set_rate_limit(
        config['musicbrainz']['ratelimit_interval'].as_number(),
        config['musicbrainz']['ratelimit'].get(int),
    )
Example #9
0
def turn_off_musicbrainz_rate_limiting_if_cassette_exists(cassette_name):
    # if cassettes exist, turn off rate limiting
    cassette = os.path.join(CASSETTE_LIBRARY_DIR, cassette_name)
    if os.path.exists(cassette):
        logger.info('Cassettes directory existsing, turning off rate-limiting')
        musicbrainzngs.set_rate_limit(False)
    else:
        musicbrainzngs.set_rate_limit()
        logger.warn("Couldn't find cassettes, going to hit real musicbrainz API")
Example #10
0
    def __init__(self):

        musicbrainzngs.set_useragent("NRG Processor", "0.01", "http://anorg.net/")
        musicbrainzngs.set_rate_limit(MUSICBRAINZ_RATE_LIMIT)

        self.file_metadata = None

        if MUSICBRAINZ_HOST:
            musicbrainzngs.set_hostname(MUSICBRAINZ_HOST)
Example #11
0
    def __init__(self):

        musicbrainzngs.set_useragent("NRG Processor", "0.01", "http://anorg.net/")
        musicbrainzngs.set_rate_limit(MUSICBRAINZ_RATE_LIMIT)
        
        self.pp = pprint.PrettyPrinter(indent=4)
        self.pp.pprint = lambda d: None
        
        if MUSICBRAINZ_HOST:
            musicbrainzngs.set_hostname(MUSICBRAINZ_HOST)
Example #12
0
def configure():
    """Set up the python-musicbrainz-ngs module according to settings
    from the beets configuration. This should be called at startup.
    """
    hostname = config['musicbrainz']['host'].as_str()
    musicbrainzngs.set_hostname(hostname)
    musicbrainzngs.set_rate_limit(
        config['musicbrainz']['ratelimit_interval'].as_number(),
        config['musicbrainz']['ratelimit'].get(int),
    )
Example #13
0
def turn_off_musicbrainz_rate_limiting_if_cassette_exists(cassette_name):
    # if cassettes exist, turn off rate limiting
    cassette = os.path.join(CASSETTE_LIBRARY_DIR, cassette_name)
    if os.path.exists(cassette):
        logger.info('Cassettes directory existsing, turning off rate-limiting')
        musicbrainzngs.set_rate_limit(False)
    else:
        musicbrainzngs.set_rate_limit()
        logger.warn(
            "Couldn't find cassettes, going to hit real musicbrainz API")
    def setUp(self):
        musicbrainzngs.set_rate_limit(3, 3)

        self.cop = Timecop()
        self.cop.install()

        @musicbrainz._rate_limit
        def limited():
            pass
        self.func = limited
    def setUp(self):
        musicbrainzngs.set_rate_limit(True, 3, 3)

        self.cop = Timecop()
        self.cop.install()

        @musicbrainz._rate_limit
        def limited():
            pass

        self.func = limited
Example #16
0
    def __init__(self):
        log = logging.getLogger('util.process.Process.__init__')

        musicbrainzngs.set_useragent("NRG Processor", "0.01", "http://anorg.net/")
        musicbrainzngs.set_rate_limit(MUSICBRAINZ_RATE_LIMIT)
        
        self.pp = pprint.PrettyPrinter(indent=4)
        self.pp.pprint = lambda d: None
        
        if MUSICBRAINZ_HOST:
            musicbrainzngs.set_hostname(MUSICBRAINZ_HOST)
Example #17
0
def startmb():

    mbuser = None
    mbpass = None

    if headphones.CONFIG.MIRROR == "musicbrainz.org":
        mbhost = "musicbrainz.org"
        mbport = 80
        sleepytime = 1
    elif headphones.CONFIG.MIRROR == "custom":
        mbhost = headphones.CONFIG.CUSTOMHOST
        mbport = int(headphones.CONFIG.CUSTOMPORT)
        mbuser = headphones.CONFIG.CUSTOMUSER
        mbpass = headphones.CONFIG.CUSTOMPASS
        sleepytime = int(headphones.CONFIG.CUSTOMSLEEP)
    elif headphones.CONFIG.MIRROR == "headphones":
        mbhost = "144.76.94.239"
        mbport = 8181
        mbuser = headphones.CONFIG.HPUSER
        mbpass = headphones.CONFIG.HPPASS
        sleepytime = 0
    else:
        return False

    musicbrainzngs.set_useragent("headphones", "0.0",
                                 "https://github.com/rembo10/headphones")
    musicbrainzngs.set_hostname(mbhost + ":" + str(mbport))

    # Their rate limiting should be redundant to our lock
    if sleepytime == 0:
        musicbrainzngs.set_rate_limit(False)
    else:
        #calling it with an it ends up blocking all requests after the first
        musicbrainzngs.set_rate_limit(limit_or_interval=float(sleepytime))
        mb_lock.minimum_delta = sleepytime

    # Add headphones credentials
    if headphones.CONFIG.MIRROR == "headphones" or headphones.CONFIG.CUSTOMAUTH:
        if not mbuser or not mbpass:
            logger.warn("No username or password set for MusicBrainz server")
        else:
            musicbrainzngs.hpauth(mbuser, mbpass)

    # Let us know if we disable custom authentication
    if not headphones.CONFIG.CUSTOMAUTH and headphones.CONFIG.MIRROR == "custom":
        musicbrainzngs.disable_hpauth()

    logger.debug(
        'Using the following server values: MBHost: %s, MBPort: %i, Sleep Interval: %i',
        mbhost, mbport, sleepytime)

    return True
    def test_invalid_args(self):
        """ Passing invalid arguments to set_rate_limit should throw
            an exception """
        try:
            musicbrainzngs.set_rate_limit(1, 0)
            self.fail("Required exception wasn't raised")
        except ValueError as e:
            self.assertTrue("new_requests" in str(e))

        try:
            musicbrainzngs.set_rate_limit(0, 1)
            self.fail("Required exception wasn't raised")
        except ValueError as e:
            self.assertTrue("limit_or_interval" in str(e))

        try:
            musicbrainzngs.set_rate_limit(1, -1)
            self.fail("Required exception wasn't raised")
        except ValueError as e:
            self.assertTrue("new_requests" in str(e))

        try:
            musicbrainzngs.set_rate_limit(0, -1)
            self.fail("Required exception wasn't raised")
        except ValueError as e:
            self.assertTrue("limit_or_interval" in str(e))
    def test_invalid_args(self):
        """ Passing invalid arguments to set_rate_limit should throw
            an exception """
        try:
            musicbrainzngs.set_rate_limit(True, 1, 0)
            self.fail("Required exception wasn't raised")
        except ValueError as e:
            self.assertTrue("new_requests" in str(e))

        try:
            musicbrainzngs.set_rate_limit(True, 0, 1)
            self.fail("Required exception wasn't raised")
        except ValueError as e:
            self.assertTrue("new_interval" in str(e))

        try:
            musicbrainzngs.set_rate_limit(True, 1, -1)
            self.fail("Required exception wasn't raised")
        except ValueError as e:
            self.assertTrue("new_requests" in str(e))

        try:
            musicbrainzngs.set_rate_limit(True, 0, -1)
            self.fail("Required exception wasn't raised")
        except ValueError as e:
            self.assertTrue("new_interval" in str(e))
Example #20
0
def startmb():
    mbuser = None
    mbpass = None

    if headphones.CONFIG.MIRROR == "musicbrainz.org":
        mbhost = "musicbrainz.org"
        mbport = 80
        sleepytime = 1
    elif headphones.CONFIG.MIRROR == "custom":
        mbhost = headphones.CONFIG.CUSTOMHOST
        mbport = int(headphones.CONFIG.CUSTOMPORT)
        mbuser = headphones.CONFIG.CUSTOMUSER
        mbpass = headphones.CONFIG.CUSTOMPASS
        sleepytime = int(headphones.CONFIG.CUSTOMSLEEP)
    elif headphones.CONFIG.MIRROR == "headphones":
        mbhost = "musicbrainz.codeshy.com"
        mbport = 80
        mbuser = headphones.CONFIG.HPUSER
        mbpass = headphones.CONFIG.HPPASS
        sleepytime = 0
    else:
        return False

    musicbrainzngs.set_useragent("headphones", "0.0", "https://github.com/rembo10/headphones")
    musicbrainzngs.set_hostname(mbhost + ":" + str(mbport))

    # Their rate limiting should be redundant to our lock
    if sleepytime == 0:
        musicbrainzngs.set_rate_limit(False)
    else:
        # calling it with an it ends up blocking all requests after the first
        musicbrainzngs.set_rate_limit(limit_or_interval=float(sleepytime))
        mb_lock.minimum_delta = sleepytime

    # Add headphones credentials
    if headphones.CONFIG.MIRROR == "headphones" or headphones.CONFIG.CUSTOMAUTH:
        if not mbuser or not mbpass:
            logger.warn("No username or password set for MusicBrainz server")
        else:
            musicbrainzngs.hpauth(mbuser, mbpass)

    # Let us know if we disable custom authentication
    if not headphones.CONFIG.CUSTOMAUTH and headphones.CONFIG.MIRROR == "custom":
        musicbrainzngs.disable_hpauth()

    logger.debug(
        "Using the following server values: MBHost: %s, MBPort: %i, Sleep Interval: %i", mbhost, mbport, sleepytime
    )

    return True
Example #21
0
def configure():
    """Set up the python-musicbrainz-ngs module according to settings
    from the beets configuration. This should be called at startup.
    """
    hostname = config['musicbrainz']['host'].as_str()
    https = config['musicbrainz']['https'].get(bool)
    # Only call set_hostname when a custom server is configured. Since
    # musicbrainz-ngs connects to musicbrainz.org with HTTPS by default
    if hostname != "musicbrainz.org":
        musicbrainzngs.set_hostname(hostname, https)
    musicbrainzngs.set_rate_limit(
        config['musicbrainz']['ratelimit_interval'].as_number(),
        config['musicbrainz']['ratelimit'].get(int),
    )
Example #22
0
    def __init__(self):
        log = logging.getLogger('util.importer.__init__')

        musicbrainzngs.set_useragent("NRG Processor", "0.01", "http://anorg.net/")
        musicbrainzngs.set_rate_limit(MUSICBRAINZ_RATE_LIMIT)
        
        if MUSICBRAINZ_HOST:
            musicbrainzngs.set_hostname(MUSICBRAINZ_HOST)
            
        self.pp = pprint.PrettyPrinter(indent=4)
        
        self.pp.pprint = lambda d: None
        
        
        self.mb_completed = []
Example #23
0
 def __init__(self, simplecache=None):
     """Initialize - optionaly provide simplecache object"""
     if not simplecache:
         from simplecache import SimpleCache
         self.cache = SimpleCache()
     else:
         self.cache = simplecache
     import musicbrainzngs as mbrainz
     mbrainz.set_useragent(
         "script.skin.helper.service", "1.0.0",
         "https://github.com/marcelveldt/script.skin.helper.service")
     mbrainz.set_rate_limit(limit_or_interval=2.0, new_requests=1)
     addon = xbmcaddon.Addon(ADDON_ID)
     if addon.getSetting("music_art_mb_mirror"):
         mbrainz.set_hostname(addon.getSetting("music_art_mb_mirror"))
     del addon
     self.mbrainz = mbrainz
Example #24
0
 def __init__(self, simplecache=None):
     '''Initialize - optionaly provide simplecache object'''
     if not simplecache:
         from simplecache import SimpleCache
         self.cache = SimpleCache()
     else:
         self.cache = simplecache
     import musicbrainzngs as mbrainz
     mbrainz.set_useragent(
         "script.skin.helper.service",
         "1.0.0",
         "https://github.com/marcelveldt/script.skin.helper.service")
     mbrainz.set_rate_limit(limit_or_interval=2.0, new_requests=1)
     addon = xbmcaddon.Addon(ADDON_ID)
     if addon.getSetting("music_art_mb_mirror"):
         mbrainz.set_hostname(addon.getSetting("music_art_mb_mirror"))
     del addon
     self.mbrainz = mbrainz
Example #25
0
def startmb():

    mbuser = None
    mbpass = None

    if headphones.MIRROR == "musicbrainz.org":
        mbhost = "musicbrainz.org"
        mbport = 80
        sleepytime = 1
    elif headphones.MIRROR == "custom":
        mbhost = headphones.CUSTOMHOST
        mbport = int(headphones.CUSTOMPORT)
        sleepytime = int(headphones.CUSTOMSLEEP)
    elif headphones.MIRROR == "headphones":
        mbhost = "144.76.94.239"
        mbport = 8181
        mbuser = headphones.HPUSER
        mbpass = headphones.HPPASS
        sleepytime = 0
    else:
        return False

    musicbrainzngs.set_useragent("headphones", "0.0",
                                 "https://github.com/rembo10/headphones")
    musicbrainzngs.set_hostname(mbhost + ":" + str(mbport))
    if sleepytime == 0:
        musicbrainzngs.set_rate_limit(False)
    else:
        #calling it with an it ends up blocking all requests after the first
        musicbrainzngs.set_rate_limit(limit_or_interval=float(sleepytime))

    # Add headphones credentials
    if headphones.MIRROR == "headphones":
        if not mbuser and mbpass:
            logger.warn("No username or password set for VIP server")
        else:
            musicbrainzngs.hpauth(mbuser, mbpass)

    logger.debug(
        'Using the following server values: MBHost: %s, MBPort: %i, Sleep Interval: %i',
        mbhost, mbport, sleepytime)

    return True
def main():
	parser = IrankOptionParser()
	parser.add_option('--threshold', default=5, type='int', help='include only artists with at least THRESHOLD files in collection')
	parser.add_option('--target', type='int', help='update only TARGET artists and then exit')
	parser.add_option('--max-age', metavar='DAYS', type='int', help='if --target is given, also update all artists which haven\'t been updated in DAYS days')
	parser.add_option('--min-age', metavar='DAYS', type='int', help='if --target is given, ignore artists which have been checked within DAYS days')
	parser.add_option('--update-only', help='don\'t print RSS feed', action='store_true')
	parser.add_option('--full', help='wipe existing DB', action='store_true')
	parser.add_option('--quick', help='don\'t update DB if it already exists', action='store_true')
	options, args = parser.parse_args()
	logging.basicConfig(level=logging.DEBUG if options.verbose else logging.WARN)

	app = IrankApp(options)
	mb_path = os.path.join(app.base_path, 'musicbrainz.sqlite')

	if options.full:
		try:
			os.unlink(mb_path)
		except OSError as e:
			if e.errno != errno.ENOENT: raise

	existing = os.path.exists(mb_path)
	mbdb = (load_db if existing else init_db)(mb_path)
	version = irank.version()
	mb.set_useragent("irank", version, "https://github.com/gfxmonk/python-irank")
	logging.debug("setting rate limit to 2/s")
	mb.set_rate_limit(new_requests = 2)
	try:
		if not (existing and options.quick):
			db = irank_db.load(app.db_path)
			populate_db(mbdb, options, db)
			db.close()

		if not options.update_only:
			releases = mbdb.execute('''select
				artist, title, date
				from releases
				order by date desc
				limit 100''')
			doc = make_feed(releases)
			print(doc.toprettyxml())
	finally:
		mbdb.close()
Example #27
0
def set_auth(config_file='config.yaml'):

    if os.path.isfile(config_file):
        with open(config_file, 'r') as fp:
            auth_dict = yaml.safe_load(fp)
            try:
                creds = auth_dict['mbz_creds']
                logger.debug(
                    'Auth ({}): Setting user-agent and rate-limit'.format(
                        'MBZ'))
                musicbrainzngs.set_useragent(
                    app=creds['useragent']['app'],
                    version=creds['useragent']['version'],
                    contact=creds['useragent']['contact'])
                musicbrainzngs.set_rate_limit(
                    limit_or_interval=float(
                        creds['rate_limit']['limit_or_interval']),
                    new_requests=int(creds['rate_limit']['new_requests']))
            except (TypeError, KeyError):
                logger.error(
                    'SpotiM3U ({}): Invalid YAML (MBZ)'.format('Func'))
Example #28
0
def startmb():

    mbuser = None
    mbpass = None

    if headphones.MIRROR == "musicbrainz.org":
        mbhost = "musicbrainz.org"
        mbport = 80
        sleepytime = 1
    elif headphones.MIRROR == "custom":
        mbhost = headphones.CUSTOMHOST
        mbport = int(headphones.CUSTOMPORT)
        sleepytime = int(headphones.CUSTOMSLEEP)
    elif headphones.MIRROR == "headphones":
        mbhost = "144.76.94.239"
        mbport = 8181
        mbuser = headphones.HPUSER
        mbpass = headphones.HPPASS
        sleepytime = 0
    else:
        return False

    musicbrainzngs.set_useragent("headphones","0.0","https://github.com/rembo10/headphones")
    musicbrainzngs.set_hostname(mbhost + ":" + str(mbport))
    if sleepytime == 0:
        musicbrainzngs.set_rate_limit(False)
    else:
        #calling it with an it ends up blocking all requests after the first
        musicbrainzngs.set_rate_limit(limit_or_interval=float(sleepytime))

    # Add headphones credentials
    if headphones.MIRROR == "headphones":
        if not mbuser and mbpass:
            logger.warn("No username or password set for VIP server")
        else:
            musicbrainzngs.hpauth(mbuser,mbpass)

    logger.debug('Using the following server values: MBHost: %s, MBPort: %i, Sleep Interval: %i', mbhost, mbport, sleepytime)

    return True
Example #29
0
    def __init__(self):
        super(OldestDatePlugin, self).__init__()
        self.import_stages = [self._on_import]
        self.config.add({
            'auto': True,  # Run during import phase
            'ignore_track_id': False,  # During import, ignore existing track_id
            'filter_on_import': True,  # During import, weight down candidates with no work_id
            'prompt_missing_work_id': True,  # During import, prompt to fix work_id if missing
            'force': False,  # Run even if already processed
            'overwrite_year': False,  # Overwrite year field in tags
            'filter_recordings': True,  # Skip recordings with attributes before fetching them
            'approach': 'releases',  # recordings, releases, hybrid, both
            'release_types': None,  # Filter by release type, e.g. ['Official']
            'use_file_date': False  # Also use file's embedded date when looking for oldest date
        })

        if self.config['ignore_track_id']:
            self.register_listener('import_task_created', self._import_task_created)
        if self.config['prompt_missing_work_id']:
            self.register_listener('import_task_choice', self._import_task_choice)
        if self.config['filter_on_import']:
            self.register_listener('trackinfo_received', self._import_trackinfo)
            # Add heavy weight for missing work_id from a track
            config['match']['distance_weights'].add({'work_id': 4})

        # Get global MusicBrainz host setting
        musicbrainzngs.set_hostname(config['musicbrainz']['host'].get())
        musicbrainzngs.set_rate_limit(1, config['musicbrainz']['ratelimit'].get())

        for recording_field in (
                'recording_year',
                'recording_month',
                'recording_day',
                'recording_disambiguation'):
            field = mediafile.MediaField(
                mediafile.MP3DescStorageStyle(recording_field),
                mediafile.MP4StorageStyle('----:com.apple.iTunes:{}'.format(
                    recording_field)),
                mediafile.StorageStyle(recording_field))
            self.add_media_field(recording_field, field)
import mutagen
from mutagen.easyid3 import EasyID3
from mutagen.easymp4 import EasyMP4
from mutagen.oggvorbis import OggVorbis
from mutagen.flac import FLAC
from optparse import OptionParser
import os
import smtplib
import urllib

musicbrainzngs.set_useragent(
    "new_music_finder.py",
    "0.2",
    "https://joetotaro.net",
)
musicbrainzngs.set_rate_limit(limit_or_interval=1.0, new_requests=1)
FORMAT = '%(asctime)s %(levelname)s %(funcName)s:%(lineno)d %(message)s'


def find_releases(artists_set, year_month):
    good = u""
    questionable = u""

    for artist in artists_set:
        result = musicbrainzngs.search_releases(
            query=u"artist:\"{}\" AND date:{}-?? AND status:official AND primarytype:album".format(artist, year_month))

        if not result['release-list']:
            Logger.debug("no release found for artist %s", artist)

        music_brains_links = u""
    def setUp(self):
        self.opener = _common.FakeOpener("<response/>")
        musicbrainzngs.compat.build_opener = lambda *args: self.opener

        musicbrainzngs.set_useragent("test", "1")
        musicbrainzngs.set_rate_limit(False)
Example #32
0
# PARTICULAR PURPOSE.  See the GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License along with
# this program.  If not, see http://www.gnu.org/licenses/

import argparse
import collections
import os

import musicbrainzngs as mb

import compmusic.file
import compmusic.musicbrainz

mb.set_useragent("Dunya", "0.1")
mb.set_rate_limit(False)
mb.set_hostname("sitar.s.upf.edu:8090")

import eyed3
import logging

eyed3.utils.log.log.setLevel(logging.ERROR)


class Stats(object):
    # How many recordings are done for each work
    # key is workid
    work_recording_counts = collections.Counter()

    # artists. could be artists of the release, or as release
    # rels, or as track rels
Example #33
0
    def setUp(self):
        self.opener = _common.FakeOpener("<response/>")
        musicbrainzngs.compat.build_opener = lambda *args: self.opener

        musicbrainzngs.set_useragent("test", "1")
        musicbrainzngs.set_rate_limit(False)
Example #34
0
  #  print("Error: cannot ping "+sites[args[0]]+"\n")
  #  exit(1)
  #if len(args)>1:
  #  pingtest(args[1:])

def concat3D(list1,list2):
  if len(list1)==len(list2):
    return [ list1[x]+list2[x] for x in xrange(list1)]
  print("Error: cannot add two lists who differ in length")
  return []

def getConfig():
  return getFileContents('config')

config = getConfig()
mb.set_rate_limit()
mb.set_useragent('Zarvox_Automated_DJ','Alpha',"KUPS' [email protected]")
mbMultiplier = float(config['musicbrainz_multiplier'])
if 'musicbrainz_hostname' in config:
  mbHostname = config['musicbrainz_hostname']
  print("Setting musicbrainz hostname to "+mbHostname)
  mb.set_hostname(mbHostname)

def whatquote(text):
  return text.replace('+','%2B')

def mbquote(text):
  newText = text
  for badchar in '()[]^@/~=&"':
    newText = newText.replace(badchar, ' ')
  for badchar in '!':
Example #35
0
def set_up_musicbrainzngs( user_agent_app, user_agent_version ):
    """
    Call this before running `mp3_tag_fixer.py`
    """
    musicbrainzngs.set_useragent( user_agent_app, user_agent_version )
    musicbrainzngs.set_rate_limit( limit_or_interval=1.0, new_requests=1 )
Example #36
0
 def setUp(self):
     musicbrainzngs.set_useragent("a", "1")
     musicbrainzngs.set_rate_limit(rate_limit=False)
Example #37
0
 def setUp(self):
     musicbrainzngs.set_useragent("test", "1")
     musicbrainzngs.set_rate_limit(False)
Example #38
0
def loadConfig():
    global config
    global ignoredArtists
    global cacheFile
    global firstArg
    global uploadSongs
    global authFile
    global MBfile
    global configPath

    configPath = userDir / 'config.ini'
    if len(sys.argv) > 1:
        firstArg = sys.argv[1]

    if configPath.exists():
        config.read(configPath)
        # if the ini file contains a relative path for the cache file use userDir as a base
        cacheFile = pathlib.Path(
            config['DEFAULT']
            ['cachefile']) if config['DEFAULT']['cachefile'].startswith(
                '/') else userDir / config['DEFAULT']['cachefile']
        authFile = pathlib.Path(
            config['DEFAULT']
            ['authfile']) if config['DEFAULT']['authfile'].startswith(
                '/') else userDir / config['DEFAULT']['authfile']
        MBfile = pathlib.Path(
            config['DEFAULT']
            ['mbfile']) if config['DEFAULT']['mbfile'].startswith(
                '/') else userDir / config['DEFAULT']['mbfile']
        ignoredArtists = json.loads(config.get('DEFAULT', 'ignoredartists'))
        uploadSongs = config['DEFAULT'].getboolean('uploadsongs')
        wordRatio = config['DEFAULT'].getint('wordRatio')
        phraseRatio = config['DEFAULT'].getint('phraseRatio')
        YTDelay = config['DEFAULT'].getfloat('YTDelay')
        musicbrainzngs.set_hostname(config['DEFAULT']['mbhost'])
        musicbrainzngs.set_rate_limit(1,
                                      config['DEFAULT'].getint('mbrateLimit'))
    else:
        config['DEFAULT'] = {}
        config['DEFAULT']['cachefile'] = 'cache.p'
        config['DEFAULT']['authfile'] = 'headers_auth.json'
        config['DEFAULT']['mbfile'] = 'MBdata.p'
        config['DEFAULT']['uploadsongs'] = 'no'
        config['DEFAULT']['mbhost'] = 'musicbrainz.org'
        config['DEFAULT']['mbrateLimit'] = '1'
        config['DEFAULT']['wordRatio'] = 96
        config['DEFAULT']['phraseRatio'] = 89
        config['DEFAULT']['YTDelay'] = 0.1
        config['DEFAULT']['ignoredartists'] = json.dumps(
            ['karaoke', 'in the style of', 'tribute'])
        config['DEFAULT']['ignoredgenres'] = json.dumps([
            '^punk', '^grunge', '^hard', '^metal', '^classical',
            '^alternative', '^rap', '^hip hop', '^holiday', '^christmas'
        ])
        cacheFile = userDir / 'cache.p'
        authFile = userDir / 'headers_auth.json'
        MBfile = userDir / 'MBdata.p'
        wordRatio = 96
        phraseRatio = 89
        YTDelay = 0.1
        ignoredArtists = ['karaoke', 'in the style of', 'tribute']
        print('Writing config file')
        with openFile(configPath, 'w') as (configFile, err):
            if err:
                print(f'Problem saving config file: {err}')
            else:
                config.write(configFile)
Example #39
0
def init():
    musicbrainzngs.set_useragent("mymusiclist", "0.1", contact="none")
    musicbrainzngs.set_rate_limit(limit_or_interval=False, new_requests=1)
    print("[Exthook] Initialized")
Example #40
0
# Prerrequisites.
isAvailable = True
errorMsg = ""
try:
    import musicbrainzngs
    from musicbrainzngs import mbxml
    import urllib2

except:
    isAvailable = False
    errorMsg = "The python-musicbrainz-ngs python module git master needs to be installed. See https://github.com/alastair/python-musicbrainz-ngs/ . "

else:
# general script settings
  musicbrainzngs.set_rate_limit(False) # set on again to reduce server load?
  musicbrainzngs.set_useragent(
    "kde-nepomuk-metadata-extractor",
    "0.6",
    "https://projects.kde.org/projects/playground/base/nepomuk-metadata-extractor",
  )

#------------------------------------------------------------------------------
# Module options
#
# Must have:
# name          = Long name of the service
# icon          = download the favicon and put is as png in the folder, icon is than name.png
# identifier    = short unique identifier for the service, no special chars, whitespaces
# resource      = list of resources this plugin can fetch for example ['tvshow', 'movie']
# urlregex      = a list of regular expressions that fits a url to this plugin
Example #41
0
import configparser
import musicbrainzngs

config = configparser.ConfigParser()
config.read('config.ini', encoding='utf-8')
version = config['musicbrainz']['version']
email = config['musicbrainz']['email']

# Connect this to web form
id_input = "ef49c461-0948-4c57-9baa-8fbb15f0e05b"

# Identify app to MusicBrainz
musicbrainzngs.set_useragent('SpekCheck', version, contact=email)
musicbrainzngs.set_rate_limit(limit_or_interval=1.0, new_requests=1)

try:
    result = musicbrainzngs.get_release_by_id(
        id_input, includes=["artists", "discids", "labels"])
except WebServiceError as exc:
    print("Something went wrong with the request: %s" % exc)
else:
    # Fetches fields from 'result' dictionary
    release = result["release"]
    title = release["title"]
    artist_credit = release["artist-credit"][0]["artist"]["name"]
    physical_format = release["medium-list"][0]["format"]
    catalog_number = release["label-info-list"][0]["catalog-number"]

    # Return values to DB
    print('title: ' + title)
    print('artist: ' + artist_credit)
import json
import logging
from compmusic import dunya
import musicbrainzngs as mb

from utilities.constants import *
from utilities.recordingcomputation import *
from utilities.generalutilities import *

mb_logger = logging.getLogger('musicbrainzngs')
mb_logger.setLevel(logging.WARNING)

# Dunya token
dunya.set_token(DUNYA_TOKEN)

mb.set_rate_limit()
mb.set_hostname("musicbrainz.org")


# -------------------------------------------------- CHECK --------------------------------------------------

def check_dunya_metadata():
    ''' Check if all the json file relating to metadata are stored in the data directory

    :return: True if all the file exist. Otherwise, return False
    '''
    flag = True
    for fn in DF_LISTS:
        file_name = PREFIX_JSON + fn + '.json'
        if not os.path.exists(os.path.join(DATA_DIR, file_name)):
            flag = False
 def setUp(self):
     musicbrainzngs.set_useragent("a", "1")
     musicbrainzngs.set_rate_limit(1, 100)
     urllib2.build_opener = self.build_opener
Example #44
0
                        print_function, unicode_literals)

import sys

import logbook
import musicbrainzngs
from beets.autotag.mb import album_info
from headphones2 import local_redis
from redis.lock import Lock
from retry import retry

RELEASE_INCLUDES = ['media', 'recordings', 'release-groups', 'labels', 'artist-credits']

musicbrainzngs.set_useragent("headphones2", "0.0", "https://github.com/omerbenamram/headphones2")
musicbrainzngs.set_hostname("musicbrainz.org:80")
musicbrainzngs.set_rate_limit()
logger = logbook.Logger(__name__)
logger.handlers.append(logbook.StreamHandler(sys.stdout))


class MusicbrainzLock(Lock):
    def __enter__(self):
        super(MusicbrainzLock, self).__enter__()
        logger.debug('MusicbrainzLock acquired')

    def __exit__(self, exc_type, exc_val, exc_tb):
        super(MusicbrainzLock, self).__exit__(exc_type, exc_val, exc_tb)
        logger.debug('MusicbrainzLock released')


musicbrainz_lock = MusicbrainzLock(local_redis, 'musicbrainz', thread_local=False)
    def tearDown(self):
        musicbrainzngs.set_rate_limit(1, 1)

        self.cop.restore()
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.  See the GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License along with
# this program.  If not, see http://www.gnu.org/licenses/
import urllib2
import urllib
import json
import cookielib
import re
import sys

import compmusic
import musicbrainzngs as mb
mb.set_useragent("Dunya", "0.1")
mb.set_rate_limit(True)
mb.set_hostname("musicbrainz.org")

domain = "https://musicbrainz.org"
password = '******'
username = '******'
login_url = '/login'
work_url = '/work/%s/edit'

auth_token = "###"
symbtrmu2_url = 'http://dunya.compmusic.upf.edu/document/by-id/%s/symbtrmu2'
dunya_fuzzy_url = 'http://dunya.compmusic.upf.edu/api/makam/fuzzy'

mb_cache = {}

def get_symbtrmu2(work_mbid):
    def tearDown(self):
        musicbrainzngs.set_rate_limit(True, 1, 1)

        self.cop.restore()
Example #48
0
import musicbrainzngs
from functools import wraps
import json
import redis

rconn = redis.StrictRedis(host="localhost")
musicbrainzngs.set_hostname("musicbrainz.s.upf.edu")
musicbrainzngs.set_rate_limit(False)
musicbrainzngs.set_useragent("test", "test")

def cache(f):
    @wraps(f)
    def inner(*args, **kwargs):
        # TODO: understand args and kwargs
        # -- args[0] is mbid
        key = "%s:%s" % (f.__name__, args[0])
        val = rconn.get(key)
        if not val:
            ret = f(*args, **kwargs)
            val = json.dumps(ret)
            rconn.set(key, val)
        else:
            ret = json.loads(val)
        return ret
    return inner

@cache
def get_recording(mbid):
    try:
        rec = musicbrainzngs.get_recording_by_id(mbid, includes=["releases", "artists"])
        return rec["recording"]
Example #49
0
 def tearDown(self):
     musicbrainzngs.set_rate_limit(True)
Example #50
0
# PARTICULAR PURPOSE.  See the GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License along with
# this program.  If not, see http://www.gnu.org/licenses/


import sys
import os
import argparse
import collections

import compmusic.file
import compmusic.musicbrainz
import musicbrainzngs as mb
mb.set_useragent("Dunya", "0.1")
mb.set_rate_limit(False)
mb.set_hostname("sitar.s.upf.edu:8090")

import eyed3
import logging
eyed3.utils.log.log.setLevel(logging.ERROR)

class Stats(object):

    # How many recordings are done for each work
    # key is workid
    work_recording_counts = collections.Counter()

    # artists. could be artists of the release, or as release
    # rels, or as track rels
    artists = set()
Example #51
0
        return

    release.Sync(options)

    return


########################
### Main Script Loop ###
########################

PrintHeader()

Warp.plugin.LoadPlugins()

ws.set_rate_limit(
)  # Disable the default rate limiting, as I do my own, and don't know whether this is blocking/non-blocking.
ws.set_useragent("Warp Tagger", "0.2", "*****@*****.**")

if os.path.exists("./options"):
    ReadOptions("./options")
elif os.path.exists("./options.default"):
    ReadOptions("./options.default")

# result = ws.get_release_by_id("dee5c657-7960-4a3c-a01e-66865ba24320",["artist-credits","recordings","labels","release-groups","media"])["release"]
# Warp.utils.safeprint( json.dumps(result, sort_keys=True, indent=4, ensure_ascii = False) )
last_fetch_time = 0

# raise SystemError

if os.path.isdir(options["library_folder"]):
    options["library_folder"] = os.path.realpath(options["library_folder"])
Example #52
0
the recordings tags.
'''

from __future__ import print_function

import urllib2
import urllib
import json
import cookielib
import re
import sys

import compmusic
import musicbrainzngs as mb
mb.set_useragent("Dunya", "0.1")
mb.set_rate_limit(True)
mb.set_hostname("musicbrainz.org")

domain = "https://musicbrainz.org"
password = '******'
username = '******'
login_url = '/login'
work_url = '/work/%s/edit'

auth_token = "###"
symbtrmu2_url = 'http://dunya.compmusic.upf.edu/document/by-id/%s/symbtrmu2'
dunya_fuzzy_url = 'http://dunya.compmusic.upf.edu/api/makam/fuzzy'

mb_cache = {}
count_missing_mu2 = 0
count_matched_mu2 = 0
Example #53
0
	def findRelease(self):
		name = self.query
		
		results = []

		limit = 1

		chars = set('!?*')
		if any((c in chars) for c in name):
		    name = '"'+name+'"' 
		    
		mb.set_useragent("headphones","1.0","https://github.com/erikvip/headphones")
		mb.set_rate_limit(True)
		res = mb.search_releases(query='artist:'+name,limit=limit)

		logging.info('musicbrainz query: %s' % name)
		logging.info('musicbrainz response: \n %s' % res)

		for a in res['release-list']:
			album = {
				'id': a['id'], 
				'artist': a['artist-credit-phrase'], 
				#'date': a['date'], 
				#'country': a['country'], 
				'status': a['status'], 
				'title' : a['title'],
				'tracks' : []
			}

			disc = mb.get_release_by_id(a['id'], ["media","recordings"])

			output = "TITLE \"%(artist)s - %(title)s\"\n" % album
			output += "PERFORMER \"%(artist)s\"\n" % album
			output += "FILE \"%s.mp3l\" MP3\n" % a['id']

			time = 0
			minutes = 0
			seconds = 0

			logging.info('musicbrainz release response: \n %s' % disc)

			for d in disc['release']['medium-list']:
				
				for t in d['track-list']:
					track = {
						'position': str(t['position'].zfill(2)), 
						'title' : t['recording']['title'].encode('ascii', 'ignore'),
						'minutes' : str(minutes).zfill(2), 
						'seconds ': seconds,
						'duration' : "%s:%s" % (str(minutes).zfill(2), seconds), 
						'seconds' : time
					}

					output += "  TRACK %(position)s AUDIO\n" % track
					output += "    TITLE \"%(title)s\"\n" % track
#					if t['position'] == "1":
#						output += "    INDEX 00 00:00:00\n"
					output += "    INDEX 01 %(duration)s:00\n" % track


					# Convert recording time to Minutes:Seconds
					time += int(t['length']) / 1000
					minutes = time/60
					seconds = str(time%60)[:2].zfill(2)
					

#					logging.info('Track #%(position)s \tDuration: %(duration)s [%(seconds)ss] \t%(title)s' % track)

			results.append(album)

					

		#return results
		return output
Example #54
0
    if not release.valid:
        return

    release.Sync( options )

    return

########################
### Main Script Loop ###
########################

PrintHeader()

Warp.plugin.LoadPlugins()

ws.set_rate_limit()  # Disable the default rate limiting, as I do my own, and don't know whether this is blocking/non-blocking.
ws.set_useragent( "Warp Tagger", "0.2", "*****@*****.**" )

if os.path.exists( "./options" ):
    ReadOptions( "./options" )
elif os.path.exists( "./options.default" ):
    ReadOptions( "./options.default" )

# result = ws.get_release_by_id("dee5c657-7960-4a3c-a01e-66865ba24320",["artist-credits","recordings","labels","release-groups","media"])["release"]
# Warp.utils.safeprint( json.dumps(result, sort_keys=True, indent=4, ensure_ascii = False) )
last_fetch_time = 0

# raise SystemError

if os.path.isdir( options["library_folder"] ):
    options["library_folder"] = os.path.realpath( options["library_folder"] )
def get_album_art(artist, album, file, 
  year = None, lang = None, tracks = None, quality = None, format = None, 
  status = None, verbose = False):
  '''
  Name:
    get_album_art
  Purpose:
    A function to download album artwork using the musicbrainz api
  Inputs:
    artist  : The artist of the album
    album   : Name of the album
    file    : Full path to where the file will be downloaded
  Outputs:
    Downloads album artwork
  Keywords:
    year     : Year album was released
    tracks   : The number of tracks on the album. Default is None.
    lang     : The language of the release. Default is english (eng)
    quality  : Quality of the returned info. Default is high.
    format   : Format of the release (cd, vinyl, etc.). Default is CD.
    status   : The type of release. Default is official.
  Author and History:
    Kyle R. Wodzicki     Created 24 May 2016
      Adapted from examples int he musicbrainzngs package.

      Modified 12 Nov. 2016 by Kyle R. Wodzicki
        Changed the data['artist'] == artist.upper() to 
        data['artist'] in artist.upper(). This should allow a little more 
        flexibility. One example is the Riding with the King album by B.B. King
        and Eric Clapton. However, musicbrainz has the artist as just B.B. King.
        Issues may arise if the name of an artist somehow fits into the name
        of the artist of interest.
  '''
  MB.set_useragent("iTunes_Convert_KRW", "1.0");                                # Set the user of the MusicBrainz API
  MB.set_rate_limit(limit_or_interval=False);                                   # Set the limit interval to false, i.e., no limit

  open(file, 'a').close();                                                    # Empty file created so do not attempt to download on subsequent runs. THIS FILE IS OVERWRITTEN IF ARTWORK FOUND!!!!
  quality = 'high'     if quality is None else quality;
  status  = 'official' if status  is None else status;
  lang    = 'eng'      if lang    is None else lang;
  format  = 'CD'       if format  is None else format;

  release_id = None;                                                            # Set release_id to None
  result = search_releases(artist, album, quality);  
  if result is None: return 2  
  for i in range(-1,len(importance)):  
    if (i >= 0): exec(importance[i] + " = None");                          # Set a given 'importance' variable to None.
    for release in result['release-list']:                                      # Iterate over list of releases
      data = parse_release( release );                                          # Parse the release
      if data is None: continue;                                                # If vital information not present in release, the skip
      if (verbose is True): print( data );                                      # Print data IF verbose
      if (data['artist'] in artist.upper() or artist.upper() in data['artist']):
        if (data['album'] not in album.upper() and \
            album.upper() not in data['album']): continue;
        if (status is not None):
          if (data['status'] != status.upper()): continue;                      # If status exists and does NOT match the default status, skip
        if (data['disambig'] is not None):  
          if (data['disambig'] not in album.upper()): continue;  
        if (format is not None):  
          if (format.upper() != data['format']): continue;                      # If user input format for the album and that does not match the number on the release, skip
        if (tracks is not None):  
          if (int(tracks) != data['tracks']): continue;                         # If user input number of tracks and that does not match the number on the release, skip
        if (year is not None):  
          if (int(year) != data['year']): continue;                             # If user input year and that does not match the year of the release, skip
        if (lang is not None):  
          if (lang.upper() != data['lang']): continue;                          # If user input year and that does not match the year of the release, skip
        release_id = release['id'];                                             # Get the MusicBrainz ID for the album
        release_info = get_release_by_id( release_id );                    # Get information about the relase
        if release_info is None: return 3;                                      # If MusicBrainz search fails three times, return 2
        if (verbose is True): print( release_info );
        if get_image(release_info, release_id, file):
          return 0;
  return 1
 def setUp(self):
     musicbrainzngs.set_useragent("a", "1")
     musicbrainzngs.set_rate_limit(rate_limit=False)
Example #57
0
import logbook
import musicbrainzngs
from beets.autotag.mb import album_info
from headphones2 import local_redis
from redis.lock import Lock
from retry import retry

RELEASE_INCLUDES = [
    'media', 'recordings', 'release-groups', 'labels', 'artist-credits'
]

musicbrainzngs.set_useragent("headphones2", "0.0",
                             "https://github.com/omerbenamram/headphones2")
musicbrainzngs.set_hostname("musicbrainz.org:80")
musicbrainzngs.set_rate_limit()
logger = logbook.Logger(__name__)
logger.handlers.append(logbook.StreamHandler(sys.stdout))


class MusicbrainzLock(Lock):
    def __enter__(self):
        super(MusicbrainzLock, self).__enter__()
        logger.debug('MusicbrainzLock acquired')

    def __exit__(self, exc_type, exc_val, exc_tb):
        super(MusicbrainzLock, self).__exit__(exc_type, exc_val, exc_tb)
        logger.debug('MusicbrainzLock released')


musicbrainz_lock = MusicbrainzLock(local_redis,