def get_mw_audio(key: str) -> [CE_AudioObject]: # Use the Muziekweb API to retrieve all the tracks on the album doc = get_album_information(key) if doc is not None and doc.firstChild.tagName == "Result" and doc.firstChild.attributes[ 'ErrorCode'].value == "0": # Now extract the audio links from the Muziekweb data audio_objects = list() for track in doc.getElementsByTagName('Track'): trackId = track.getElementsByTagName( 'AlbumTrackID')[0].firstChild.data audio_object = CE_AudioObject( identifier=None, name=trackId, url=MW_AUDIO_URL.format(trackId), contributor=GLOBAL_CONTRIBUTOR, creator=GLOBAL_IMPORTER_REPO, ) audio_object.title = track.getElementsByTagName( 'TrackTitle')[0].firstChild.data audio_object.publisher = GLOBAL_PUBLISHER audio_object.description = 'Embed in frame using the following code: <iframe width="300" height="30" src="[url]" frameborder="no" scrolling="no" allowtransparency="true"></iframe>' audio_objects.append(audio_object) return audio_objects return None
def get_mw_audio_1track(key: str) -> [CE_AudioObject]: # Use the Muziekweb API to retrieve one track key_album = key.split('-')[0] doc = get_album_information(key_album) if doc is not None and doc.firstChild.tagName == "Result" and doc.firstChild.attributes[ 'ErrorCode'].value == "0": # Now extract the audio links from the Muziekweb data audio_objects = list() music_works = list() persons = list() for track in doc.getElementsByTagName('Track'): trackId = track.getElementsByTagName( 'AlbumTrackID')[0].firstChild.data if trackId == key: # append audio object audio_object = CE_AudioObject( identifier=None, name=track.getElementsByTagName('TrackTitle') [0].firstChild.data, url=MW_AUDIO_URL.format(trackId), contributor=GLOBAL_CONTRIBUTOR, creator=GLOBAL_IMPORTER_REPO, ) audio_object.title = "Muziekweb - de muziekbibliotheek van Nederland" audio_object.publisher = GLOBAL_PUBLISHER audio_object.description = 'Embed in frame using the following code: <iframe width="300" height="30" src="[url]" frameborder="no" scrolling="no" allowtransparency="true"></iframe>' audio_objects.append(audio_object) # append musicwork unif_title = track.getElementsByTagName( 'UniformTitle')[0].attributes['Link'].value unif_text = track.getElementsByTagName( 'UniformTitle')[0].firstChild.data.replace(' ', '-') unif_style = track.getElementsByTagName( 'Catalogue')[0].firstChild.data.split(' ')[0] music_work = CE_MusicComposition( identifier=None, name=track.getElementsByTagName('TrackTitle') [0].firstChild.data, url=MW_MUSIC_URL.format(unif_title, unif_style, unif_text), contributor=GLOBAL_CONTRIBUTOR, creator=GLOBAL_IMPORTER_REPO, ) music_work.title = 'Muziekweb - de muziekbibliotheek van Nederland' music_work.contributor = GLOBAL_CONTRIBUTOR music_work.source = MW_MUSIC_URL.format( unif_title, unif_style, unif_text) music_works.append(music_work) # append persons perf_link = track.getElementsByTagName( 'Performer')[0].attributes['Link'].value doc_artist = get_artist_information(perf_link) num_persons = int( doc_artist.getElementsByTagName('ExternalLinks') [0].attributes['Count'].value) perf_name = doc_artist.getElementsByTagName( 'PresentationName')[0].firstChild.data perf_text = perf_name.replace(' ', '-') #MW person person = CE_Person( identifier=None, name='{} - Muziekweb'.format(perf_name), url=MW_MUSIC_URL.format(perf_link, unif_style, perf_text), contributor=GLOBAL_CONTRIBUTOR, creator=GLOBAL_IMPORTER_REPO, title='{} - Muziekweb'.format(perf_name), source=MW_MUSIC_URL.format(perf_link, unif_style, perf_text), ) persons.append(person) # external links for pers in range(num_persons): prov_name = doc_artist.getElementsByTagName( 'ExternalLink')[pers].attributes['Provider'].value print('Searching for person: {} - {}'.format( perf_name, prov_name)) ext_link = doc_artist.getElementsByTagName( 'ExternalLinks')[0].getElementsByTagName( 'Link')[pers].firstChild.data if prov_name == 'ISNI': ext_link = MW_MUSIC_URL.format(perf_link, unif_style, ext_link) ppl = load_person_from_isni(ext_link) person = CE_Person( identifier=None, name=ppl['title'], url=ppl['source'], contributor=ppl['contributor'], creator=GLOBAL_IMPORTER_REPO, title=ppl['title'], source=ppl['source'], ) elif prov_name == 'VIAF': ppl = load_person_from_viaf(ext_link) person = CE_Person( identifier=None, name=ppl['title'], url=ppl['source'], contributor=ppl['contributor'], creator=GLOBAL_IMPORTER_REPO, title=ppl['title'], source=ppl['source'], ) elif prov_name == 'MUSICBRAINZ': mbid = ext_link.split('/')[-1] ppl = load_person_from_musicbrainz(mbid) person = CE_Person( identifier=None, name=ppl['title'], url=ppl['source'], contributor=ppl['contributor'], creator=GLOBAL_IMPORTER_REPO, title=ppl['title'], source=ppl['source'], ) person.birthPlace = ppl['birthplace'] person.birthDate = ppl['birth_date'] person.deathPlace = ppl['deathplace'] person.deathDate = ppl['death_date'] elif prov_name == 'WIKIDATA': ppl = load_person_from_wikidata(ext_link) wiki_data_link = ext_link person = CE_Person( identifier=None, name=ppl['title'], url=ppl['source'], contributor=ppl['contributor'], creator=GLOBAL_IMPORTER_REPO, title=ppl['title'], source=ppl['source'], ) person.description = ppl['description'] elif prov_name == 'WIKIPEDIA_EN': wiki_data_link = 'https://en.wikipedia.org/wiki/{}'.format( ext_link) ppl = load_person_from_wikipedia_wikipedia( wiki_data_link, 'en') person = CE_Person( identifier=None, name=ppl['name'], url=ppl['source'], contributor=ppl['contributor'], creator=GLOBAL_IMPORTER_REPO, title=ppl['title'], source=ppl['source'], ) person.description = ppl['description'] elif prov_name == 'WIKIPEDIA_NL': wiki_data_link = 'https://nl.wikipedia.org/wiki/{}'.format( ext_link) ppl = load_person_from_wikipedia_wikipedia( wiki_data_link, 'nl') person = CE_Person( identifier=None, name=ppl['name'], url=ppl['source'], contributor=ppl['contributor'], creator=GLOBAL_IMPORTER_REPO, title=ppl['title'], source=ppl['source'], ) person.description = ppl['description'] else: if prov_name == 'ALLMUSIC': contributor = 'https://www.allmusic.com/' elif prov_name == 'DISCOGS': contributor = 'https://www.discogs.com/' elif prov_name == 'LASTFM': contributor = 'https://www.last.fm/' else: continue person = CE_Person( identifier=None, name='{} - {}'.format(perf_name, prov_name), url=ext_link, contributor=contributor, creator=GLOBAL_IMPORTER_REPO, title='{} - {}'.format(perf_name, prov_name), source=ext_link, ) persons.append(person) print('External link: {}'.format(ext_link)) return audio_objects, music_works, persons return None
def get_mw_audio_1track(key: str) -> [CE_AudioObject]: # Use the Muziekweb API to retrieve one track key_album = key.split('-')[0] doc = get_album_information(key_album) if doc is not None and doc.firstChild.tagName == "Result" and doc.firstChild.attributes[ 'ErrorCode'].value == "0": # Now extract the audio links from the Muziekweb data audio_objects = list() music_recordings = list() music_works = list() persons = list() music_groups = list() for track in doc.getElementsByTagName('Track'): trackId = track.getElementsByTagName( 'AlbumTrackID')[0].firstChild.data if trackId == key: track_name = track.getElementsByTagName( 'TrackTitle')[0].firstChild.data # append audio object audio_object = CE_AudioObject( identifier=None, name=track_name, url=MW_AUDIO_URL.format(trackId), contributor=GLOBAL_CONTRIBUTOR, creator=GLOBAL_IMPORTER_REPO, ) audio_object.title = "Muziekweb - de muziekbibliotheek van Nederland" audio_object.publisher = GLOBAL_PUBLISHER audio_object.description = 'Embed in frame using the following code: <iframe width="300" height="30" src="[url]" frameborder="no" scrolling="no" allowtransparency="true"></iframe>' audio_objects.append(audio_object) # append music recording object music_recording = CE_MusicRecording( identifier=None, name=track_name, url=MW_AUDIO_URL.format(trackId), contributor=GLOBAL_CONTRIBUTOR, creator=GLOBAL_IMPORTER_REPO, ) music_recording.title = "Muziekweb - de muziekbibliotheek van Nederland" music_recording.publisher = GLOBAL_PUBLISHER music_recording.description = 'Embed in frame using the following code: <iframe width="300" height="30" src="[url]" frameborder="no" scrolling="no" allowtransparency="true"></iframe>' music_recordings.append(music_recording) # append musicwork unif_title = track.getElementsByTagName( 'UniformTitle')[0].attributes['Link'].value unif_text = track.getElementsByTagName( 'UniformTitle')[0].firstChild.data.replace(' ', '-') unif_style = track.getElementsByTagName( 'Catalogue')[0].firstChild.data.split(' ')[0] music_work = CE_MusicComposition( identifier=None, name=track_name, url=MW_MUSIC_URL.format(unif_title, unif_style, unif_text), contributor=GLOBAL_CONTRIBUTOR, creator=GLOBAL_IMPORTER_REPO, ) music_work.title = 'Muziekweb - de muziekbibliotheek van Nederland' music_work.contributor = GLOBAL_CONTRIBUTOR music_work.source = MW_MUSIC_URL.format( unif_title, unif_style, unif_text) music_works.append(music_work) # append persons perf_link = track.getElementsByTagName( 'Performer')[0].attributes['Link'].value doc_artist = get_artist_information(perf_link) num_ext_links = int( doc_artist.getElementsByTagName('ExternalLinks') [0].attributes['Count'].value) perf_name = doc_artist.getElementsByTagName( 'PresentationName')[0].firstChild.data perf_text = perf_name.replace(' ', '-') # check if person or musicgroup prov_names = [ doc_artist.getElementsByTagName('ExternalLink') [pers].attributes['Provider'].value for pers in range(num_ext_links) ] artist_type = None if 'MUSICBRAINZ' in prov_names: ext_link = doc_artist.getElementsByTagName( 'ExternalLinks')[0].getElementsByTagName('Link')[ prov_names.index('MUSICBRAINZ')].firstChild.data mbid = ext_link.split('/')[-1] artist = musicbrainz.get_artist_from_musicbrainz(mbid) artist_type = artist.get('type', None) if artist_type == 'Group': music_groups, persons = get_music_group_information( doc_artist, music_groups, persons, num_ext_links, perf_name, perf_link, perf_text, unif_style) else: persons = get_person_information(doc_artist, persons, num_ext_links, perf_name, perf_link, perf_text, unif_style) return audio_objects, music_recordings, music_works, persons, music_groups return None, None, None, None, None