Commit 9690e6f1 authored by Brian Guadalupe's avatar Brian Guadalupe

Merge branch 'albumartwip' into 'master'

Implements album art auto retrieval with caching

See merge request brian/mymusiclist!12
parents 1f1d25b2 f1663b06
This diff is collapsed.
# -*- coding: utf-8 -*-
import pprint
import musicbrainzngs
from musicbrainzngs import ResponseError
from core.models import Album
pp = pprint.PrettyPrinter(indent=4)
def init():
musicbrainzngs.set_useragent("mymusiclist","0.1", contact="none")
musicbrainzngs.set_rate_limit(limit_or_interval=False, new_requests=1)
print("[Exthook] Initialized")
def verifyAlbumArt(album, artist):
if(album.art == None):
album.art = fetchAlbumArt(album.album_name, artist)
album.save()
#may or may not add checks to see if valid http link
def fetchAlbumArt(name, artist):
debug("GET " + name + " " + artist)
results = musicbrainzngs.search_release_groups(name, limit = 3, artistname=artist, primarytype="album")
#pp.pprint(results['release-group-list'])
results = results['release-group-list']
resultid = results[0]['id']
debug("ID = " + resultid)
try:
imagelist = musicbrainzngs.get_release_group_image_list(resultid)
except ResponseError:
debug("No image found.")
return None
except NetworkError:
debug("Cannot connect to MB server")
return None
return imagelist['images'][0]['thumbnails']['large']
def debug(string):
print("[Exthook] " + string)
\ No newline at end of file
......@@ -12,6 +12,7 @@ class Album(models.Model):
album_name = models.CharField(max_length=64)
year = models.DecimalField(max_digits=4, decimal_places=0)
artist = models.ForeignKey(Artist)
art = models.URLField(null=True, blank=True)
def __str__(self):
return self.album_name
......
......@@ -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)
exthook.verifyAlbumArt(result[0], artist_name)
return render(request, 'album.html', {'result':result[0], 'songs': songs, 'artist': artist_name})
\ No newline at end of file
......@@ -4,19 +4,18 @@
{% block sidebar %}
<h2> Album info </h2>
<img src = "{{result.art}}" 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