musicfix

music file renamer and tagger
git clone git://git.2f30.org/musicfix
Log | Files | Refs | README | LICENSE

commit b34e26ac39cbe67e9ae4bf992f8d4c97d6ed2040
parent 7f70e5fce32a97e66238d9e6fe33339d19bdcbf1
Author: lostd <lostd@2f30.org>
Date:   Thu, 22 Oct 2015 18:03:53 +0300

Support multiple images for cover art

Diffstat:
MREADME | 4++++
Mbin/musicfix | 49+++++++++++++++++++++++++++++++------------------
2 files changed, 35 insertions(+), 18 deletions(-)

diff --git a/README b/README @@ -102,6 +102,10 @@ Only for image and rdata naming: zz: zeros that match d + n width +Only for image naming: + + i: the index in the list + # Cover artwork support diff --git a/bin/musicfix b/bin/musicfix @@ -74,11 +74,13 @@ def mkname n end # Get cover artwork -def getimgurl rel +def getimages rel return nil unless rel['images'] - img = rel['images'].select {|i| i['type'] == 'primary'}.first || - rel['images'].first - img['uri'] + imgs = [] + rel['images'].each do |img| + imgs << img['uri'] + end + imgs end # Construct position list from tracks filter @@ -201,9 +203,10 @@ end cfg = {} cfg['mdir'] = '~/music' cfg['track'] = '"#{mdir}/#{fba}-#{my}-#{fb}-#{fv}/#{d}#{fn}-#{fa}-#{ft}.#{x}"' -cfg['image'] = '"#{mdir}/#{fba}-#{my}-#{fb}-#{fv}/#{zz}-#{fba}-#{fb}_cover.jpg"' +cfg['image'] = '"#{mdir}/#{fba}-#{my}-#{fb}-#{fv}/#{zz}-#{fba}-#{fb}_cover#{i}.jpg"' cfg['rdata'] = '"#{mdir}/#{fba}-#{my}-#{fb}-#{fv}/#{zz}-#{fba}-#{fb}_release.yaml"' #cfg['after'] = '"mpc update #{fba}-#{my}-#{fb}-#{fv}"' +cfg['nimg'] = 1 # User configuration overrides cfgpath = File.expand_path('~/.musicfixrc') @@ -283,7 +286,7 @@ elsif cmd == 'tags' then rel['genre'] = [] rel['format'] = nil rel['comment'] = [] - rel['imgurl'] = nil + rel['images'] = nil rel['tracklist'] = [] # Populate tracklist fl.each do |fname| @@ -358,7 +361,7 @@ else if tracks then rel['comment'] += ", tracks: #{tracks}" end - rel['imgurl'] = getimgurl r + rel['images'] = getimages(r).first(cfg['nimg']) rel['tracklist'] = [] # Populate tracklist tl.each do |s| @@ -451,20 +454,30 @@ end # Also save the first image of the artwork zz = '0' * (mkdiscnum tl.first['pos'].to_s).join.length -imgname = eval cfg['image'] -if rel['imgurl'] then - STDERR.puts "Save image to #{imgname}" - unless fake - # Relative path or URL - if File.exists? rel['imgurl'] - FileUtils.copy rel['imgurl'], imgname - else - img = open(rel['imgurl'], Headers).read +if rel['images'] then + relimgs = [] + rel['images'].each_with_index do |imgurl, idx| + pad = rel['images'].length.to_s.length + i = idx.to_s.rjust(pad, '0') + if rel['images'].length == 1 + i = '' + end + # The variable i can be used in the image template + imgname = eval cfg['image'] + STDERR.puts "Save image to #{imgname}" + unless fake + # Relative path or URL + if File.exists? imgurl + img = open(imgurl).read + else + img = open(imgurl, Headers).read + end File.open(imgname, 'wb').write img + # Update to local relative path now + relimgs << (File.basename imgname) end - # Update to local relative path now - rel['imgurl'] = File.basename imgname end + rel['images'] = relimgs end # Also save the release file for future use relfile = eval cfg['rdata']