commit 9a7afb5a6e03ed08233358773233393030e0b82a
parent 3836e0ca36dd7eb349ec01d3ada3eb299e618baf
Author: lostd <lostd@2f30.org>
Date: Fri, 27 Mar 2015 16:10:24 +0200
Switch to https and auth for images
Diffstat:
3 files changed, 33 insertions(+), 5 deletions(-)
diff --git a/CHANGELOG b/CHANGELOG
@@ -1,3 +1,6 @@
+* Switch to HTTPS and use Discogs Auth through user tokens.
+* Get images only through the API as intended.
+
## 0.1.7
* Fix http requests to work with the current API.
* All stdout output is valid YAML.
diff --git a/README b/README
@@ -103,6 +103,19 @@ Only for image and rdata naming:
zz: zeros that match d + n width
+# Cover artwork support
+
+From March 2015 and onwards cover artwork images are resources restricted
+to authenticated clients. The easiest way to do this and the one supported
+by musicfix is to create a Discogs account and generate a personal access
+token from the developers settings. Add the token in `~/.musicfixrc` like
+this:
+
+ token: abcxyz123456
+
+You'll get no cover artwork without adding your personal access token.
+
+
# Some test releases
* Sound, The (2) – From The Lions Mouth: 377432
diff --git a/bin/musicfix b/bin/musicfix
@@ -78,8 +78,7 @@ def getimgurl rel
return nil unless rel['images']
img = rel['images'].select {|i| i['type'] == 'primary'}.first ||
rel['images'].first
- img['uri'].gsub! 'api.discogs.com/images/R-90', 's.pixogs.com/image/R'
- img['uri'].gsub! 'api.discogs.com/images/', 's.pixogs.com/image/'
+ img['uri']
end
# Construct position list from tracks filter
@@ -206,6 +205,12 @@ if File.exists? cfgpath
cfg.merge! new
end
+# Authentication option
+urlopts = ''
+if cfg['token'] then
+ urlopts = "?token=#{cfg['token']}"
+end
+
# Expand music directory
cfg['mdir'] = File.expand_path cfg['mdir']
@@ -309,10 +314,10 @@ elsif cmd == 'tags' then
else
# Get release data from Discogs
STDERR.puts "Getting release data from Discogs..."
- r = YAML.load(open("http://api.discogs.com/releases/#{relid}",
+ r = YAML.load(open("https://api.discogs.com/releases/#{relid}#{urlopts}",
Headers))
mr = if r['master_id'] then
- YAML.load(open("http://api.discogs.com/masters/#{r['master_id']}",
+ YAML.load(open("https://api.discogs.com/masters/#{r['master_id']}#{urlopts}",
Headers))
end
# Tracklist can contain dummy header tracks, strip them
@@ -443,8 +448,15 @@ imgname = eval cfg['image']
if rel['imgurl'] then
STDERR.puts "Save image to #{imgname}"
unless fake
- img = open(rel['imgurl'], Headers).read
+ # Relative path or URL
+ if File.exists? rel['imgurl']
+ img = open(rel['imgurl']).read
+ else
+ img = open(rel['imgurl'], Headers).read
+ end
File.open(imgname, 'wb').write img
+ # Update to local relative path now
+ rel['imgurl'] = File.basename imgname
end
end
# Also save the release file for future use