コード例 #1
0
ファイル: models.py プロジェクト: kaninfod/musicplayer
    def get_coverart(self, album):
        path = "app/static/media/"
        filename = "%s.jpg" % album.id

        musicbrainzngs.set_useragent("python-musicplayer-flask","0.1","*****@*****.**")
        covers = cache.get('covers')
        if album.id in covers:
            return

        covers.append(album.id)
        cache.set("covers", covers)


        if not album.musicbrainz_albumid or album.coverimage:
            return
            #raise NameError('musicbrainz_albumid not set')
        try:
            data = musicbrainzngs.get_image_list(album.musicbrainz_albumid)
        except Exception as e:
            return e

        if len(data['images']) == 0:
            raise NameError('No images returned from service')

        urllib.request.urlretrieve(data['images'][0]['image'], "%s%s" % (path, filename))
        ci = open("%s%s" % (path, filename), 'rb')
        album.coverimage.put(ci, content_type = 'image/jpeg')


        return
コード例 #2
0
ファイル: main.py プロジェクト: chadberg/whipper
def main(argv):
    # load plugins

    from morituri.configure import configure
    pluginsdir = configure.pluginsdir
    homepluginsdir = os.path.join(os.path.expanduser('~'),
        '.morituri', 'plugins')

    distributions, errors = pkg_resources.working_set.find_plugins(
        pkg_resources.Environment([pluginsdir, homepluginsdir]))
    if errors:
        log.warning('errors finding plugins: %r', errors)
    log.debug('mapping distributions %r', distributions)
    map(pkg_resources.working_set.add, distributions)

    # validate dependencies
    from morituri.common import deps
    h = deps.DepsHandler()
    h.validate()

    # set user agent
    import musicbrainzngs
    musicbrainzngs.set_useragent("morituri", configure.version,
        'https://thomas.apestaart.org/morituri/trac')


    c = Rip()
    try:
        ret = c.parse(argv)
    except SystemError, e:
        sys.stderr.write('rip: error: %s\n' % e.args)
        return 255
コード例 #3
0
def lookup_song(artist, title, format_string, sql):
    musicbrainzngs.set_useragent('Song-Looker-Upper', '0.1', 'http://www.kbarnes3.com')

    query = '"{0}" AND artist:"{1}" AND status:official'.format(title, artist)

    result = musicbrainzngs.search_recordings(query)

    if len(result['recording-list']) < 1:
        print('No songs found for query ' + query, file=sys.stderr)
        return

    recording = result['recording-list'][0]

    try:
        artist = recording['artist-credit'][0]['artist']['name']
        artist = artist.replace(u'\u2019', "'")
        title = recording['title']
        title = title.replace(u'\u2019', "'")

        if sql:
            artist = artist.replace("'", "''")
            title = title.replace("'", "''")

        length = recording['release-list'][0]['medium-list'][1]['track-list'][0]['length']
        duration = int(int(length) / 1000)

        output = format_string.format(artist=artist, title=title, duration=duration)
        print(output, end='')
    except Exception as ex:
        print('Error handling recording: ' + str(recording), file=sys.stderr)
        print(ex.message, file=sys.stderr)
        raise RecordParseException(ex.message)
コード例 #4
0
ファイル: mb_match.py プロジェクト: mayhem/ia_matcher
def match_tracks_to_release(title, tracks, mbid, name):
    '''
       Given a list of tracks, a candidate release mbid and name this function should return
       a score (0.0-1.0) of how well this list of tracks compares to the MB release.
    '''

    try:
        musicbrainzngs.set_useragent(config.USER_AGENT_STRING, config.USER_AGENT_VERSION, config.USER_AGENT_USER)
        rel = musicbrainzngs.get_release_by_id(mbid, includes=['recordings'])
    except musicbrainzngs.WebServiceError as exc:
        print "Something went wrong with the request: %s" % exc 
        return -1

#    print "--- %-40s %s" % (title.encode('utf-8'), name.encode('utf-8'))
    matches = []
    total = 0.0
    print 
    for i, t in enumerate(rel["release"]["medium-list"][0]["track-list"]):
        try:
            d = Levenshtein.ratio(clean_string(t['recording']['title']), tracks[i]['clean'])
            print "%.3f %2d %-40s | %s" % (d, i+1, clean_string(t['recording']['title']), tracks[i]['clean'])
            total += d
        except IndexError:
            return -1

    return total / len(tracks)
コード例 #5
0
 def __init__(self, username=None):
     self.auth = False
     self.keyring_failed = False
     self.username = username
     musicbrainzngs.set_hostname(options.server)
     musicbrainzngs.set_useragent(AGENT_NAME, __version__,
             "http://github.com/JonnyJD/musicbrainz-isrcsubmit")
コード例 #6
0
ファイル: covers.py プロジェクト: Sinkler/music
 def handle(self, **options):
     musicbrainzngs.set_useragent(settings.MB_APP, settings.MB_VERSION, settings.MB_CONTACT)
     if options['full']:
         albums = Album.objects.filter(image='')
     else:
         albums = Album.objects.filter(is_get_image=False)
     for album in albums:
         print 'ALBUM: ', album
         for release in album.releases.all():
             try:
                 data = musicbrainzngs.get_image_list(release.mbid)
                 url = ''
                 for image in data['images']:
                     if 'Front' in image['types'] and image['approved']:
                         url = image['thumbnails']['large']
                 if url:
                     print '+'
                     album.image = url
                     break
             except musicbrainzngs.musicbrainz.ResponseError:
                 pass
         if not album.image:
             print '-'
         album.is_get_image = True
         album.save()
     print 'FINISHED'
コード例 #7
0
ファイル: steeb.py プロジェクト: napcae/steeb
def load(evt):
    m.set_useragent("steeb", "0.1", "*****@*****.**")
    mainwin['button_search'].onclick = search_artist
    mainwin['artistslist'].onitemselected = get_albums
    mainwin['albumslist'].onitemselected = get_tracks
    mainwin['button_down'].onclick = clickevt_album
    lv = mainwin['artistslist']
コード例 #8
0
ファイル: discogs.py プロジェクト: M0rg4n/geordi
 def individual_subitem_matches(self, subitem, data):
     musicbrainzngs.set_useragent('geordi', 'discogs-subitem-matches', 'http://geordi.musicbrainz.org')
     (discogs_type, discogs_id) = re.split('-', subitem, 1)
     if discogs_type == 'master':
         try:
             url_data = musicbrainzngs.browse_urls(
                 resource='http://www.discogs.com/master/%s' % discogs_id,
                 includes=['release-group-rels'])
             mbids = [release_group['release-group']['id'] for release_group in url_data['url']['release_group-relation-list']]
             return {'release-group': mbids}
         except:
             return {'unmatch': []}
     elif discogs_type in ['artist', 'label'] and data.get('name', False):
         names = data.get('name', [])
         mbids = []
         for name in names:
             try:
                 url_data = musicbrainzngs.browse_urls(
                     resource='http://www.discogs.com/%s/%s' % (discogs_type, urllib.quote_plus(name.encode('utf-8'), '!\'()*-._~')),
                     includes=['%s-rels' % discogs_type])
                 mbids = mbids + [entity[discogs_type]['id'] for entity in url_data['url']['%s-relation-list' % discogs_type]]
             except: continue
         mbids = uniq(mbids)
         if len(mbids) > 0:
             return {discogs_type: mbids}
         else:
             return {'unmatch': []}
     else:
         return {}
コード例 #9
0
    def __init__(self):
        run = Prop("run")
        if (run) and (time.time() < float(run) + 3):
            return

        Prop("run", str(time.time()))
        Prop("stamp", _stamp)

        self.once = True
        self.abort = False
        self.mesg = None
        self.station = None
        self.stations = None
        self.songs = {}
        self.pithos = mypithos.Pithos()
        self.player = xbmc.Player()
        self.playlist = xbmc.PlayList(xbmc.PLAYLIST_MUSIC)
        self.ahead = {}
        self.queue = collections.deque()
        self.prof = Val("prof")
        self.wait = {"auth": 0, "stations": 0, "flush": 0, "scan": 0, "next": 0}
        self.silent = xbmc.translatePath("special://home/addons/%s/resources/media/silent.m4a" % _id)

        musicbrainzngs.set_useragent("kodi.%s" % _id, Val("version"))
        xbmcvfs.mkdirs(xbmc.translatePath(Val("cache")).decode("utf-8"))
        xbmcvfs.mkdirs(xbmc.translatePath(Val("library")).decode("utf-8"))
コード例 #10
0
ファイル: ModelUpdater.py プロジェクト: maeln/Mary
	def run(self):
		musicbrainzngs.set_useragent("Mary", "Alpha", "*****@*****.**")
		if self.model is not None:
			for row in self.model.row:
				self.find_mbid(row)
				if self.lock.is_set():
					break
コード例 #11
0
ファイル: __old_importer.py プロジェクト: hzlf/openbroadcast
    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)
コード例 #12
0
ファイル: vk_downloader.py プロジェクト: yenbekbay/mudl
 def search_mb(self):
     musicbrainzngs.set_useragent("mudl", "0.1.3")
     criteria = {"artist": self.user_query.bare_artist(), "recording": self.user_query.bare_title()}
     try:
         recordings = musicbrainzngs.search_recordings(limit=10, **criteria)
         for recording in recordings["recording-list"]:
             yield VKDownloader.get_mb_info(recording)
     except Exception as e:
         print(colored.red(u"Something went wrong with the request: {0}".format(e)))
コード例 #13
0
ファイル: gigographics.py プロジェクト: mdgweb/gigographics
 def __init__(self, mbz_id):
     self.mbz_id = mbz_id
     musicbrainzngs.set_useragent("gigographics.mdg.io", "0.1", "http://gigographics.mdg.io")
     self.data = {
         'artist' : {
             'name' : musicbrainzngs.get_artist_by_id(self.mbz_id)['artist']['name'],
             'mbz_id' : self.mbz_id
         }
     }
コード例 #14
0
ファイル: identifier.py プロジェクト: hzlf/openbroadcast.org
    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)
コード例 #15
0
ファイル: CDDBAdd.py プロジェクト: KMNR/KLAP-CDDBAdds
def musicbrainz_lookup():
    """
    Scans a folder for music files with metadata. Collects metadata information
    from all music files and assumes they belong to the same album. Produces a
    simple description of the album that it loads into a KLAP form.
    """
    
    # Help the user
    if len(sys.argv) != 2:
        print "Usage: {} Drive".format(sys.argv[0])
        sys.exit(1)

    tracks = []
    musicbrainzngs.set_useragent("KLAP-CDDBAdd", "0.3", "*****@*****.**")

    disc = discid.read(sys.argv[1])
    try:
        result = musicbrainzngs.get_releases_by_discid(disc.id,
                                                       includes=["artists","recordings","release-groups"])
    except musicbrainzngs.ResponseError:
        print "Couldn't find that disc in the online database, sorry!"
        return None
    else:
        print "Found disc {}".format(disc.id)
        subd = None
        if result.get("disc"):
            if len(result['disc']['release-list']) == 0:
                print "Found the disc id, but it didn't have any releases..."
                return None
            print "Found a musicbrainz release id"
            open_url(KLAP_MB_URL.format(result['disc']['release-list'][0]['id']))
            sys.exit()
        elif result.get("cdstub"):
            artist = normalize(result["cdstub"]["artist"])
            album = normalize(result["cdstub"]["title"])
            subd = result["cdstub"]
            c = 1
            for track in subd['track-list']:
                title = normalize(track['title'])
                tartist = normalize(track['artist'])
                d = {'number': c,
                     'title': title}
                if tartist != artist:
                    d['artist'] = tartist
                tracks.append(d)
                c += 1
    
    # Make sure the info is safe for KLAP
    artist = artist
    album = album
    
    # Make the dict
    obj = {'artist': artist,
           'album': album,
           'tracks': tracks,
          }
    return obj
コード例 #16
0
ファイル: disc_info.py プロジェクト: mathgl67/Afro
def disc_info_fetch(disc_id=None):
    if not disc_id:
        disc = _read_disc()
        disc_id = disc.id

    musicbrainzngs.set_useragent(afro.name, afro.version, afro.url)
    try:
        return musicbrainzngs.get_releases_by_discid(disc_id, includes=['artists', 'recordings'])
    except musicbrainzngs.ResponseError as exception:
        return None
コード例 #17
0
ファイル: main.py プロジェクト: RecursiveForest/whipper
def main():
    # set user agent
    musicbrainzngs.set_useragent("whipper", whipper.__version__,
                                 "https://github.com/JoeLametta/whipper")

    try:
        server = config.Config().get_musicbrainz_server()
    except KeyError, e:
        sys.stderr.write('whipper: %s\n' % e.message)
        sys.exit()
コード例 #18
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)
コード例 #19
0
ファイル: discogs.py プロジェクト: M0rg4n/geordi
 def automatic_item_matches(self, data):
     musicbrainzngs.set_useragent('geordi', 'discogs-item-matches', 'http://geordi.musicbrainz.org')
     try:
         url_data = musicbrainzngs.browse_urls(
             resource='http://www.discogs.com/release/%s' % data['discogs']['release']['_id'],
             includes=['release-rels'])
         mbids = [release['release']['id'] for release in url_data['url']['release-relation-list']]
         return {'release': mbids}
     except:
         return {'unmatch': []}
コード例 #20
0
    def test_set_useragent(self):
        """ When a useragent is set it is sent with the request """
        musicbrainzngs.set_useragent("caa-test", "0.1")

        resp = b'{"images":[]}'
        self.opener = _common.FakeOpener(resp)
        musicbrainzngs.compat.build_opener = lambda *args: self.opener
        res = caa.get_image_list("8ec178f4-a8e8-4f22-bcba-1964466ef214")

        headers = dict(self.opener.headers)
        self.assertTrue("User-agent" in headers)
        self.assertEqual("caa-test/0.1 python-musicbrainzngs/%s" % _version, headers["User-agent"])
コード例 #21
0
ファイル: releases.py プロジェクト: Sinkler/music
 def handle(self, **options):
     musicbrainzngs.set_useragent(settings.MB_APP, settings.MB_VERSION, settings.MB_CONTACT)
     if options['changed']:
         artists = Artist.objects.exclude(lastfm_mbid=F('mbid'))
     else:
         artists = Artist.objects\
             .filter(lastfm_playcount__gt=settings.LASTFM_MIN_PLAY_COUNT, mbid__gt='')\
             .order_by('lastfm_playcount')
     for artist in artists:
         print 'ARTIST: ', artist.title
         if artist.updated and not (now() - artist.updated).days:
             print 'updated recently'
             continue
         if options['changed']:
             # deleting old releases and albums
             artist.max_year = 0
             for old_release in artist.releases.all():
                 old_release.delete()
             for old_album in artist.albums.all():
                 old_album.delete()
             artist.save()
         # getting new releases
         for release_type in settings.MB_RELEASE_TYPES:
             limit = 100
             offset = 0
             parsed = 0
             cont = True
             while cont:
                 releases = musicbrainzngs.browse_releases(artist=artist.mbid,
                                                           release_type=[release_type],
                                                           release_status=settings.MB_RELEASE_STATUSES,
                                                           limit=limit,
                                                           offset=offset)
                 for release in releases['release-list']:
                     parsed += 1
                     album, created = Release.objects.get_or_create(mbid=release.get('id'), artist=artist)
                     if created:
                         print 'NEW: ', release.get('id'), release.get('title')
                         album.date = release.get('date')
                         if album.date:
                             album.year = release.get('date').split('-')[0]
                         album.title = release.get('title')
                         album.country = release.get('country')
                         album.type = release_type
                         album.save()
                 if parsed < releases['release-count']:
                     offset += limit
                 else:
                     cont = False
         artist.updated = now()
         artist.save()
     print 'FINISHED'
コード例 #22
0
def main():
	m.set_useragent("application", "0.01", "http://example.com")
	print m.get_artist_by_id("952a4205-023d-4235-897c-6fdb6f58dfaa", [])
	#print m.get_label_by_id("aab2e720-bdd2-4565-afc2-460743585f16")
	#print m.get_release_by_id("e94757ff-2655-4690-b369-4012beba6114")
	#print m.get_release_group_by_id("9377d65d-ffd5-35d6-b64d-43f86ef9188d")
	#print m.get_recording_by_id("cb4d4d70-930c-4d1a-a157-776de18be66a")
	#print m.get_work_by_id("7e48685c-72dd-3a8b-9274-4777efb2aa75")

	#print m.get_releases_by_discid("BG.iuI50.qn1DOBAWIk8fUYoeHM-")
	#print m.get_recordings_by_isrc("GBAYE9300106")

	m.auth("", "")
コード例 #23
0
ファイル: models.py プロジェクト: swist/ripple
	def GetMusicBrainz(self):
		mbrainz.set_useragent("Example music app", "0.1", "http://example.com/music")
		result = mbrainz.search_artists(self.name)['artist-list'][0]
		# for result in results:
		#   if int(result['ext:score']) > 75:
		#       break
		#print result
		self.musicbrainz_id = result['id']
		self.mbrainz_cache = mbrainz.get_artist_by_id(self.musicbrainz_id, ['artist-rels', 'url-rels'])['artist']
		if 'url-relation-list' in self.mbrainz_cache:
			self.social_media = self.mbrainz_cache.pop('url-relation-list')
		if 'artist-relation-list' in self.mbrainz_cache:
			self.aliases = self.mbrainz_cache.pop('artist-relation-list')
コード例 #24
0
ファイル: lastfm.py プロジェクト: thomwiggers/onebot
 def __init__(self, bot):
     """Initialise the plugin"""
     self.bot = bot
     self.log = bot.log.getChild(__name__)
     self.config = bot.config.get(__name__, {})
     musicbrainzngs.set_useragent(__name__, 1.0)
     try:
         self.app = lfm.App(self.config['api_key'],
                            self.config['api_secret'],
                            self.config.get('cache_file'))
     except KeyError:  # pragma: no cover
         raise Exception(
             "You need to set the Last.FM api_key and api_scret "
             "in the config section [{}]".format(__name__))
コード例 #25
0
def main():
    # set user agent
    musicbrainzngs.set_useragent("whipper", configure.version,
                                 "https://github.com/JoeLametta/whipper")
    # register plugins with pkg_resources
    distributions, _ = pkg_resources.working_set.find_plugins(
        pkg_resources.Environment([directory.data_path('plugins')])
    )
    map(pkg_resources.working_set.add, distributions)
    try:
        ret = Whipper(sys.argv[1:], os.path.basename(sys.argv[0]), None).do()
    except SystemError, e:
        sys.stderr.write('whipper: error: %s\n' % e.args)
        return 255
コード例 #26
0
 def __init__(self, option_config_json):
     # If you plan to submit data, authenticate
     # musicbrainzngs.auth(option_config_json.get('MediaBrainz','User').strip(),
     # option_config_json.get('MediaBrainz','Password').strip())
     musicbrainzngs.set_useragent("MediaKraken_Server", common_version.APP_VERSION,
                                  "[email protected] "
                                  "https://https://github.com/MediaKraken/MediaKraken_Deployment")
     # If you are connecting to a development server
     if option_config_json['MusicBrainz']['Host'] is not None:
         if option_config_json['MusicBrainz']['Host'] != 'Docker':
             musicbrainzngs.set_hostname(option_config_json['MusicBrainz']['Host'] + ':'
                                         + option_config_json['MusicBrainz']['Port'])
         else:
             musicbrainzngs.set_hostname('mkmusicbrainz:5000')
コード例 #27
0
ファイル: mb.py プロジェクト: noam09/headphones
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
コード例 #28
0
def search_mb():
    musicbrainzngs.set_useragent('music-downloader', '0.1')
    criteria = {}
    if len(query_comps) > 1:
        criteria = {'artist': clear_comps[0], 'recording': clear_comps[1]}
    try:
        if criteria:
            recordings = musicbrainzngs.search_recordings(limit=10, **criteria)
        else:
            recordings = musicbrainzngs.search_recordings(limit=10, query=clear_query)
    except Exception as e:
        print "Failure: Something went wrong"
        sys.exit()
    for recording in recordings['recording-list']:
        yield get_mb_info(recording)
コード例 #29
0
ファイル: media.py プロジェクト: jrwang/mediagrab
    def mb_shit(self, mb_id):
        self.mb = mb_id
        import musicbrainzngs
        musicbrainzngs.set_useragent('a','.1','foo')
        r = musicbrainzngs.get_release_by_id(self.mb, includes=["artists", "recordings"])['release']
        d = {}
        all_tracklist = []
        for disc in r['medium-list']:
            all_tracklist += disc['track-list']

        d['trackCount'], d['artistName'], d['releaseDate'], d['primaryGenreName'], d['collectionPrice'] = len(all_tracklist), r['artist-credit'][0]['artist']['name'], str(r['date'])[0:4] + '-01-01T00:00:00Z', 'MB', None
        d['trackDetails'] = [{'trackTimeMillis': int(rec['recording']['length'])} for rec in all_tracklist]
        self.mb_details = d
        self.title = r['title']
        self.details = [{'artistName': d['artistName'], 'releaseDate': d['releaseDate']}]
コード例 #30
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 = []
コード例 #31
0
    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"])
else:
コード例 #32
0
ファイル: general_methods.py プロジェクト: aruskin/MUMT-621
 def __init__(self, app, version):
     musicbrainzngs.set_useragent(app=app, version=version)
コード例 #33
0
 def __init__(self):
     client_credentials_manager = SpotifyClientCredentials()
     self.sp = spotipy.Spotify(
         client_credentials_manager=client_credentials_manager)
     musicbrainzngs.set_useragent('playlists-producer', '1.0',
                                  '*****@*****.**')
コード例 #34
0
import csv
import requests
import argparse
import os
import re
import datetime
from datetime import timedelta
from calendar import monthrange
import musicbrainzngs
musicbrainzngs.set_useragent('mbid_correcter', 0.1, '*****@*****.**')
import pylast


def date_prcsr(rls_lst):
    """Takes list of releases, returns 
    - earliest date (9999-9-9 if no date)
    - level with highest resolution (0 if no date)
    - highest resolution of earliest date (-1 if no date)
    - if earliest date earlier than higher resolved date: time difference between earliest and highest resolved date (0 if no date or if highest resolved date is earliest)
    - length of release list
    - length of release list with dates
    """

    rlss_long = []
    rlss_medm = []
    rlss_shrt = []

    len_rls_lst_ttl = len(rls_lst)

    for i in rls_lst:
        try:
コード例 #35
0
def init():
    import settings
    import server
    import database

    settings_set = settings.SettingsSet('plugins.base_extra.music.album_art')

    settings_set.register_key('enable', True)
    settings_set.register_key('local.enable', True)

    settings_set.register_key('lastfm.enable', False)
    settings_set.register_key('lastfm.api_key', '')

    settings_set.register_key('musicbrainz.enable', False)

    settings_set.register_key('cache.enable', True)
    settings_set.register_key('cache.path', '~/.cache/pmms/albumart')

    if settings_set.get_key('enable'):
        from plugins.base.music.models import Album
        from flask import send_file
        import os

        def load_cache(album: Album):
            cache_path = os.path.expanduser(settings_set.get_key('cache.path'))
            full_path = os.path.join(
                cache_path, '%s - %s.jpg' % (album.artist.name, album.name))
            if os.path.isfile(full_path):
                with open(full_path, 'rb') as f:
                    return BytesIO(f.read())

        def write_cache(art: BytesIO, album: Album):
            cache_path = os.path.expanduser(settings_set.get_key('cache.path'))
            if not os.path.isdir(cache_path):
                os.makedirs(cache_path)

            with open(
                    os.path.join(
                        cache_path,
                        '%s - %s.jpg' % (album.artist.name, album.name)),
                    'wb') as f:
                f.write(art.read())

        @server.app.route(
            '/api/artists/<int:_artist_id>/albums/<int:album_id>/art')
        @server.app.route('/api/albums/<int:album_id>/art')
        def get_album_art(album_id: int, _artist_id: int = None):
            try:
                album = database.db.session.query(Album).filter_by(
                    id=album_id).one()
            except NoResultFound:
                return jsonify({'message': 'Album does not exist'}), 404

            art = None

            enable_cache = settings_set.get_key('cache.enable')

            if enable_cache:
                art = load_cache(album)

            do_cache = True
            if art:
                do_cache = False

            if not art and settings_set.get_key('local.enable'):
                art = fetch_local_art(album)
            if not art and settings_set.get_key('musicbrainz.enable'):
                art = fetch_musicbrainz_art(album)
            if not art and settings_set.get_key('lastfm.enable'):
                art = fetch_lastfm_art(album)

            if art:
                if enable_cache and do_cache:
                    write_cache(art, album)

                art.seek(0)  # Writing to cache moves stream pos to end

                return send_file(art, mimetype='image/jpeg')
            else:
                return jsonify({'message': 'Failed to find art'}), 404

        if settings_set.get_key('musicbrainz.enable'):
            import musicbrainzngs as mb
            mb.set_useragent('pmms', '1.0.0')
コード例 #36
0
ファイル: fixalbum.py プロジェクト: dbach/Scripts
#!/usr/bin/python

## See http://www.libertypages.com/clarktech/?p=6182 for discussion

from __future__ import print_function
import string, re
from appscript import *
import musicbrainzngs as m
import nltk
import optparse

m.set_useragent(
    "application",
    "0.1",
    "https://github.com/alastair/python-musicbrainz-ngs/",
)

verbose = True


def getinfo(release, song, album, artist):
    ac = release['artist-credit']
    rl = release['release-list']

    newartist = release['artist-credit'][0]['artist']['name']

    distance = nltk.metrics.edit_distance(newartist, artist)
    if (distance > 5):
        if verbose:
            print(u"     ## Wrong artist: {}".format(newartist))
        return (release['title'], newartist, "", 9999)
コード例 #37
0
 def test_client(self):
     musicbrainzngs.set_useragent("testapp", "0.1", "*****@*****.**")
     musicbrainz._mb_request(path="foo", client_required=True)
     self.assertTrue("testapp" in _common.opener.myurl)
コード例 #38
0
    for item, spotify_id in zip(response, iterator):
        df_dict = {'name': spotify_id}
        try:
            for key, value in zip(item.keys(), item.values()):
                df_dict[key] = [value]
        except:
            print('couldn\'t find {}'.format(spotify_id))
        hits.append(pd.DataFrame(df_dict, index=[spotify_id]))
    df_hits = pd.concat(hits, sort=True)
    df_hits.to_csv(path, sep='\t', encoding='utf-8', index=False)
    return True


# Set musicbrainz crednetials
musicbrainzngs.set_rate_limit(limit_or_interval=1.0, new_requests=1)
musicbrainzngs.set_useragent('hit_predictor', '0.0.1',
                             '*****@*****.**')
musicbrainzngs.set_format(fmt='xml')


def musicbrainz_ids_by_isrc():
    res = musicbrainzngs.search_recordings(query='')
    res = musicbrainzngs.browse_events(
        area=None,
        artist='650e7db6-b795-4eb5-a702-5ea2fc46c848',
        place=None,
        includes=[],
        limit=100,
        offset=None)
    pp.pprint(res)

コード例 #39
0
import musicbrainzngs

musicbrainzngs.set_useragent('BustersPractical3', 0.5, contact='*****@*****.**')

artist_id = "03098741-08b3-4dd7-b3f6-1b0bfa2c879c"

result = musicbrainzngs.get_artist_by_id(artist_id, includes=["tags"])
print result
コード例 #40
0
'''
This program calls a couple of key functions to:
	- scrape, parse and store all guitar tabs from Ultimate-Guitar.com using scrapy
	- embellish the database (using MusicBrainzDB) with artist and song information for each tab
'''

import os, time

from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, BigInteger, SmallInteger, String
from ugscrape.SQLsetup import FactTab

import musicbrainzngs as mb
mb.set_useragent("Ultimate Guitar analyser", "0.1", "")
'''Calls scrapy to crawl Ultimate-Guitar.com and times the process'''


def scrape_UG():
    start = time.time()
    os.system("C:\\Python27\\Scripts\\scrapy crawl ultimateguitar")
    print(time.time() - start)

    # Diagnostics
    os.system("ls")


'''Creates DimSong table to store MusicBrainz information'''

コード例 #41
0
    def setUp(self):
        self.opener = _common.FakeOpener("<response/>")
        musicbrainzngs.compat.build_opener = lambda *args: self.opener

        musicbrainzngs.set_useragent("a", "1")
        musicbrainzngs.set_rate_limit(False)
コード例 #42
0
from optparse import OptionParser
import musicbrainzngs
from musicbrainzngs.compat import is_py2
import sys
import pprint

__author__      = "Paul Harrison'"
__title__       = "Music Brainz utilities"
__description__ = "Various utilities using the musicbrainzngs python bindings to access the MB database"
__version__     = "0.1"

debug = False

musicbrainzngs.set_useragent(
    "MythTV",
    "0.28",
    "https://www.mythtv.org",
)

#musicbrainzngs.set_hostname("musicbrainz.org")
#musicbrainzngs.set_hostname("music.peavers.com:5000")
musicbrainzngs.set_hostname("musicbrainz-mirror.eu:5000")

def log(debug, txt):
    if debug:
        print(txt)

def convert_etree(etostr):
    """lxml.etree.tostring is a bytes object in python3, and a str in python2.
    """
    if is_py2:
コード例 #43
0
import musicbrainzngs
import re
import traceback
from urlparse import urljoin

from beets import logging
import beets.autotag.hooks
import beets
from beets import util
from beets import config

VARIOUS_ARTISTS_ID = '89ad4ac3-39f7-470e-963a-56509c546377'
BASE_URL = 'http://musicbrainz.org/'

musicbrainzngs.set_useragent('beets', beets.__version__,
                             'http://beets.radbox.org/')


class MusicBrainzAPIError(util.HumanReadableException):
    """An error while talking to MusicBrainz. The `query` field is the
    parameter to the action and may have any type.
    """
    def __init__(self, reason, verb, query, tb=None):
        self.query = query
        if isinstance(reason, musicbrainzngs.WebServiceError):
            reason = 'MusicBrainz not reachable'
        super(MusicBrainzAPIError, self).__init__(reason, verb, tb)

    def get_message(self):
        return u'{0} in {1} with query {2}'.format(self._reasonstr(),
                                                   self.verb, repr(self.query))
コード例 #44
0
from urllib.error import HTTPError
import musicbrainzngs
import requests_cache
from musicbrainzngs.musicbrainz import ResponseError
from flask import current_app
from madnessbracket import create_app
from madnessbracket.utilities.logging_handlers import log_missing_info

app = create_app()
app.app_context().push()

requests_cache.install_cache()

musicbrainzngs.set_useragent(
    *current_app.config['MUSIC_BRAINZ_USER_AGENT'].split(','))


def music_brainz_get_release_id_via_release_group(release_group_id: str):
    """get release id from a release_group id
    param:
        release_group_id (str): release group id from Music Brainz

    return:
        (str): release id
    """
    try:
        release_group_info = musicbrainzngs.get_release_group_by_id(
            release_group_id, includes=['releases'])
    except (HTTPError, ResponseError) as e:
        info = f"RELEASE GROUP ID ({release_group_id}   ERROR({e}))"
        log_missing_info(info)
コード例 #45
0
ファイル: art_apis.py プロジェクト: baloothebear4/mDisplay
 def __init__(self, keys):
     musicbrainzngs.set_useragent(
         "mDisplay",
         "0.1",
         "https://github.com/baloothebear4/mVista/",)
     musicbrainzngs.auth(keys.passes['musicBrainz.USERNAME'], keys.passes['musicBrainz.TOKEN'])
コード例 #46
0
import pandas as pd
import numpy as np
import musicbrainzngs
import geo_nomi

musicbrainzngs.set_useragent(
    "python-musicbrainzngs-example",
    "0.1",
"https://github.com/bramochsendorf",)

genre = 'electro'

# load in data
df = pd.read_pickle('/data1/python/data_science/lastfm/topartists_'+genre)
# limit to certain range?
#df = df.iloc[0:2]

# first we need to filter out all rows which do not have a musicbrainz artist ID 
a = df['mbid']
df = df[a.notnull()]

# obtain artist ids, initiate counter and open string with results
artist_id = df['mbid']
counter = 0
total = []

# now loop over all artist IDs
for art in artist_id:
    counter += 1
    print 'Loop = '+np.str_(counter)
    # get artist info from the API (through artist ID)
コード例 #47
0
from musicbrainzngs import get_artist_by_id, get_label_by_id, get_place_by_id, get_series_by_id, set_useragent
from musicbrainzngs.musicbrainz import ResponseError
from time import sleep
from json import dumps
from pandas import DataFrame, read_csv
from codecs import open

set_useragent('kp_lister', '0.0.1', contact='*****@*****.**')
with open("mbids_contemporary_music.txt", "r") as f:
    mbids = f.readlines()

records = []
for mbid in set(mbids):
    try:
        mb_data = get_artist_by_id(mbid.strip().split("/")[-1],
                                   includes=['url-rels'])["artist"]
    except ResponseError:
        try:
            mb_data = get_place_by_id(mbid.strip().split("/")[-1],
                                      includes=['url-rels'])["place"]
        except ResponseError:
            try:
                mb_data = get_label_by_id(mbid.strip().split("/")[-1],
                                          includes=['url-rels'])["label"]
            except ResponseError:
                mb_data = get_series_by_id(mbid.strip().split("/")[-1],
                                           includes=['url-rels'])["series"]
    print(mb_data)
    data = {
        "name":
        mb_data["name"],
コード例 #48
0
from .attribute import Attribute
import json
import warnings
import urllib

import musicbrainzngs as mb

mb.set_useragent("Makam corpus metadata", "1.2.0", "compmusic.upf.edu")


class WorkMetadata(object):
    def __init__(self, get_recording_rels=True, print_warnings=None):
        self.get_recording_rels = get_recording_rels
        self.print_warnings = print_warnings

    def from_musicbrainz(self, mbid):
        included_rels = (['artist-rels', 'recording-rels']
                         if self.get_recording_rels else ['artist-rels'])
        work = mb.get_work_by_id(mbid, includes=included_rels)['work']

        data = {
            'makam': [],
            'form': [],
            'usul': [],
            'title': work['title'],
            'mbid': mbid,
            'composer': dict(),
            'lyricist': dict(),
            'url': 'http://musicbrainz.org/work/' + mbid,
            'language': ''
        }
コード例 #49
0
ファイル: tagSearch.py プロジェクト: bhoang9/sortMp3
#file contains function to search database for title and artist tags
#still need to test

import musicbrainzngs as musicData
import mutagen
import os
import Levenshtein
from mutagen.mp3 import EasyMP3
from mutagen.easyid3 import EasyID3
from mutagen import MutagenError

musicData.set_useragent("dataSearch_test", "0.1")

#search database for a specific artist
#result = musicData.search_artists(artist="green day")

#search database for a specific song, get first 5 results
#result2 = musicData.search_recordings("morgan page the longest road deadmau5 remix", limit=5)

#TESTING: printing from artist search
#for artists in result['artist-list']:
#        print(artists['name'])

#TESTING: if search yields no results
#if(result2['recording-list'] == []):
#    print("empty")

#TESTING: printing from song search
#for recordings in result2['recording-list']:
#        print(recordings['title'] + " | artist " + recordings['artist-credit-phrase'])
コード例 #50
0
#!/usr/bin/python
# -*- coding: utf-8 -*-

import requests
import base64
from xml.dom.minidom import Document
import xml.etree.ElementTree as ET
from Utils import *
import musicbrainzngs as m

tmdb_apiKey = base64.b64decode("NDc2N2I0YjJiYjk0YjEwNGZhNTUxNWM1ZmY0ZTFmZWM=")
m.set_useragent("script.skin.helper.service", "0.01", "https://github.com/marcelveldt/script.skin.helper.service")

def getPVRThumbs(title,channel,type="channels",path="",genre=""):
    cacheFound = False
    ignore = False
    artwork = {}
    pvrThumbPath = None
        
    #should we ignore this path ?
    ignoretitles = WINDOW.getProperty("SkinHelper.ignoretitles")
    ignorechannels = WINDOW.getProperty("SkinHelper.ignorechannels")
    stripwords = WINDOW.getProperty("SkinHelper.stripwords")
    if ignorechannels:
        for item in ignorechannels.split(";"):
            if item.lower() == channel.lower(): ignore = True
    if ignoretitles:
        for item in ignoretitles.split(";"):
            if item.lower() in title.lower(): ignore = True
    if stripwords:
        for word in stripwords.split(";"): title = title.replace(word,"")
コード例 #51
0
# 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 musicbrainzngs as mb
import os
import json


def pprint(data):
    print json.dumps(data, sort_keys=True, indent=4, separators=(',', ': '))


mb.set_useragent('eac-cue-submit-isrc', '1', '*****@*****.**')

user = raw_input("MB Username: "******"MB Password: "******"Invalid authentication!")

delete_list = []
for directory, directories, filenames in os.walk(u"."):
    for filename in filenames:
        path = os.path.realpath(os.path.join(directory, filename))

        if os.path.splitext(path)[1] != u".cue":
            continue
コード例 #52
0
ファイル: main.py プロジェクト: f1remind/medianotiPy
def main():
    musicbrainzngs.set_useragent(NAME, VERSION)

    artists = get_local_artists()
    cache = get_cache()
    missing_artists = []

    new_releases = []
    for artist in artists:
        if artist in cache:
            artistid = cache[artist]['id']
        else:
            results = musicbrainzngs.search_artists(artist=artist)
            if results['artist-count'] > 0:
                artistid = results['artist-list'][0]['id']
                if results['artist-list'][0]['name'].upper() != artist.upper():
                    print(f'Artist {artist} not found')
                    missing_artists.append(artist)
                    continue
            else:
                print(f'Artist {artist} not found')
                continue

        print(f'Getting Data for {artist}')
        releases = musicbrainzngs.get_artist_by_id(\
            artistid, includes=["release-groups"], \
            release_type=["album"])['artist']['release-group-list']
        releases = sorted(releases, key=lambda x: x['first-release-date'])
        relevant_releases = []
        for release in releases:

            if release['type'] == 'Compilation':
                continue
            if "secondary-type-list" in release and 'Live' in release[
                    'secondary-type-list']:
                continue

            release['artist'] = artist
            relevant_releases.append(release)
            #print(f'\t{release["title"]}')

            if artist in cache:
                new_release = True
                for cacherelease in cache[artist]['release-group-list']:
                    if cacherelease['id'] == release['id']:
                        new_release = False
                if new_release:
                    print(f"New release! {release['title']} by {artist}")
                    cache[artist]['release-group-list'].append(release)
                    new_releases.append(release)
            else:
                cache[artist] = {
                    'id': artistid,
                    'release-group-list': relevant_releases
                }
    print(f'{len(new_releases)} new releases')
    for release in new_releases:
        print(f'{release["artist"]} - {release["title"]}')
    if len(missing_artists):
        print()
        print("Couldn't find these artists:")
        for artist in missing_artists:
            print(f'\t-{artist}')
    save_cache(cache)
    return True
コード例 #53
0
def init(app_name, app_version, hostname=None):
    # We need to identify our application to access the MusicBrainz webservice.
    # See https://python-musicbrainzngs.readthedocs.org/en/latest/usage/#identification for more info.
    musicbrainzngs.set_useragent(app_name, app_version)
    if hostname:
        musicbrainzngs.set_hostname(hostname)
コード例 #54
0
ファイル: cdda.py プロジェクト: Rsantct/pe.audio.sys
def read_disc_metadata(device=CDROM_DEVICE):
    def simple_md(disc):
        """ For disc not found, we can derive the tracks and tracks length
            from the 'disc' object properties.
        """
        print(
            f'(cdda.py) {disc.last_track_num} tracks found on discid \'{disc.id}\''
        )
        # https://musicbrainz.org/doc/Development/XML_Web_Service/Version_2#discid
        # The toc consists of the following:
        #   First track (always 1)
        #   total number of tracks
        #   sector offset of the leadout (end of the disc
        #   a list of sector offsets for each track, beginning with track 1 (generally 150 sectors)
        #
        # Example of TOC for a 7 tracks disc:
        # disc.toc_string: '1 7 235745 150 40742 77847 108042 118682 154277 191952'
        toc = disc.toc_string.split()

        # A second of CD-AUDIO has 75 frames (or sectors) -wikipedia-
        track_sectors = toc[3:] + [toc[2]]
        track_sectors = [int(x) for x in track_sectors]
        for i in range(len(track_sectors)):
            if i == 0:
                continue
            trackNum = i
            trackLen = (track_sectors[i] - track_sectors[i - 1]) / 75
            md[str(trackNum)] = {
                'title': 'track ' + f'{trackNum}'.zfill(2),
                'length': msec2string(trackLen * 1e3)
            }

        return md

    # will complete md with info retrieved from musicbrainz
    md = CDDA_INFO_TEMPLATE.copy()

    mz.set_useragent('tmp', '0.1', 'dummy@mail')

    try:
        disc = discid.read(device)
        md['discid'] = disc.id
        global CDDA_DISCID
        CDDA_DISCID = disc.id
    except:
        print('(cdaa.py) not CDDA found')
        return md

    try:
        result = mz.get_releases_by_discid(disc.id,
                                           includes=['artists', 'recordings'])
    except mz.ResponseError:
        print('(cdda.py) disc not found or bad response')
        return simple_md(disc)

    # most of discs are 'disc' musicbrainz kinf of
    if result.get('disc'):

        print(f'(cdda.py) musicbrainz got \'disc\': {disc.id}')

        mz_md = result['disc']['release-list'][0]

        md['artist'] = mz_md['artist-credit-phrase']

        md['album'] = mz_md['title']

        track_list = mz_md['medium-list'][0]['track-list']

    # but somo are 'cdstub' musicbrainz kind of
    elif result.get('cdstub'):

        print(f'(cdda.py) musicbrainz got \'cdstub\': {disc.id}')

        mz_md = result['cdstub']

        if 'artist' in mz_md:
            md['artist'] = mz_md['artist']
        elif 'artist-credit-phrase' in mz_md:
            md['artist'] = mz_md['artist-credit-phrase']

        if 'title' in mz_md:
            md['album'] = mz_md['title']

        # (!) pending on investigate more on tracks under 'cdstub'
        if 'track-list' in mz_md:
            track_list = mz_md['track-list']
        else:
            track_list = []

    # Lets complete our track list structure inside the 'md' template
    for pos, track in enumerate(track_list):

        # Retrieve track length
        # from normal 'disc':
        if 'recording' in track and 'length' in track['recording']:
            lengthStr = msec2string(float(track['recording']['length']))
        # from some 'cdstub':
        elif 'length' in track:
            lengthStr = msec2string(float(track['length']))
        # from some 'cdstub':
        elif 'track_or_recording_length' in track:
            lengthStr = msec2string(float(track['track_or_recording_length']))
        else:
            lengthStr = msec2string(0.0)

        # Retrieve track title
        if 'recording' in track and 'title' in track['recording']:
            track_title = track['recording']['title']
        elif 'title' in track:
            track_title = track['title']

        # adding to our metadata disc structure
        md[str(pos + 1)] = {'title': track_title, 'length': lengthStr}

    return md
コード例 #55
0
import musicbrainzngs
import re
import unicodedata
import az_scraper as az

musicbrainzngs.set_useragent(
    "python-musicbrainzngs-example",
    "0.1",
    "https://github.com/alastair/python-musicbrainzngs/",
)


def get_song_names(artist_dict):
    '''
    This function takes an artist dictioanry as supplied by the MusicBrainz API
    :param artist_dict: dictionary as retreived from musicbrainz api
    :return: dictionary of song names from artist
    '''
    artist_dict = {}
    # Do STUFF with the song names
    artists = ['Caro Emerald']
    song_names = {}

    #Only test code can be commented out when we use artist_songs.py
    for a in artists:
        artist_dict[a] = musicbrainzngs.search_recordings(artist=a, limit=25)

    #For all artists get the song names
    for a in artists:
        print(artist_dict)
        for recording in artist_dict[a]['recording-list']:
コード例 #56
0
def create_app(debug=None):
    app = CustomFlask(
        import_name=__name__,
        use_flask_uuid=True,
    )

    # Configuration
    load_config(app)

    if debug is not None:
        app.debug = debug

    if app.debug and app.config['SECRET_KEY']:
        app.init_debug_toolbar()

    # Logging
    app.init_loggers(file_config=app.config.get('LOG_FILE'),
                     email_config=app.config.get('LOG_EMAIL'),
                     sentry_config=app.config.get('LOG_SENTRY')
                     )

    # Database connection
    from db import init_db_engine
    init_db_engine(app.config['SQLALCHEMY_DATABASE_URI'])

    # Cache
    if 'REDIS_HOST' in app.config and\
       'REDIS_PORT' in app.config and\
       'REDIS_NAMESPACE' in app.config and\
       'REDIS_NS_VERSIONS_LOCATION' in app.config:
        if not os.path.exists(app.config['REDIS_NS_VERSIONS_LOCATION']):
            os.makedirs(app.config['REDIS_NS_VERSIONS_LOCATION'])

        from brainzutils import cache
        cache.init(
            host=app.config['REDIS_HOST'],
            port=app.config['REDIS_PORT'],
            namespace=app.config['REDIS_NAMESPACE'],
            ns_versions_loc=app.config['REDIS_NS_VERSIONS_LOCATION'])
    else:
        raise Exception('One or more redis cache configuration options are missing from config.py')

    # Add rate limiting support
    @app.after_request
    def after_request_callbacks(response):
        return inject_x_rate_headers(response)

    # check for ratelimit config values and set them if present
    if 'RATELIMIT_PER_IP' in app.config and 'RATELIMIT_WINDOW' in app.config:
        set_rate_limits(app.config['RATELIMIT_PER_IP'], app.config['RATELIMIT_PER_IP'], app.config['RATELIMIT_WINDOW'])

    # MusicBrainz
    import musicbrainzngs
    from db import SCHEMA_VERSION
    musicbrainzngs.set_useragent(app.config['MUSICBRAINZ_USERAGENT'], SCHEMA_VERSION)
    if app.config['MUSICBRAINZ_HOSTNAME']:
        musicbrainzngs.set_hostname(app.config['MUSICBRAINZ_HOSTNAME'])

    # OAuth
    from webserver.login import login_manager, provider
    login_manager.init_app(app)
    provider.init(app.config['MUSICBRAINZ_CLIENT_ID'],
                  app.config['MUSICBRAINZ_CLIENT_SECRET'])

    # Error handling
    from webserver.errors import init_error_handlers
    init_error_handlers(app)

    # Static files
    import static_manager

    # Template utilities
    app.jinja_env.add_extension('jinja2.ext.do')
    from webserver import utils
    app.jinja_env.filters['date'] = utils.reformat_date
    app.jinja_env.filters['datetime'] = utils.reformat_datetime
    # During development, built js and css assets don't have a hash, but in production we use
    # a manifest to map a name to name.hash.extension for caching/cache busting
    if app.debug:
        app.context_processor(lambda: dict(get_static_path=static_manager.development_get_static_path))
    else:
        static_manager.read_manifest()
        app.context_processor(lambda: dict(get_static_path=static_manager.manifest_get_static_path))

    _register_blueprints(app)

    # Admin section
    from flask_admin import Admin
    from webserver.admin import views as admin_views
    admin = Admin(app, index_view=admin_views.HomeView(name='Admin'))
    admin.add_view(admin_views.AdminsView(name='Admins'))

    @app.before_request
    def prod_https_login_redirect():
        """ Redirect to HTTPS in production except for the API endpoints
        """
        if urlparse.urlsplit(request.url).scheme == 'http' \
                and app.config['DEBUG'] == False \
                and app.config['TESTING'] == False \
                and request.blueprint not in ('api', 'api_v1_core', 'api_v1_datasets', 'api_v1_dataset_eval'):
            url = request.url[7:] # remove http:// from url
            return redirect('https://{}'.format(url), 301)


    @app.before_request
    def before_request_gdpr_check():
        # skip certain pages, static content and the API
        if request.path == url_for('index.gdpr_notice') \
          or request.path == url_for('login.logout') \
          or request.path.startswith('/_debug') \
          or request.path.startswith('/static') \
          or request.path.startswith(API_PREFIX):
            return
        # otherwise if user is logged in and hasn't agreed to gdpr,
        # redirect them to agree to terms page.
        elif current_user.is_authenticated and current_user.gdpr_agreed is None:
            return redirect(url_for('index.gdpr_notice', next=request.full_path))

    return app
コード例 #57
0
ファイル: cdrom.py プロジェクト: l0k9j8/mopidy-cd
 def __init__(self):
     musicbrainzngs.set_useragent(Extension.dist_name, Extension.version)
コード例 #58
0
import unidecode
from compmusic.dunya import logger

# this code needed if pycompmusic is copied (not installed as dependecy) in parent URI
parentDir = os.path.abspath(
    os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])),
                 os.path.pardir, os.path.pardir))
pathPyCompMusic = os.path.join(parentDir, 'pycompmusic')
if not pathPyCompMusic in sys.path:
    sys.path.append(pathPyCompMusic)

import compmusic.file
from compmusic.dunya.makam import download_mp3
from compmusic.dunya.conn import set_token

mb.set_useragent("Dunya", "0.1")
mb.set_rate_limit(False)
mb.set_hostname("musicbrainz.sb.upf.edu")

set_token('0d8cd9be63c10c5dc67f70e1052acec836de29bd')


def storeScoreAndAudio(symbTrNameNoExt, recIDs, rootTargetdir):
    '''
    params symbTrNameNoExt
    '''

    symbTrNameNoExt = os.path.basename(symbTrNameNoExt)

    targetDir = makeDir(symbTrNameNoExt, rootTargetdir)
    saveScores(symbTrNameNoExt, symbTrDir, targetDir)
コード例 #59
0
ファイル: mb.py プロジェクト: tompipe/beets
import beets.autotag.hooks
import beets
from beets import util
from beets import config
import six

VARIOUS_ARTISTS_ID = '89ad4ac3-39f7-470e-963a-56509c546377'

if util.SNI_SUPPORTED:
    BASE_URL = 'https://musicbrainz.org/'
else:
    BASE_URL = 'http://musicbrainz.org/'

SKIPPED_TRACKS = ['[data track]']

musicbrainzngs.set_useragent('beets', beets.__version__,
                             'http://beets.io/')


class MusicBrainzAPIError(util.HumanReadableException):
    """An error while talking to MusicBrainz. The `query` field is the
    parameter to the action and may have any type.
    """
    def __init__(self, reason, verb, query, tb=None):
        self.query = query
        if isinstance(reason, musicbrainzngs.WebServiceError):
            reason = u'MusicBrainz not reachable'
        super(MusicBrainzAPIError, self).__init__(reason, verb, tb)

    def get_message(self):
        return u'{0} in {1} with query {2}'.format(
            self._reasonstr(), self.verb, repr(self.query)
コード例 #60
0
 def updateMetaData(self, musicBrainzId):
     #we look up the song and download the dictionary of recording stats
     musicbrainzngs.set_useragent('CS3030MusicApp', 'V0.5')
     result = musicbrainzngs.get_release_by_id(musicBrainzId, includes=['artist-credits', 'release-rels'])
     #then we call the metadata update function to complete the process
     self.setMetaData(self.title, result['release']['artist-credit-phrase'], result['release']['title'])