Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mymusiclist
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Brian Guadalupe
mymusiclist
Commits
f1663b06
Commit
f1663b06
authored
Nov 19, 2017
by
Gink
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adds caching of album art, making the first retrieval the only slow one
parent
d8a91ab0
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
16 additions
and
7 deletions
+16
-7
exthook.py
core/exthook.py
+12
-4
models.py
core/models.py
+1
-0
views.py
search/views.py
+2
-2
album.html
templates/album.html
+1
-1
No files found.
core/exthook.py
View file @
f1663b06
...
@@ -2,15 +2,21 @@
...
@@ -2,15 +2,21 @@
import
pprint
import
pprint
import
musicbrainzngs
import
musicbrainzngs
from
musicbrainzngs
import
ResponseError
from
musicbrainzngs
import
ResponseError
from
core.models
import
Album
pp
=
pprint
.
PrettyPrinter
(
indent
=
4
)
pp
=
pprint
.
PrettyPrinter
(
indent
=
4
)
def
init
():
def
init
():
musicbrainzngs
.
set_useragent
(
"mymusiclist"
,
"0.1"
,
contact
=
"none"
)
musicbrainzngs
.
set_useragent
(
"mymusiclist"
,
"0.1"
,
contact
=
"none"
)
musicbrainzngs
.
set_rate_limit
(
limit_or_interval
=
False
,
new_requests
=
1
)
musicbrainzngs
.
set_rate_limit
(
limit_or_interval
=
False
,
new_requests
=
1
)
print
(
"[Exthook] Initialized"
)
print
(
"[Exthook] Initialized"
)
def
getAlbumArtByName
(
name
,
artist
):
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
)
debug
(
"GET "
+
name
+
" "
+
artist
)
results
=
musicbrainzngs
.
search_release_groups
(
name
,
limit
=
3
,
artistname
=
artist
,
primarytype
=
"album"
)
results
=
musicbrainzngs
.
search_release_groups
(
name
,
limit
=
3
,
artistname
=
artist
,
primarytype
=
"album"
)
#pp.pprint(results['release-group-list'])
#pp.pprint(results['release-group-list'])
...
@@ -21,9 +27,11 @@ def getAlbumArtByName(name, artist):
...
@@ -21,9 +27,11 @@ def getAlbumArtByName(name, artist):
imagelist
=
musicbrainzngs
.
get_release_group_image_list
(
resultid
)
imagelist
=
musicbrainzngs
.
get_release_group_image_list
(
resultid
)
except
ResponseError
:
except
ResponseError
:
debug
(
"No image found."
)
debug
(
"No image found."
)
return
"NaN"
return
None
except
NetworkError
:
debug
(
"Cannot connect to MB server"
)
return
None
return
imagelist
[
'images'
][
0
][
'thumbnails'
][
'large'
]
return
imagelist
[
'images'
][
0
][
'thumbnails'
][
'large'
]
def
debug
(
string
):
def
debug
(
string
):
print
(
"[Exthook] "
+
string
)
print
(
"[Exthook] "
+
string
)
\ No newline at end of file
core/models.py
View file @
f1663b06
...
@@ -12,6 +12,7 @@ class Album(models.Model):
...
@@ -12,6 +12,7 @@ class Album(models.Model):
album_name
=
models
.
CharField
(
max_length
=
64
)
album_name
=
models
.
CharField
(
max_length
=
64
)
year
=
models
.
DecimalField
(
max_digits
=
4
,
decimal_places
=
0
)
year
=
models
.
DecimalField
(
max_digits
=
4
,
decimal_places
=
0
)
artist
=
models
.
ForeignKey
(
Artist
)
artist
=
models
.
ForeignKey
(
Artist
)
art
=
models
.
URLField
(
null
=
True
,
blank
=
True
)
def
__str__
(
self
):
def
__str__
(
self
):
return
self
.
album_name
return
self
.
album_name
...
...
search/views.py
View file @
f1663b06
...
@@ -32,5 +32,5 @@ def album_profile(request, identifier):
...
@@ -32,5 +32,5 @@ def album_profile(request, identifier):
result
=
Album
.
objects
.
filter
(
id
=
identifier
)
result
=
Album
.
objects
.
filter
(
id
=
identifier
)
artist_name
=
result
[
0
]
.
artist
.
name
artist_name
=
result
[
0
]
.
artist
.
name
songs
=
Song
.
objects
.
filter
(
album
=
identifier
)
songs
=
Song
.
objects
.
filter
(
album
=
identifier
)
albumart
=
exthook
.
getAlbumArtByName
(
result
[
0
]
.
album_name
,
artist_name
)
exthook
.
verifyAlbumArt
(
result
[
0
],
artist_name
)
return
render
(
request
,
'album.html'
,
{
'result'
:
result
[
0
],
'songs'
:
songs
,
'artist'
:
artist_name
,
'image'
:
albumart
})
return
render
(
request
,
'album.html'
,
{
'result'
:
result
[
0
],
'songs'
:
songs
,
'artist'
:
artist_name
})
\ No newline at end of file
\ No newline at end of file
templates/album.html
View file @
f1663b06
...
@@ -4,7 +4,7 @@
...
@@ -4,7 +4,7 @@
{% block sidebar %}
{% block sidebar %}
<img
src =
"{{
image
}}"
alt=
"No album art available"
>
<img
src =
"{{
result.art
}}"
alt=
"No album art available"
>
<p>
<p>
<b>
{{result.album_name}}
</b>
({{result.year}})
<br>
<b>
{{result.album_name}}
</b>
({{result.year}})
<br>
{{artist}}
<br>
<br>
{{artist}}
<br>
<br>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment