Divisiones visuales en medium
This commit is contained in:
@@ -10,6 +10,10 @@ from utils import parallel_map
|
|||||||
import fetcher.musicbrainz as mb
|
import fetcher.musicbrainz as mb
|
||||||
|
|
||||||
|
|
||||||
|
###
|
||||||
|
# Utility code
|
||||||
|
###
|
||||||
|
|
||||||
def full_country_name(country_code):
|
def full_country_name(country_code):
|
||||||
"""Obtiene el nombre de un pais en español dado su codigo de pais"""
|
"""Obtiene el nombre de un pais en español dado su codigo de pais"""
|
||||||
return dict(countries_for_language('es')).get(country_code, country_code)
|
return dict(countries_for_language('es')).get(country_code, country_code)
|
||||||
@@ -28,6 +32,35 @@ def translate_artist_type(artist_type):
|
|||||||
return translation.get(artist_type, artist_type)
|
return translation.get(artist_type, artist_type)
|
||||||
|
|
||||||
|
|
||||||
|
def find_best_cover(mb_covers):
|
||||||
|
"""Intenta obtener la cover art mas apropiada a partir de una lista de estas"""
|
||||||
|
only_aproved_front = [x for x in mb_covers.get('images') if x.get('approved', False)
|
||||||
|
and x.get('front', False) and not x.get('back', False)]
|
||||||
|
if len(only_aproved_front) > 0:
|
||||||
|
return only_aproved_front[0]
|
||||||
|
|
||||||
|
only_aproved = [x for x in mb_covers.get('images') if x.get('approved', False)]
|
||||||
|
if len(only_aproved) > 0:
|
||||||
|
return only_aproved[0]
|
||||||
|
|
||||||
|
return mb_covers.get('images')[0]
|
||||||
|
|
||||||
|
|
||||||
|
def paginate(count, limit, page):
|
||||||
|
"""Crea un modelo de paginado a partir de la cantidad de elementos, el limite de elementos y la
|
||||||
|
pagina actual"""
|
||||||
|
return {
|
||||||
|
'total': count,
|
||||||
|
'current_page': page,
|
||||||
|
'last_page': ceil(count / limit),
|
||||||
|
'per_page': limit,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
###
|
||||||
|
# Mapear entidades
|
||||||
|
##
|
||||||
|
|
||||||
def map_artist(mb_artist):
|
def map_artist(mb_artist):
|
||||||
"""Mapea el modelo de artista entregado por musicbrainz a uno propio"""
|
"""Mapea el modelo de artista entregado por musicbrainz a uno propio"""
|
||||||
artist = {
|
artist = {
|
||||||
@@ -108,30 +141,13 @@ def map_coverart(mb_cover):
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def find_best_cover(mb_covers):
|
##
|
||||||
"""Intenta obtener la cover art mas apropiada a partir de una lista de estas"""
|
# Obtener entidades
|
||||||
only_aproved_front = [x for x in mb_covers.get('images') if x.get('approved', False)
|
##
|
||||||
and x.get('front', False) and not x.get('back', False)]
|
|
||||||
if len(only_aproved_front) > 0:
|
|
||||||
return only_aproved_front[0]
|
|
||||||
|
|
||||||
only_aproved = [x for x in mb_covers.get('images') if x.get('approved', False)]
|
|
||||||
if len(only_aproved) > 0:
|
|
||||||
return only_aproved[0]
|
|
||||||
|
|
||||||
return mb_covers.get('images')[0]
|
|
||||||
|
|
||||||
|
|
||||||
def paginate(count, limit, page):
|
|
||||||
"""Crea un modelo de paginado a partir de la cantidad de elementos, el limite de elementos y la
|
|
||||||
pagina actual"""
|
|
||||||
return {
|
|
||||||
'total': count,
|
|
||||||
'current_page': page,
|
|
||||||
'last_page': ceil(count / limit),
|
|
||||||
'per_page': limit,
|
|
||||||
}
|
|
||||||
|
|
||||||
|
##
|
||||||
|
# Artistas
|
||||||
|
##
|
||||||
|
|
||||||
def get_artist(mbid):
|
def get_artist(mbid):
|
||||||
"""Obtiene un artista desde musicbrainz incluyendo sus tags"""
|
"""Obtiene un artista desde musicbrainz incluyendo sus tags"""
|
||||||
@@ -177,6 +193,10 @@ def get_artist_of_disc(mbid, limit, page):
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
##
|
||||||
|
# Releases
|
||||||
|
##
|
||||||
|
|
||||||
def get_release(mbid):
|
def get_release(mbid):
|
||||||
"""Obtiene una release desde musicbrainz incluyendo sus artistas"""
|
"""Obtiene una release desde musicbrainz incluyendo sus artistas"""
|
||||||
mb_release = mb.get_release_by_mbid(mbid, includes=['artists'])
|
mb_release = mb.get_release_by_mbid(mbid, includes=['artists'])
|
||||||
@@ -211,6 +231,11 @@ def get_artist_of_release(mbid, limit, page):
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
##
|
||||||
|
# Recordings
|
||||||
|
##
|
||||||
|
|
||||||
|
|
||||||
def get_recording(mbid):
|
def get_recording(mbid):
|
||||||
"""Obtiene una grabacion incluyendo a su artista"""
|
"""Obtiene una grabacion incluyendo a su artista"""
|
||||||
mb_recording = mb.get_recording_by_mbid(mbid, includes=['artists'])
|
mb_recording = mb.get_recording_by_mbid(mbid, includes=['artists'])
|
||||||
@@ -259,6 +284,11 @@ def get_artist_of_recording(mbid, limit, page):
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
##
|
||||||
|
# CoverArt
|
||||||
|
##
|
||||||
|
|
||||||
|
|
||||||
def get_cover_art_disc(mbid):
|
def get_cover_art_disc(mbid):
|
||||||
"""Obtiene el cover art de un disco"""
|
"""Obtiene el cover art de un disco"""
|
||||||
mb_covers = mb.get_release_group_cover_art(mbid)
|
mb_covers = mb.get_release_group_cover_art(mbid)
|
||||||
@@ -291,6 +321,10 @@ def get_cover_art_recording(mbid):
|
|||||||
|
|
||||||
return get_cover_art_release(release['releases'][0]['id'])
|
return get_cover_art_release(release['releases'][0]['id'])
|
||||||
|
|
||||||
|
##
|
||||||
|
# Busqueda
|
||||||
|
##
|
||||||
|
|
||||||
|
|
||||||
def search_artist(query, limit, page):
|
def search_artist(query, limit, page):
|
||||||
"""Busca un artista dada una query"""
|
"""Busca un artista dada una query"""
|
||||||
|
|||||||
Reference in New Issue
Block a user