Traduciendo country_codes

This commit is contained in:
Daniel Cortes
2020-06-03 21:29:35 -04:00
parent c654f447b1
commit 50b5694865
2 changed files with 20 additions and 19 deletions

View File

@@ -2,20 +2,21 @@ import fetcher.musicbrainz as mb
from utils import pretty_print_json
def translate_artist(artist):
type = artist.get('type', None)
if type == 'Person':
artist['type'] = 'Persona'
elif type == 'Group':
artist['type'] = 'Grupo'
elif type == 'Orchestra':
artist['type'] = 'Orquesta'
elif type == 'Choir':
artist['type'] = 'Coro'
elif type == 'Character':
artist['type'] = 'Personaje'
elif type == 'Other':
artist['type'] = 'Otro'
def full_country_name(country_code):
from country_list import countries_for_language
return dict(countries_for_language('es')).get(country_code, country_code)
def translate_artist_type(artist_type):
translation = {
'Person': 'Persona',
'Group': 'Grupo',
'Orchestra': 'Orquesta',
'Choir': 'Coro',
'Character': 'Personaje',
'Other': 'Otro',
}
return translation.get(artist_type, artist_type)
def map_artist(mb_artist):
@@ -24,13 +25,11 @@ def map_artist(mb_artist):
'name': mb_artist.get('name'),
'sort_name': mb_artist.get('sort_name'),
'disambiguation': mb_artist.get('disambiguation'),
'type': mb_artist.get('type'),
'country': mb_artist.get('country'),
'type': translate_artist_type(mb_artist.get('type')),
'country': full_country_name(mb_artist.get('country')),
'tags': sorted(mb_artist.get('tags', []), key=lambda tag: tag['count'], reverse=True),
}
translate_artist(artist)
return artist
@@ -193,6 +192,7 @@ def get_recording(mbid):
return map_recording(mb_recording)
def get_recordings_of_release(mbid, limit, page):
mb_recordings = mb.browse_recordings(params={'release': mbid}, includes=['artist-credits'], limit=limit, offset=limit * (page - 1))
if 'error' in mb_recordings: