musicfix 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +11 -0
  3. data/README +2 -2
  4. data/bin/musicfix +77 -45
  5. metadata +4 -17
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4f5c80d51297e9111600c9203d0623943d250d8b
4
- data.tar.gz: 8ddb775d3aa6f2a3c83497a3b9aa159bb47d708f
3
+ metadata.gz: a17bc779557199bbf5d0a2a0fb73e8f2eba7111e
4
+ data.tar.gz: 718671ebe4f9ec0b17f1b9b041cec160dfb194af
5
5
  SHA512:
6
- metadata.gz: 7cac8a4e9c952c4301c111bb650f40f73c7a645af434bba9969a11fde6d007c83098002293e9e0df70a106e9cf6c0352dfbc0632c02ecb9ecf42e02bbf262885
7
- data.tar.gz: 3e761cb2de179b64a7456db4c0d3a8dfcc19a343db7bff57815e492808111e280ecc936bf8f8290cf91ac998af3a40a004bb67da6289b4108cc119d2a0694893
6
+ metadata.gz: 58271c448ab3602583c315ac1aef9439613c82ea64edc5c974d442dd4d161c63bef2693de599948b086a77e5b4011881b28c138d370d0029a0d0b1ef862d0b89
7
+ data.tar.gz: 39018cb6b5fc1092952b1ced6bb27cd1103a639fedc2382635c2b6021c524c6e1be5dad317bece6b4e0a0a494b8a3d3836198cee7edb1ef3ce4eca01b425c08d
@@ -0,0 +1,11 @@
1
+ ## 0.1.4
2
+ * Remove the discogs-wrapper gem dependency and directly call the
3
+ Discogs API with JSON output format.
4
+ * Most of the common release format abbreviations are in place.
5
+ * Always start numbering of track lists from 1 ("A" becomes "A1").
6
+ * Numbering in artist name can also appear before the article, strip it.
7
+
8
+ ## 0.1.3
9
+ * Release format string is now abbreviated for file naming.
10
+ * Add the fake command prefix to avoid writing to disk.
11
+ * Start to keep a change log.
data/README CHANGED
@@ -1,4 +1,4 @@
1
- # $Id: README,v 1.13 2013/06/27 15:30:07 lostd Exp $
1
+ # $Id: README,v 1.14 2013/11/08 19:06:13 lostd Exp $
2
2
 
3
3
  # Description
4
4
 
@@ -13,7 +13,7 @@ to the program. Enjoy!
13
13
  # Dependencies
14
14
 
15
15
  * System packages: taglib
16
- * Ruby gems: discogs-wrapper stringex taglib-ruby
16
+ * Ruby gems: stringex taglib-ruby
17
17
 
18
18
 
19
19
  # Usage
@@ -1,27 +1,33 @@
1
1
  #!/usr/bin/env ruby
2
2
  # encoding: utf-8
3
3
 
4
- # $Id: musicfix,v 1.39 2013/08/06 10:42:41 lostd Exp $
4
+ # $Id: musicfix,v 1.52 2013/11/11 11:15:10 lostd Exp $
5
5
 
6
6
  require 'rubygems'
7
7
  require 'fileutils'
8
8
  require 'open-uri'
9
- require 'discogs'
10
9
  require 'stringex'
11
10
  require 'taglib'
12
11
  require 'yaml'
13
12
 
13
+ # Headers
14
+ Ver = '0.1.4'
15
+ Homepage = 'http://www.2f30.org/~lostd/musicfix/'
16
+ Headers = {'User-Agent' => "musicfix/#{Ver} +#{Homepage}"}
17
+
14
18
  # Concatenate artist list using '&'
15
19
  # Convert "Sound, The (2)" to "The Sound"
20
+ # Convert "Unknown (21), The" to "The Unknown"
16
21
  def mkartist al
17
- nl = al.collect {|a| a.name}
22
+ nl = al.collect {|a| a['name']}
18
23
  nl.each {|n| n.gsub! /\s\(\d+\)$/, ''}
19
24
  nl.each {|n| n.gsub! /(.*), The$/, 'The \1'}
25
+ nl.each {|n| n.gsub! /\s\(\d+\)$/, ''}
20
26
  nl.join ' & '
21
27
  end
22
28
 
23
29
  # Convert "3" to (nil, "03")
24
- # Convert "A" to (nil, "A0")
30
+ # Convert "A" to (nil, "A1")
25
31
  # Convert "A3" to (nil, "A3")
26
32
  # Convert "2.3" to ("2", "03")
27
33
  # Convert "2.03" to ("2", "03")
@@ -36,7 +42,7 @@ def mkdiscnum pos
36
42
  d = d.gsub /\D/, ''
37
43
  end
38
44
  if n.match /[A-Z]/
39
- n = n.ljust(2, '0')
45
+ n = n.ljust(2, '1')
40
46
  else
41
47
  n = n.rjust(2, '0')
42
48
  end
@@ -64,10 +70,10 @@ end
64
70
 
65
71
  # Get cover artwork
66
72
  def getimgurl rel
67
- return nil unless rel.images
68
- img = rel.images.select {|i| i.type == 'primary'}.first ||
69
- rel.images.first
70
- img.uri.gsub 'api.discogs.com', 's.pixogs.com'
73
+ return nil unless rel['images']
74
+ img = rel['images'].select {|i| i['type'] == 'primary'}.first ||
75
+ rel['images'].first
76
+ img['uri']
71
77
  end
72
78
 
73
79
  # Construct position list from tracks filter
@@ -92,27 +98,50 @@ end
92
98
 
93
99
  # Make a sane format string also using format description
94
100
  def mkformat format
95
- if format.descriptions
96
- "#{format.descriptions.first} #{format.name}"
97
- else
98
- "#{format.name}"
101
+ f = []
102
+ # Ignore in favor of LP/EP/7"/12" descriptions
103
+ unless format['name'] == "Vinyl"
104
+ f << format['name']
99
105
  end
106
+ if format['descriptions']
107
+ # Too general
108
+ format['descriptions'].delete "Album"
109
+ unless format['descriptions'].empty?
110
+ f << format['descriptions'].first
111
+ end
112
+ end
113
+ f.join ' '
100
114
  end
101
115
 
102
116
  # Shorten certain common words that appear in format strings
103
117
  def mkshort n
104
- n = n.gsub "Album CD", "CD"
105
- n = n.gsub "LP Vinyl", "LP"
106
- n = n.gsub "EP Vinyl", "EP"
107
- n = n.gsub "Mini-Album Vinyl", "MiniLP"
108
- n = n.gsub '12" Vinyl', '12inch'
109
- n = n.gsub '7" Vinyl', '7inch'
110
- n = n.gsub "Cassette", "Cass"
111
- n = n.gsub "Limited Edition", "Ltd"
112
- n = n.gsub "Compilation", "Comp"
113
- n = n.gsub "Reissue", "RE"
114
- n = n.gsub "Enhanced", "Enh"
115
- n = n.gsub "Unofficial Release", "Unofficial"
118
+ ft = {
119
+ 'Cassette' => 'Cass',
120
+ '12"' => '12inch',
121
+ '7"' => '7inch',
122
+ 'Mini-Album' => 'MiniAlbum',
123
+ 'Maxi-Single' => 'Maxi',
124
+ 'Picture Disc' => 'Pic',
125
+ 'Flexi-disc' => 'Flexi',
126
+ 'Reissue' => 'RE',
127
+ 'Remaster' => 'RM',
128
+ 'Repress' => 'RP',
129
+ 'Mispress' => 'MP',
130
+ 'Test Pressing' => 'TP',
131
+ 'Enhanced' => 'Enh',
132
+ 'Digipak ' => 'Dig',
133
+ 'Box Set' => 'Box',
134
+ 'Limited Edition' => 'Ltd',
135
+ 'Club Edition' => 'Club',
136
+ 'Compilation' => 'Comp',
137
+ 'Sampler' => 'Smplr',
138
+ 'Numbered' => 'Num',
139
+ 'Unofficial Release' => 'Unofficial',
140
+ 'Single Sided' => 'S/Sided',
141
+ }
142
+ # Note that prefix substitution is broken
143
+ ftre = /(#{ft.keys.join('|')})/
144
+ n.gsub(ftre, ft)
116
145
  end
117
146
 
118
147
  # Parse command line
@@ -182,38 +211,41 @@ if cmd == 'load' then
182
211
  else
183
212
  # Get release data from Discogs
184
213
  puts "Geting release data..."
185
- discogs = Discogs::Wrapper.new("musicfix")
186
- r = discogs.get_release(relid)
187
- mr = if r.master_id then discogs.get_master_release(r.master_id) end
214
+ r = YAML.load(open("http://api.discogs.com/release/#{relid}?f=json",
215
+ Headers))['resp']['release']
216
+ mr = if r['master_id'] then
217
+ YAML.load(open("http://api.discogs.com/master/#{r['master_id']}?f=json",
218
+ Headers))['resp']['master']
219
+ end
188
220
  # Tracklist can contain dummy header tracks, strip them
189
- tl = r.tracklist.select {|t| t.position}
221
+ tl = r['tracklist'].select {|t| t['position']}
190
222
  # Apply tracks filter if given
191
223
  if tracks then
192
224
  pl = mkposlist tracks
193
225
  puts "Invalid tracks filter: #{tracks}" unless pl
194
- tl = tl.select {|t| pl.include? t.position}
226
+ tl = tl.select {|t| pl.include? t['position']}
195
227
  end
196
228
  # Gather release-wide data
197
229
  rel = {}
198
- rel['artist'] = mkartist r.artists
199
- rel['album'] = r.title
200
- rel['year'] = r.released
201
- rel['masteryear'] = if mr then mr.year end || r.released
230
+ rel['artist'] = mkartist r['artists']
231
+ rel['album'] = r['title']
232
+ rel['year'] = r['released']
233
+ rel['masteryear'] = if mr then mr['year'] end || r['released']
202
234
  # Year can be full-date so keep only the year part
203
- rel['year'] = rel['year'].slice(0..3)
204
- rel['masteryear'] = rel['masteryear'].slice(0..3)
205
- rel['genre'] = if r.styles then r.styles.first end ||
206
- if r.genres then r.genres.first end
207
- rel['format'] = mkformat r.formats.first
208
- rel['comment'] = "Discogs: #{r.id}"
235
+ rel['year'] = rel['year'].to_s.slice(0..3).to_i
236
+ rel['masteryear'] = rel['masteryear'].to_s.slice(0..3).to_i
237
+ rel['genre'] = if r['styles'] then r['styles'].first end ||
238
+ if r['genres'] then r['genres'].first end
239
+ rel['format'] = mkformat r['formats'].first
240
+ rel['comment'] = "Discogs: #{r['id']}"
209
241
  rel['imgurl'] = getimgurl r
210
242
  rel['tracklist'] = []
211
243
  # Populate tracklist
212
244
  tl.each do |s|
213
245
  trk = {}
214
- trk['pos'] = s.position
215
- trk['artist'] = mkartist s.artists if s.artists
216
- trk['title'] = s.title
246
+ trk['pos'] = s['position']
247
+ trk['artist'] = mkartist s['artists'] if s['artists']
248
+ trk['title'] = s['title']
217
249
  rel['tracklist'] << trk
218
250
  end
219
251
  end
@@ -285,7 +317,7 @@ fl.each do |ofname|
285
317
  f.tag.album = b
286
318
  f.tag.title = t
287
319
  f.tag.track = tn
288
- f.tag.year = y.to_i
320
+ f.tag.year = y
289
321
  f.tag.genre = g
290
322
  f.tag.comment = c
291
323
  f.save
@@ -299,7 +331,7 @@ imgname = eval cfg['image']
299
331
  if rel['imgurl'] then
300
332
  puts "Save cover to #{imgname}"
301
333
  unless fake
302
- img = open(rel['imgurl'], {"User-Agent" => "Mozilla 5.0"}).read
334
+ img = open(rel['imgurl'], Headers).read
303
335
  File.open(imgname, 'wb').write img
304
336
  end
305
337
  end
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: musicfix
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
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-08-07 00:00:00.000000000 Z
11
+ date: 2013-11-11 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: discogs-wrapper
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - '>='
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - '>='
25
- - !ruby/object:Gem::Version
26
- version: '0'
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: stringex
29
15
  requirement: !ruby/object:Gem::Requirement
@@ -63,7 +49,8 @@ files:
63
49
  - bin/musicfix
64
50
  - README
65
51
  - LICENSE
66
- homepage: http://www.2f30.org/~lostd/musicfix
52
+ - CHANGELOG
53
+ homepage: http://www.2f30.org/~lostd/musicfix/
67
54
  licenses:
68
55
  - BSD
69
56
  metadata: {}