musicfix

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

commit 883b790d72d1cb008a615c19784435c1ad2f9afb
parent 5e18c9451d1210be1e582e1aa0e2fc8552445e17
Author: lostd <lostd@2f30.org>
Date:   Thu, 27 Jun 2013 15:19:03 +0000

Introduce the fake command prefix

Diffstat:
MREADME | 12+++++++-----
Mbin/musicfix | 44++++++++++++++++++++++++++------------------
2 files changed, 33 insertions(+), 23 deletions(-)

diff --git a/README b/README @@ -18,12 +18,12 @@ to the program. Enjoy! # Usage - $ musicfix relid [tracks] - $ musicfix dump relid [relfile] - $ musicfix load [relfile] + $ musicfix [fake] relid [tracks] + $ musicfix [fake] dump relid [relfile] + $ musicfix [fake] load [relfile] More sophisticated track selection can be performed by providing -a second command line argument of the form: +a tracks selector command line argument of the form: "1--3,5,8" "A2--A4,B3" @@ -32,7 +32,9 @@ a second command line argument of the form: Alternatively, YAML metadata files can be used (`release.yaml` by default) in order to dump information from Discogs.com and/or load the information from file. This way you can generate a base release file, edit to -your needs, and then use it for tagging and renaming. +your needs, and then use it for tagging and renaming. The fake prefix +on all commands results in no files to be copied/written and no cover +artwork to be downloaded. # Configuration diff --git a/bin/musicfix b/bin/musicfix @@ -112,9 +112,11 @@ end # Parse command line usage = '' -usage << "Usage: musicfix relid [tracks]\n" -usage << " musicfix dump relid [relfile]\n" -usage << " musicfix load [relfile]\n" +usage << "Usage: musicfix [fake] relid [tracks]\n" +usage << " musicfix [fake] dump relid [relfile]\n" +usage << " musicfix [fake] load [relfile]\n" +fake = ARGV[0] == 'fake' +ARGV.delete 'fake' cmd = ARGV[0] || (puts usage; exit) case cmd when 'load' then @@ -214,8 +216,10 @@ end # Output release info puts rel.to_yaml if cmd == 'dump' then - File.open(relfile, 'w') do |f| - f.puts rel.to_yaml + unless fake + File.open(relfile, 'w') do |f| + f.puts rel.to_yaml + end end exit end @@ -268,17 +272,19 @@ fl.each do |ofname| x = File.extname(ofname).delete('.').downcase nfname = eval cfg['track'] puts "Copy track to #{nfname}" - FileUtils.makedirs(File.dirname nfname) - FileUtils.copy(ofname, nfname) - TagLib::FileRef.open(nfname) do |f| - f.tag.artist = a - f.tag.album = b - f.tag.title = t - f.tag.track = tn - f.tag.year = y.to_i - f.tag.genre = g - f.tag.comment = c - f.save + unless fake + FileUtils.makedirs(File.dirname nfname) + FileUtils.copy(ofname, nfname) + TagLib::FileRef.open(nfname) do |f| + f.tag.artist = a + f.tag.album = b + f.tag.title = t + f.tag.track = tn + f.tag.year = y.to_i + f.tag.genre = g + f.tag.comment = c + f.save + end end end @@ -287,8 +293,10 @@ zz = '0' * (mkdiscnum tl.last['pos'].to_s).join.length imgname = eval cfg['image'] if rel['imgurl'] then puts "Save cover to #{imgname}" - img = open(rel['imgurl'], {"User-Agent" => "Mozilla"}).read - File.open(imgname, 'wb').write img + unless fake + img = open(rel['imgurl'], {"User-Agent" => "Mozilla"}).read + File.open(imgname, 'wb').write img + end end # Execute command if provided