def getAlbumTitleFromMusicBrainz(songTitle, artistName): print "searching musicbrainz" musicbrainzngs.set_useragent("BillboardChartAnalyzer","1","*****@*****.**") workList = musicbrainzngs.search_works(work=songTitle, artist=artistName) for work in workList['work-list']: if songTitle in work['title']: print "found potential song" for artist in work['artist-relation-list']: if artistName in artist['name']: print work['title'] + ": " + artist['name']
def get(self, params): """ Returns list of works based on the query and URL parameters. """ args = works_arguments.parse_args(request) offset = int(params['offset']) limit = int(params['limit']) composer = args['composer'] title = args['title'] results = mbz.search_works(query=title, limit=limit, offset=offset, strict=False, artist=composer) # print(results) return self.mbz_results_to_omi(offset, results)
def test_search_works(self): musicbrainzngs.search_works("Fountain City") self.assertEqual("http://musicbrainz.org/ws/2/work/?query=Fountain+City", self.opener.get_url()) musicbrainzngs.search_works(work="Fountain City") expected_query = 'work:(fountain city)' expected = 'http://musicbrainz.org/ws/2/work/?query=%s' % musicbrainzngs.compat.quote_plus(expected_query) self.assertEquals(expected, self.opener.get_url()) # Invalid query field with self.assertRaises(musicbrainzngs.InvalidSearchFieldError): musicbrainzngs.search_works(foo="value")
def test_file(self, fname): fname = os.path.basename(fname) fname = os.path.splitext(fname)[0] parts = fname.split("--") if len(parts) != 5: print("wrong number of parts", parts) return makam, form, usul, name, composer = parts composer = composer.replace("_", " ") if not name: name = makam + ' ' + form name = name.replace("_", " ") works = mb.search_works(name)["work-list"] for w in works: for a in w.get("artist-relation-list", []): a = a["artist"] aname = a["name"] wname = w["title"] # if isinstance(aname, unicode): # aname = unidecode.unidecode(aname) # if isinstance(wname, unicode): # wname = unidecode.unidecode(wname) anywork = self.match(name, wname) anyname = self.match(composer, aname) reclist = self.recordingids_for_work(w["id"]) for n in self.aliases_for_artist(a["id"]): anyname = anyname or self.match(composer, n) for r in reclist: for n in self.get_performance_credit_for_recording(r): anyname = anyname or self.match(composer, n) for w in self.aliases_for_work(w["id"]): print("matching a work alias", w) anywork = anywork or self.match(name, w) if anywork and anyname: print( " match: %s by %s - http://musicbrainz.org/work/%s" % (w["title"], aname, w["id"])) self.save_scores(fname, reclist)
def test_file(self, fname): fname = os.path.basename(fname) fname = os.path.splitext(fname)[0] parts = fname.split("--") if len(parts) != 5: print "wrong number of parts", parts return makam, form, usul, name, composer = parts composer = composer.replace("_", " ") if not name: name = makam + ' ' + form name = name.replace("_", " ") works = mb.search_works(name)["work-list"] for w in works: for a in w.get("artist-relation-list", []): a = a["artist"] aname = a["name"] wname = w["title"] #if isinstance(aname, unicode): # aname = unidecode.unidecode(aname) #if isinstance(wname, unicode): # wname = unidecode.unidecode(wname) anywork = self.match(name, wname) anyname = self.match(composer, aname) reclist = self.recordingids_for_work(w["id"]) for n in self.aliases_for_artist(a["id"]): anyname = anyname or self.match(composer, n) for r in reclist: for n in self.get_performance_credit_for_recording(r): anyname = anyname or self.match(composer, n) for w in self.aliases_for_work(w["id"]): print "matching a work alias", w anywork = anywork or self.match(name, w) if anywork and anyname: print " match: %s by %s - http://musicbrainz.org/work/%s" % (w["title"], aname, w["id"]) self.save_scores(fname, reclist)
def search_works(query='', limit=None, offset=None): """Search for works.""" api_resp = musicbrainzngs.search_works(query=query, limit=limit, offset=offset) return api_resp.get('work-count'), api_resp.get('work-list')
def testSearchWork(self): musicbrainzngs.search_works("Fountain City") self.assertEqual("http://musicbrainz.org/ws/2/work/?query=Fountain+City", self.opener.get_url())
work_title, the_title)) else: print("This query needs to be rechecked.") print("Input title '{}' does NOT match found title: '{}'".format( work_title, the_title)) else: print( "This query needs to be rechecked. These are artists involved: {}". format(artists)) # print("input artist name: ", artist_name, "disambiguation: ", disambiguation_artist_name) if __name__ == '__main__': args = sys.argv[1:] if len(args) != 2: sys.exit("usage: {} TITLE ARTIST".format(sys.argv[0])) # args must be inputted as strings, e.g., python search_work.py "Daft Punk" "Get Lucky" title, artist = args theTitle = title # output artist from the query and match it against my input artist name to compare if the artist name to raise error if there is no match result = musicbrainzngs.search_works(work=title, artist=artist, limit=3) # On sucess, result is a dictionary with a single key: # "release-list", which is a list of dictionaries. if not result['work-list']: sys.exit("no work found") for (idx, work) in enumerate(result['work-list']): print("match #{}:".format(idx + 1)) show_work_details(work, artist, theTitle) print()
import csv import musicbrainzngs musicbrainzngs.set_useragent( "python-musicbrainzngs-example", "0.1", "https://github.com/alastair/python-musicbrainzngs/", ) song_names = [] artists = [] with open('top40_songs_tester.csv', encoding='utf-8') as csvfile: reader = csv.DictReader(csvfile, delimiter='\t') for row in reader: work = musicbrainzngs.search_works(recording=row['title'], limit=25) print(work)
"""Print some details about a release dictionary to stdout. """ # "artist-credit-phrase" is a flat string of the credited artists # joined with " + " or whatever is given by the server. # You can also work with the "artist-credit" list manually. print("{}, by {}".format(rel['title'], rel["artist-credit-phrase"])) if 'date' in rel: print("Released {} ({})".format(rel['date'], rel['status'])) print("MusicBrainz ID: {}".format(rel['id'])) if __name__ == '__main__': args = sys.argv[1:] if len(args) != 1: sys.exit("usage: {} ARTIST".format(sys.argv[0])) artist = args # Keyword arguments to the "search_*" functions limit keywords to # specific fields. The "limit" keyword argument is special (like as # "offset", not shown here) and specifies the number of results to # return. result = musicbrainzngs.search_works(artist=artist, limit=5) # On success, result is a dictionary with a single key: # "release-list", which is a list of dictionaries. if not result['release-list']: sys.exit("no release found") for (idx, release) in enumerate(result['release-list']): print("match #{}:".format(idx + 1)) show_release_details(release) print()