Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
djrandom-py
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ale
djrandom-py
Commits
fe6c8c0f
Commit
fe6c8c0f
authored
13 years ago
by
ale
Browse files
Options
Downloads
Patches
Plain Diff
in the album art cache, when the album name ends with a number, try
querying last.fm again without the number at the end
parent
d9f5497c
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
server/djrandom/model/external.py
+26
-10
26 additions, 10 deletions
server/djrandom/model/external.py
with
26 additions
and
10 deletions
server/djrandom/model/external.py
+
26
−
10
View file @
fe6c8c0f
import
hashlib
import
os
import
re
import
subprocess
import
urllib
import
urllib2
...
...
@@ -12,6 +13,12 @@ class AlbumImageDiskCache(object):
Files are saved and converted to JPEG using Imagemagick. Negative
matches are saved as empty files.
If you want to periodically retry
'
missed
'
entries (to recover from
temporary errors, for example), you can simply run:
find $DIR -type f -size 0 -mtime +$DAYS -exec rm -f \{\} +
"""
def
__init__
(
self
,
root
):
...
...
@@ -61,16 +68,25 @@ class AlbumImageRetriever(object):
def
get_album_image
(
self
,
artist
,
album
):
if
not
self
.
cache
.
has
(
artist
,
album
):
try
:
xml
=
self
.
_get_album_info
(
artist
,
album
)
xp
=
etree
.
XPath
(
'
album/image[@size=
"
extralarge
"
]
'
)
img
=
xp
(
xml
)
if
img
:
self
.
cache
.
download
(
artist
,
album
,
img
[
0
].
text
)
else
:
self
.
cache
.
set_negative_match
(
artist
,
album
)
except
:
return
None
queries
=
[(
artist
,
album
)]
# Fix a minor annoyance that is popular in ID3 tags: if the
# album name ends in a number, it might be part of a series;
# in that case, try again without the number.
m
=
re
.
search
(
r
'
^(.+) \d+$
'
,
album
)
if
m
:
queries
.
append
((
artist
,
m
.
group
(
1
)))
for
query_artist
,
query_album
in
queries
:
try
:
xml
=
self
.
_get_album_info
(
query_artist
,
query_album
)
xp
=
etree
.
XPath
(
'
album/image[@size=
"
extralarge
"
]
'
)
img
=
xp
(
xml
)
if
img
:
self
.
cache
.
download
(
artist
,
album
,
img
[
0
].
text
)
else
:
self
.
cache
.
set_negative_match
(
artist
,
album
)
except
:
continue
break
return
self
.
cache
.
get
(
artist
,
album
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment