Commit 1097ceec authored by Gink's avatar Gink

Adds dynamic album art loading from coverartarchive.org

> to use, download 'pip' which is python's package manager, then run pip install musicbrainzngs.
> tested using python2.7
parent 95b54b6b
import musicbrainzngs
from musicbrainzngs import ResponseError
def init():
musicbrainzngs.set_useragent("mymusiclist","0.1", contact="none")
musicbrainzngs.set_rate_limit(limit_or_interval=False, new_requests=1)
print("Exthook init called.")
def getAlbumArtByName(name, artistname):
results = musicbrainzngs.search_release_groups(name, artist=artistname)
results = results['release-group-list']
resultid = results[0]['id']
print("[Exthook] ID = " + resultid)
try:
imagelist = musicbrainzngs.get_release_group_image_list(resultid)
except ResponseError:
return "NaN"
return imagelist['images'][0]['thumbnails']['large']
\ No newline at end of file
......@@ -37,7 +37,6 @@ INSTALLED_APPS = [
'playlist',
'tag',
'user',
'search.musicbrainzhook',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
......
......@@ -19,6 +19,7 @@ from django.contrib import admin
from django.contrib.auth import views as auth_views
from core import views as core_views
from core import exthook as exthook
from user import views as user_views
from search import views as search_views
......@@ -34,3 +35,5 @@ urlpatterns = [
url(r'^profile/(?P<slug>[A-Za-z0-9-+_.@]+)/edit/$', user_views.EditProfile.as_view(success_url=reverse_lazy('home')), name='editprofile'),
url(r'^$', core_views.home, name='home')
]
exthook.init()
from django.apps import AppConfig
class MusicBrainzHook(AppConfig):
name = 'Musicbrainzhook'
verbose_name = name
def ready(self):
print("Self called")
def custom():
print("print called")
\ No newline at end of file
from django.shortcuts import render, redirect, get_object_or_404
from core.models import *
from search.musicbrainzhook import *
from core import exthook
def search(request):
type = request.GET.get('searchtype', '')
......@@ -32,4 +32,5 @@ def album_profile(request, identifier):
result = Album.objects.filter(id = identifier)
artist_name = result[0].artist.name
songs = Song.objects.filter(album = identifier)
return render(request, 'album.html', {'result':result[0], 'songs': songs, 'artist': artist_name})
\ No newline at end of file
albumart = exthook.getAlbumArtByName(result[0].album_name, artist_name)
return render(request, 'album.html', {'result':result[0], 'songs': songs, 'artist': artist_name, 'image': albumart})
\ No newline at end of file
......@@ -4,19 +4,18 @@
{% block sidebar %}
<h2> Album info </h2>
<img src = "{{image}}" alt= "No album art available">
<p>
Album: {{result.name}} <br>
Artist: {{artist_name}} <br>
Year: {{result.year}} <br>
<b> {{result.album_name}} </b> ({{result.year}}) <br>
{{artist}} <br> <br>
Tags: {{songs.1.genre}}
{% endblock %}
{% block content %}
{% for i in songs %}
<div class = "boxified main">
{% for i in songs %}
<h3> {{i.song_name}} </h3>
<p> Genre: {{i.genre}} </p>
</div>
{% endfor %}
</div>
{% endblock %}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment