本文整理汇总了Python中musicbrainzngs.get_recording_by_id函数的典型用法代码示例。如果您正苦于以下问题:Python get_recording_by_id函数的具体用法?Python get_recording_by_id怎么用?Python get_recording_by_id使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_recording_by_id函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testGetRecording
def testGetRecording(self):
musicbrainzngs.get_recording_by_id("93468a09-9662-4886-a227-56a2ad1c5246")
self.assertEqual("http://musicbrainz.org/ws/2/recording/93468a09-9662-4886-a227-56a2ad1c5246", self.opener.get_url())
# one include
musicbrainzngs.get_recording_by_id("93468a09-9662-4886-a227-56a2ad1c5246", includes=["artists"])
self.assertEqual("http://musicbrainz.org/ws/2/recording/93468a09-9662-4886-a227-56a2ad1c5246?inc=artists", self.opener.get_url())
示例2: get_album_name
def get_album_name( recording_id,
log ):
"""
`recording_id` should be a Musicbrainz ID value for a recording (track) as
a string. Returns None on failure, else returns the recording's album's
name as it is most commonly known in the Musicbrainz DB as a string
"""
try:
result = musicbrainzngs.get_recording_by_id( recording_id, includes=['releases'] )
except Exception as exc:
log.warning("get_album_name(): web service call failed: %s" % exc)
return None
most_common_album_name = None
try:
# Find the most commonly occuring name for the release (album)
release_name_occurences = dict()
for release in result['recording']['release-list']:
if release['title'] not in release_name_occurences:
release_name_occurences[release['title']] = 1
else:
release_name_occurences[release['title']] += 1
most_common_album_name = \
max( release_name_occurences, key=release_name_occurences.get )
except Exception as e:
log.warning("get_album_name(): result parsing failed: %s: %s\nresult was %s" % ( type(e), e, str(result) ))
return None
return most_common_album_name
示例3: main
def main(collectionid):
# work -> list recordings
mapping = collections.defaultdict(list)
# map from an id to a name
recordingnames = {}
worknames = {}
for i, releaseid in enumerate(compmusic.musicbrainz.get_releases_in_collection(collectionid)):
print i, releaseid
try:
rel = mb.get_release_by_id(releaseid, includes=["recordings"])
except:
continue
rel = rel["release"]
for medium in rel.get("medium-list", []):
for track in medium.get("track-list", []):
recid = track["recording"]["id"]
recordingnames[recid] = track["recording"]["title"]
recording = mb.get_recording_by_id(recid, includes=["work-rels"])
recording = recording["recording"]
for work in recording.get("work-relation-list", []):
workid = work["work"]["id"]
worknames[workid] = work["work"]["title"]
mapping[workid].append(recid)
data = []
for k, v in mapping.items():
data.append((k, v))
data = sorted(data, key=lambda x: len(x[1]), reverse=True)
all_d = {"recordingnames": recordingnames,
"worknames": worknames,
"data": data
}
json.dump(all_d, open("works_by_recording.json", "w"))
示例4: getRecrodingListForAWork
def getRecrodingListForAWork( workMBID, m):
# get list of recording IDa for work ID
recordingIDsList = m.recordingids_for_work(workMBID)
existingVocalRecordings = [];
for recID in recordingIDsList:
recording = mb.get_recording_by_id(recID, includes=["artist-rels", "releases"])
# check if we have the realease of the recording in the database
listExistingReleases = getExistigReleasesForRecording(recording, recID)
if len(listExistingReleases) == 0:
continue
# check if we have vocals
if not isRecordingWithVocals(recording, recID):
print "no vocals in recording ID: ", recID
else:
existingVocalRecordings.append(recID)
return existingVocalRecordings
示例5: main
def main(path, fake_release_mbid):
releases = {}
# Get all the mbid of the recordings
onlyfiles = [f for f in os.listdir(path) if os.path.isfile(os.path.join(path, f))]
for i in onlyfiles:
head, tail = os.path.split(i)
filename, file_extension = os.path.splitext(i)
if file_extension == '.mp3':
c = eyed3.load(os.path.join(path, i))
mbid = c.tag.unique_file_ids.get("http://musicbrainz.org").render()[33:]
try:
rel = mb.get_recording_by_id(mbid, includes=["releases"])
release = None
if len(rel['recording']['release-list']):
# create release
release = rel['recording']['release-list'][0]['id']
else:
release = fake_release_mbid
# use *fake* release
if release not in releases:
releases[release] = []
releases[release].append(mbid)
except:
print("couldn't find a release for the recording %s" % mbid)
continue
coll = Collection.objects.get(mbid="544f7aec-dba6-440c-943f-103cf344efbb")
r = makam_importer.MakamReleaseImporter(coll)
for i in releases.keys():
r.import_release(i, "")
for j in releases[i]:
r.add_and_get_recording(j)
示例6: stats_for_recording
def stats_for_recording(self, recordingid):
""" Given a recording id, get its work (if it exists) and
the composer and lyricist of the work """
self.recordings.add(recordingid)
recording = mb.get_recording_by_id(recordingid, includes=["work-rels", "artist-rels"])
recording = recording["recording"]
for relation in recording.get("artist-relation-list", []):
artist = relation.get("artist", {}).get("id")
if artist:
self.artists.add(artist)
for relation in recording.get("work-relation-list", []):
workid = relation.get("work", {}).get("id")
self.works.add(workid)
self.work_recording_counts[workid] += 1
work = mb.get_work_by_id(workid, includes=["artist-rels"])
work = work["work"]
for artist in work.get("artist-relation-list", []):
t = artist["type"]
aid = artist.get("artist", {}).get("id")
if aid:
if t == "composer":
self.composers.add(aid)
elif t == "lyricist":
self.lyricists.add(aid)
示例7: _recurse_relations
def _recurse_relations(self, mb_track_id, oldest_release, relation_type):
x = musicbrainzngs.get_recording_by_id(
mb_track_id,
includes=['releases', 'recording-rels'])
if 'recording-relation-list' in x['recording'].keys():
# recurse down into edits and remasters.
# Note remasters are deprecated in musicbrainz, but some entries
# may still exist.
for subrecording in x['recording']['recording-relation-list']:
if ('direction' in subrecording.keys() and
subrecording['direction'] == 'backward'):
continue
(oldest_release, relation_type) = self._recurse_relations(
subrecording['target'],
oldest_release,
subrecording['type'])
for release in x['recording']['release-list']:
if 'date' not in release.keys():
# A release without a date. Skip over it.
continue
release_date = self._make_date_values(release['date'])
if (oldest_release['year'] is None or
oldest_release['year'] > release_date['year']):
oldest_release = release_date
elif oldest_release['year'] == release_date['year']:
if ('month' in release_date.keys() and
'month' in oldest_release.keys() and
oldest_release['month'] > release_date['month']):
oldest_release = release_date
return (oldest_release, relation_type)
示例8: get_recording_by_id
def get_recording_by_id(mbid):
recording = cache.get(mbid)
if not recording:
try:
recording = musicbrainzngs.get_recording_by_id(mbid, includes=['artists', 'releases', 'media'])['recording']
except ResponseError as e:
raise DataUnavailable(e)
cache.set(mbid, recording, time=CACHE_TIMEOUT)
return recording
示例9: track_for_id
def track_for_id(trackid):
"""Fetches a track by its MusicBrainz ID. Returns a TrackInfo object
or None if no track is found.
"""
try:
res = musicbrainzngs.get_recording_by_id(trackid, TRACK_INCLUDES)
except musicbrainzngs.ResponseError:
log.debug('Track ID match failed.')
return None
return track_info(res['recording'])
示例10: make_query
def make_query(self, params):
if params["type"] == "artist":
return musicbrainzngs.get_artist_by_id(params["mbid"])
elif params["type"] == "album":
return musicbrainzngs.get_release_by_id(params["mbid"])
elif params["type"] == "tracklist":
return musicbrainzngs.get_release_by_id(params["mbid"],
includes=["recordings"])["release"]["medium-list"][0]["track-list"]
elif params["type"] == "track":
return musicbrainzngs.get_recording_by_id(params["mbid"], includes=["artists"])
示例11: track_for_id
def track_for_id(trackid):
"""Fetches a track by its MusicBrainz ID. Returns a TrackInfo object
or None if no track is found. May raise a MusicBrainzAPIError.
"""
try:
res = musicbrainzngs.get_recording_by_id(trackid, TRACK_INCLUDES)
except musicbrainzngs.ResponseError:
log.debug("Track ID match failed.")
return None
except musicbrainzngs.MusicBrainzError as exc:
raise MusicBrainzAPIError(exc, "get recording by ID", trackid, traceback.format_exc())
return track_info(res["recording"])
示例12: get_performance_credit_for_recording
def get_performance_credit_for_recording(self, recordingid):
recording = mb.get_recording_by_id(recordingid, includes=["releases"])
recording = recording["recording"]
ret = []
for release in recording.get("release-list", []):
relid = release["id"]
mbrelease = mb.get_release_by_id(relid, includes=["artist-credits", "recordings"])
mbrelease = mbrelease["release"]
for medium in mbrelease.get("medium-list", []):
for track in medium.get("track-list", []):
if track["recording"]["id"] == recordingid:
ret.append(track["recording"]["artist-credit-phrase"])
return list(set(ret))
示例13: get_musicbrainz
def get_musicbrainz(self, obj):
results = []
includes = ['releases','artists']
for e in obj.results_acoustid:
media_id = e['id']
try:
result = musicbrainzngs.get_recording_by_id(id=media_id, includes=includes)
results.append(result)
except Exception, e:
print e
pass
示例14: match_recording
def match_recording(mbids):
release_list = []
mbid_rec = {}
for mbid in mbids:
try:
mbid_info = mb.get_recording_by_id(mbid,['artists','releases'],['official'])['recording']
except mb.musicbrainz.ResponseError :
logging.warning('{0} is an invalid MusicBrainz ID. Skipping...'.format(mbid))
continue
mbid_rlist = mbid_info['release-list']
mbid_rec[mbid] = mbid_info
for item in mbid_rlist:
item['trackid'] = mbid
release_list.extend(mbid_rlist)
return (mbid_rec, release_list)
示例15: track_for_id
def track_for_id(releaseid):
"""Fetches a track by its MusicBrainz ID. Returns a TrackInfo object
or None if no track is found. May raise a MusicBrainzAPIError.
"""
trackid = _parse_id(releaseid)
if not trackid:
log.debug(u'Invalid MBID ({0}).', releaseid)
return
try:
res = musicbrainzngs.get_recording_by_id(trackid, TRACK_INCLUDES)
except musicbrainzngs.ResponseError:
log.debug(u'Track ID match failed.')
return None
except musicbrainzngs.MusicBrainzError as exc:
raise MusicBrainzAPIError(exc, u'get recording by ID', trackid,
traceback.format_exc())
return track_info(res['recording'])