musicfix 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +4 -0
  3. data/LICENSE +1 -1
  4. data/README +30 -8
  5. data/bin/musicfix +106 -14
  6. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9b6c21ec0e1a27c4204d70c304f94b98f2992197
4
- data.tar.gz: 715fc3b30320e2e58c9260e1c0d86728b94a24f2
3
+ metadata.gz: 95f3528586137687c1f38dafeb11fdc2666c9f51
4
+ data.tar.gz: 680c84a9847bdfbfe5bcfd21d5a8bc7dc7169ebf
5
5
  SHA512:
6
- metadata.gz: 84809c52ad13adf4297ec81270a5e1f8b6274d08089a8918c9dc26aaa5576a1a12c7c589f6e50b8207e6b58d6a09e7ee7c4fb97f1a7ac5edc34ce9ad1629beb6
7
- data.tar.gz: a8cf51d8efc196aa9bfd3c6aa205870287814cb85badf7c16b2e9f6b02fd5026f4db34ea3d9a987230d7d2db03930976e6e4e34f4da12b45dcb2b6513287b3cf
6
+ metadata.gz: 11b7c508f935e211ec32939fef9b84ba08309b2d6d4a4a60de14314824cce6b4cb45cbcbdc9557c061513830aaf0411c494a96d1ec5399ec5b2c12fba59fd3eb
7
+ data.tar.gz: 7138bb4481a4e627a4d0a7a5972a145703155afadfbc6b80a0e4fc3115f54dd01ecf0244f92501dd5a6a57ed56229359b04cf50e8e8bb0b6af2b65e1bfd29e48
data/CHANGELOG CHANGED
@@ -1,3 +1,7 @@
1
+ ## 0.1.6
2
+ * Can now generate release files from audio file tags.
3
+ * Add the release metadata saving functionality and loading logic.
4
+
1
5
  ## 0.1.5
2
6
  * Dummy song entries have empty pos, not nil (came with JSON change).
3
7
 
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2012--2013 Lazaros Koromilas <lostd@2f30.org>
1
+ Copyright (c) 2012--2014 Lazaros Koromilas <lostd@2f30.org>
2
2
  All rights reserved.
3
3
 
4
4
  Redistribution and use in source and binary forms, with or without
data/README CHANGED
@@ -1,4 +1,4 @@
1
- # $Id: README,v 1.14 2013/11/08 19:06:13 lostd Exp $
1
+ # $Id: README,v 1.17 2014/01/12 17:03:44 lostd Exp $
2
2
 
3
3
  # Description
4
4
 
@@ -18,9 +18,15 @@ to the program. Enjoy!
18
18
 
19
19
  # Usage
20
20
 
21
- $ musicfix [fake] relid [tracks]
22
- $ musicfix [fake] dump relid [relfile]
23
- $ musicfix [fake] load [relfile]
21
+ $ musicfix
22
+ Usage: musicfix [fake] relid [tracks]
23
+ musicfix [fake] dump relid [relfile]
24
+ musicfix [fake] load [relfile]
25
+ musicfix [fake] tags [relfile]
26
+
27
+ The common path is to just give the release id:
28
+
29
+ $ musicfix 1234
24
30
 
25
31
  More sophisticated track selection can be performed by providing
26
32
  a tracks selector command line argument of the form:
@@ -34,7 +40,22 @@ in order to dump information from Discogs.com and/or load the information
34
40
  from file. This way you can generate a base release file, edit to
35
41
  your needs, and then use it for tagging and renaming. The fake prefix
36
42
  on all commands results in no files to be copied/written and no cover
37
- artwork to be downloaded.
43
+ artwork to be downloaded. For example:
44
+
45
+ $ musicfix dump 1234
46
+ $ musicfix fake load
47
+ $ musicfix load
48
+
49
+ You may also generate a release file using the existing audio file tags
50
+ and use that file instead:
51
+
52
+ $ musicfix tags
53
+ $ musicfix load
54
+
55
+ The release metadata is saved together with the music files by default,
56
+ and the load command looks for any YAML files in the current directory
57
+ (if there is no relfile specified and `release.yaml` does not exist).
58
+ This is useful for renaming files again using a new naming scheme.
38
59
 
39
60
 
40
61
  # Configuration
@@ -46,11 +67,12 @@ containing:
46
67
 
47
68
  mdir: ~/music/fixed
48
69
 
49
- Furthermore, templates are used for the naming of music files
50
- and the cover artwork image. The defaults are:
70
+ Furthermore, templates are used for the naming of music files, the
71
+ cover artwork image and the release metadata file. The defaults are:
51
72
 
52
73
  track: '"#{mdir}/#{fba}-#{my}-#{fb}-#{fv}/#{d}#{fn}-#{fa}-#{ft}.#{x}"'
53
74
  image: '"#{mdir}/#{fba}-#{my}-#{fb}-#{fv}/#{zz}-#{fba}-#{fb}_cover.jpg"'
75
+ rdata: '"#{mdir}/#{fba}-#{my}-#{fb}-#{fv}/#{zz}-#{fba}-#{fb}_release.yaml"'
54
76
 
55
77
  To run a shell command upon completion use the `after` attribute.
56
78
  For example, to update the MPD database:
@@ -78,7 +100,7 @@ Only for track naming:
78
100
  tn: track number counter
79
101
  x: file extension in lowercase
80
102
 
81
- Only for image naming:
103
+ Only for image and rdata naming:
82
104
 
83
105
  zz: zeros that match d + n width
84
106
 
data/bin/musicfix CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
  # encoding: utf-8
3
3
 
4
- # $Id: musicfix,v 1.53 2013/11/11 14:46:42 lostd Exp $
4
+ # $Id: musicfix,v 1.60 2014/01/12 17:40:11 lostd Exp $
5
5
 
6
6
  require 'rubygems'
7
7
  require 'fileutils'
@@ -11,8 +11,8 @@ require 'taglib'
11
11
  require 'yaml'
12
12
 
13
13
  # Headers
14
- Ver = '0.1.4'
15
- Homepage = 'http://www.2f30.org/~lostd/musicfix/'
14
+ Ver = '0.1.6'
15
+ Homepage = 'http://git.2f30.org/musicfix/'
16
16
  Headers = {'User-Agent' => "musicfix/#{Ver} +#{Homepage}"}
17
17
 
18
18
  # Concatenate artist list using '&'
@@ -124,6 +124,7 @@ def mkshort n
124
124
  'Picture Disc' => 'Pic',
125
125
  'Flexi-disc' => 'Flexi',
126
126
  'Reissue' => 'RE',
127
+ 'Remastered' => 'RM',
127
128
  'Remaster' => 'RM',
128
129
  'Repress' => 'RP',
129
130
  'Mispress' => 'MP',
@@ -144,20 +145,32 @@ def mkshort n
144
145
  n.gsub(ftre, ft)
145
146
  end
146
147
 
148
+ # Return single item if array is full of duplicates
149
+ def flatten_if_one ary
150
+ if ary.uniq.length == 1 then
151
+ ary.first
152
+ else
153
+ ary.uniq
154
+ end
155
+ end
156
+
147
157
  # Parse command line
148
158
  usage = ''
149
159
  usage << "Usage: musicfix [fake] relid [tracks]\n"
150
160
  usage << " musicfix [fake] dump relid [relfile]\n"
151
161
  usage << " musicfix [fake] load [relfile]\n"
162
+ usage << " musicfix [fake] tags [relfile]\n"
152
163
  fake = ARGV[0] == 'fake'
153
164
  ARGV.delete 'fake'
154
165
  cmd = ARGV[0] || (puts usage; exit)
155
166
  case cmd
156
167
  when 'load' then
157
- relfile = ARGV[1] || 'release.yaml'
168
+ relfile = ARGV[1] || nil
158
169
  when 'dump' then
159
170
  relid = ARGV[1] || (puts usage; exit)
160
171
  relfile = ARGV[2] || 'release.yaml'
172
+ when 'tags' then
173
+ relfile = ARGV[1] || 'release.yaml'
161
174
  else
162
175
  relid = ARGV[0]
163
176
  tracks = ARGV[1] || nil
@@ -168,6 +181,7 @@ cfg = {}
168
181
  cfg['mdir'] = '~/music'
169
182
  cfg['track'] = '"#{mdir}/#{fba}-#{my}-#{fb}-#{fv}/#{d}#{fn}-#{fa}-#{ft}.#{x}"'
170
183
  cfg['image'] = '"#{mdir}/#{fba}-#{my}-#{fb}-#{fv}/#{zz}-#{fba}-#{fb}_cover.jpg"'
184
+ cfg['rdata'] = '"#{mdir}/#{fba}-#{my}-#{fb}-#{fv}/#{zz}-#{fba}-#{fb}_release.yaml"'
171
185
  #cfg['after'] = '"mpc update #{fba}-#{my}-#{fb}-#{fv}"'
172
186
 
173
187
  # User configuration overrides
@@ -184,6 +198,14 @@ cfg['mdir'] = File.expand_path cfg['mdir']
184
198
  puts 'Configuration'
185
199
  puts cfg.to_yaml
186
200
 
201
+ # Early file checks
202
+ if cmd == 'dump' or cmd == 'tags' then
203
+ if File.exists? relfile then
204
+ puts "Release file #{relfile} exists!"
205
+ exit
206
+ end
207
+ end
208
+
187
209
  unless cmd == 'dump' then
188
210
  # Supported formats
189
211
  fmtre = /mp3|ogg|m4a|mpc|flac|wv/i
@@ -201,16 +223,76 @@ end
201
223
  # Initialize release info
202
224
  if cmd == 'load' then
203
225
  # Load release data from file
204
- if File.exists? relfile then
205
- puts "Loading release data..."
206
- rel = YAML.load File.open(relfile, 'r')
226
+ if relfile then
227
+ # The user specified some file
228
+ unless File.exists? relfile then
229
+ puts "Release file #{relfile} not found!"
230
+ exit
231
+ end
207
232
  else
208
- puts "Release file #{relfile} not found."
209
- exit
233
+ # Look for 'release.yaml' first
234
+ if File.exists? 'release.yaml' then
235
+ relfile = 'release.yaml'
236
+ else
237
+ # Look for any '.yaml' file
238
+ relfl = Dir['*'].select {|f| File.extname(f).match /yaml/i}
239
+ relfile = relfl.sort.first
240
+ end
241
+ unless relfile then
242
+ puts 'No release file found!'
243
+ exit
244
+ end
245
+ end
246
+ puts "Loading release data..."
247
+ rel = YAML.load File.open(relfile, 'r')
248
+ elsif cmd == 'tags' then
249
+ # Generate release file from audio file tags
250
+ rel = {}
251
+ rel['artist'] = []
252
+ rel['album'] = []
253
+ rel['year'] = []
254
+ rel['masteryear'] = nil
255
+ rel['genre'] = []
256
+ rel['format'] = nil
257
+ rel['comment'] = []
258
+ rel['imgurl'] = nil
259
+ rel['tracklist'] = []
260
+ # Populate tracklist
261
+ fl.each do |fname|
262
+ TagLib::FileRef.open(fname) do |f|
263
+ trk = {}
264
+ trk['pos'] = f.tag.track
265
+ trk['artist'] = f.tag.artist
266
+ trk['title'] = f.tag.title
267
+ rel['tracklist'] << trk
268
+ # Make lists and flatten afterwards
269
+ rel['artist'] << f.tag.artist
270
+ rel['album'] << f.tag.album
271
+ rel['year'] << f.tag.year
272
+ rel['genre'] << f.tag.genre
273
+ rel['comment'] << f.tag.comment
274
+ end
210
275
  end
276
+ if rel['artist'].uniq.length == 1 then
277
+ # Single-artist release
278
+ rel['artist'] = rel['artist'].first
279
+ rel['tracklist'].each do |trk|
280
+ trk.delete 'artist'
281
+ end
282
+ else
283
+ rel['artist'] = 'Various'
284
+ end
285
+ # These should be the same on all files
286
+ rel['album'] = flatten_if_one rel['album']
287
+ rel['year'] = flatten_if_one rel['year']
288
+ rel['genre'] = flatten_if_one rel['genre']
289
+ rel['comment'] = flatten_if_one rel['comment']
290
+ # Assumptions
291
+ rel['masteryear'] = rel['year']
292
+ rel['format'] = 'CD'
211
293
  else
212
294
  # Get release data from Discogs
213
- puts "Geting release data..."
295
+ puts "Getting release data..."
214
296
  r = YAML.load(open("http://api.discogs.com/release/#{relid}?f=json",
215
297
  Headers))['resp']['release']
216
298
  mr = if r['master_id'] then
@@ -252,7 +334,7 @@ end
252
334
 
253
335
  # Output release info
254
336
  puts rel.to_yaml
255
- if cmd == 'dump' then
337
+ if cmd == 'dump' or cmd == 'tags' then
256
338
  unless fake
257
339
  File.open(relfile, 'w') do |f|
258
340
  f.puts rel.to_yaml
@@ -329,18 +411,28 @@ end
329
411
  zz = '0' * (mkdiscnum tl.last['pos'].to_s).join.length
330
412
  imgname = eval cfg['image']
331
413
  if rel['imgurl'] then
332
- puts "Save cover to #{imgname}"
414
+ puts "Save image to #{imgname}"
333
415
  unless fake
334
416
  img = open(rel['imgurl'], Headers).read
335
417
  File.open(imgname, 'wb').write img
336
418
  end
337
419
  end
420
+ # Also save the release file for future use
421
+ relfile = eval cfg['rdata']
422
+ puts "Save rdata to #{relfile}"
423
+ unless fake
424
+ File.open(relfile, 'w') do |f|
425
+ f.puts rel.to_yaml
426
+ end
427
+ end
338
428
 
339
429
  # Execute command if provided
340
430
  if cfg['after'] then
341
431
  puts "Executing finishing command"
342
- run = eval cfg['after']
343
- `#{run}`
432
+ unless fake
433
+ run = eval cfg['after']
434
+ `#{run}`
435
+ end
344
436
  end
345
437
 
346
438
  # vim:set ts=4 sw=4 et:
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: musicfix
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lazaros Koromilas
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-11 00:00:00.000000000 Z
11
+ date: 2014-01-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: stringex
@@ -50,7 +50,7 @@ files:
50
50
  - README
51
51
  - LICENSE
52
52
  - CHANGELOG
53
- homepage: http://www.2f30.org/~lostd/musicfix/
53
+ homepage: http://git.2f30.org/musicfix/
54
54
  licenses:
55
55
  - BSD
56
56
  metadata: {}