mediafile 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/music_cp +4 -0
- data/lib/mediafile/bulkmediacopy.rb +1 -2
- data/lib/mediafile/mediafile.rb +48 -43
- data/lib/mediafile/version.rb +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 58cdd80b30a31b58efb8d9c89adab411a37ce313
|
4
|
+
data.tar.gz: 5ec9d81b1de89e060007a34fe1cdc7b81b4dc7cf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 14def08f1e8b54336384d47f94eda7f090b23be67fbe05d04dfc791db4845b97410cdb25f0a5e8f022b6ccd0691eb1ae23484e63feab3a1a0f27eba17f8534ef
|
7
|
+
data.tar.gz: 5ba30cc867c70413d1ed33312041250e401a68da69281d175e91d788d360b7218b7b45c1eb0a8289d545c1cf2d42e592d247767342d00721d197e219302566ec
|
data/bin/music_cp
CHANGED
@@ -61,6 +61,10 @@ opts = OptionParser.new do |opt|
|
|
61
61
|
"Number of threads to spawn, useful for transcoding. Default: #{count}" ) do |n|
|
62
62
|
count = n.to_i
|
63
63
|
end
|
64
|
+
opt.on("-V", "--version", "Disply the version and exit") do
|
65
|
+
puts MediaFile::VERSION
|
66
|
+
exit 0
|
67
|
+
end
|
64
68
|
opt.on_tail("-h", "--help", "Show this message") do
|
65
69
|
warn opt
|
66
70
|
exit
|
@@ -17,7 +17,6 @@ module MediaFile; class BulkMediaCopy
|
|
17
17
|
MediaFile.new(s,
|
18
18
|
base_dir: @destination_root,
|
19
19
|
verbose: @verbose,
|
20
|
-
|
21
20
|
printer: proc{ |msg| self.safe_print( msg ) }
|
22
21
|
)
|
23
22
|
}
|
@@ -56,7 +55,7 @@ module MediaFile; class BulkMediaCopy
|
|
56
55
|
|
57
56
|
def safe_print(message='')
|
58
57
|
locked {
|
59
|
-
|
58
|
+
print block_given? ? yield : message
|
60
59
|
}
|
61
60
|
end
|
62
61
|
|
data/lib/mediafile/mediafile.rb
CHANGED
@@ -33,11 +33,9 @@ module MediaFile; class MediaFile
|
|
33
33
|
unless File.exists? destination
|
34
34
|
FileUtils.mkdir_p File.dirname destination
|
35
35
|
begin
|
36
|
-
|
37
|
-
transcode
|
38
|
-
|
39
|
-
FileUtils.cp @source, temp_dest
|
40
|
-
end
|
36
|
+
transcode_table.has_key?(@type) ?
|
37
|
+
transcode(transcode_table, temp_dest) :
|
38
|
+
FileUtils.cp(@source, temp_dest)
|
41
39
|
FileUtils.mv temp_dest, destination
|
42
40
|
rescue => e
|
43
41
|
FileUtils.rm temp_dest if File.exists? temp_dest
|
@@ -91,7 +89,7 @@ module MediaFile; class MediaFile
|
|
91
89
|
when :flac
|
92
90
|
raise "Please don't transcode to flac. It is broken right now"
|
93
91
|
%W{flac -7 -V -s -o #{destination}} +
|
94
|
-
(@artist ? ["-T", "artist=#{@artist}"] : [] ) +
|
92
|
+
(@artist ? ["-T", "artist=#{@artist}"] : [] ) +
|
95
93
|
(@title ? ["-T", "title=#{@title}"] : [] ) +
|
96
94
|
(@album ? ["-T", "album=#{@album}"] : [] ) +
|
97
95
|
(@track > 0 ? ["-T", "tracknumber=#{@track}"] : [] ) +
|
@@ -157,19 +155,19 @@ module MediaFile; class MediaFile
|
|
157
155
|
ret
|
158
156
|
end
|
159
157
|
end
|
160
|
-
}
|
158
|
+
}
|
161
159
|
rescue Timeout::Error
|
162
|
-
printit "Timeout exceeded!\n" << tpids.map { |p|
|
160
|
+
printit "Timeout exceeded!\n" << tpids.map { |p|
|
163
161
|
Process.kill 15, p
|
164
162
|
Process.kill 9, p
|
165
163
|
"#{p} #{Process.wait2( p )[1]}"
|
166
164
|
}.join(", ")
|
167
165
|
FileUtils.rm [destination]
|
168
|
-
raise
|
166
|
+
raise
|
169
167
|
end
|
170
168
|
if err.any?
|
171
|
-
printit "
|
172
|
-
|
169
|
+
printit "###\nError transcoding #{@source}: #{err.map{|it,stat| "#{it} EOT:#{stat.exitstatus} #{stat}" }.join(" and ")}\n###\n"
|
170
|
+
exit 1
|
173
171
|
end
|
174
172
|
end
|
175
173
|
|
@@ -185,7 +183,7 @@ module MediaFile; class MediaFile
|
|
185
183
|
}
|
186
184
|
)
|
187
185
|
bool=true
|
188
|
-
@relpath = dest.gsub(/\s/,"_").gsub(/[,:)\]\[('"@$^*<>?!]/,"").gsub(/_[&]_/,"_and_").split('').map{ |c|
|
186
|
+
@relpath = dest.gsub(/\s/,"_").gsub(/[,:)\]\[('"@$^*<>?!]/,"").gsub(/_[&]_/,"_and_").split('').map{ |c|
|
189
187
|
b = bool; bool = c.match('/|_'); b ? c.capitalize : c
|
190
188
|
}.join('').gsub(/__+/,'_')
|
191
189
|
end
|
@@ -194,27 +192,29 @@ module MediaFile; class MediaFile
|
|
194
192
|
# this doesn't include the extension.
|
195
193
|
@newname ||= (
|
196
194
|
read_tags
|
197
|
-
bool=true
|
198
|
-
file= (
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
195
|
+
bool = true
|
196
|
+
file = (
|
197
|
+
case
|
198
|
+
when (@disc_number && (@track > 0) && @title) && !(@disc_total && @disc_total == 1)
|
199
|
+
"%1d_%02d-" % [@disc_number, @track] + @title
|
200
|
+
when (@track > 0 && @title)
|
201
|
+
"%02d-" % @track + @title
|
202
|
+
when @title
|
203
|
+
@title
|
204
|
+
else
|
205
|
+
@name
|
206
|
+
end
|
207
|
+
).gsub(
|
208
|
+
/^\.+|\.+$/,""
|
209
|
+
).gsub(
|
210
|
+
/\//,"_"
|
211
|
+
).gsub(
|
212
|
+
/\s/,"_"
|
213
|
+
).gsub(
|
214
|
+
/[,:)\]\[('"@$^*<>?!]/,""
|
215
|
+
).gsub(
|
216
|
+
/_[&]_/,"_and_"
|
217
|
+
).split('').map{ |c|
|
218
218
|
b = bool; bool = c.match('/|_'); b ? c.capitalize : c
|
219
219
|
}.join('')
|
220
220
|
)
|
@@ -242,8 +242,8 @@ module MediaFile; class MediaFile
|
|
242
242
|
tag = file.tag
|
243
243
|
@album = tag.album if tag.album
|
244
244
|
@artist = tag.artist if tag.artist
|
245
|
-
@title = tag.title if tag.title
|
246
|
-
@genre = tag.genre if tag.genre
|
245
|
+
@title = tag.title if tag.title
|
246
|
+
@genre = tag.genre if tag.genre
|
247
247
|
@comment= tag.comment if tag.comment
|
248
248
|
@track = tag.track if tag.track
|
249
249
|
@year = tag.year if tag.year
|
@@ -253,18 +253,23 @@ module MediaFile; class MediaFile
|
|
253
253
|
case @type
|
254
254
|
when :m4a
|
255
255
|
TagLib::MP4::File.open(@source) do |file|
|
256
|
-
@disc_number = file.tag.item_list_map["disk"]
|
256
|
+
@disc_number = file.tag.item_list_map["disk"] ?
|
257
|
+
file.tag.item_list_map["disk"].to_int_pair[0] :
|
258
|
+
nil
|
259
|
+
@album_artist = file.tag.item_list_map["aART"] ?
|
260
|
+
file.tag.item_list_map["aART"].to_string_list[0]
|
261
|
+
: @album_artist
|
257
262
|
end
|
258
263
|
when :flac
|
259
264
|
TagLib::FLAC::File.open(@source) do |file|
|
260
265
|
if tag = file.xiph_comment
|
261
266
|
[
|
262
|
-
[
|
263
|
-
[
|
264
|
-
[
|
267
|
+
[:@album_artist, ['ALBUMARTIST', 'ALBUM ARTIST', 'ALBUM_ARTIST'], :to_s ],
|
268
|
+
[:@disc_number, ['DISCNUMBER'], :to_i ],
|
269
|
+
[:@disc_total, ['DISCTOTAL'], :to_i ]
|
265
270
|
].each do |field,list,func|
|
266
271
|
val = list.collect{ |i| tag.field_list_map[i] }.select{|i| i }.first
|
267
|
-
instance_variable_set(
|
272
|
+
instance_variable_set(field, val[0].send(func)) if val
|
268
273
|
end
|
269
274
|
end
|
270
275
|
end
|
@@ -272,9 +277,9 @@ module MediaFile; class MediaFile
|
|
272
277
|
TagLib::MPEG::File.open(@source) do |file|
|
273
278
|
tag = file.id3v2_tag
|
274
279
|
if tag
|
275
|
-
[['TPE2',
|
276
|
-
if tag.frame_list(
|
277
|
-
instance_variable_set(
|
280
|
+
[[:@album_artist, 'TPE2', :to_s], [:@disc_number, 'TPOS', :to_i]].each do |field,list,func|
|
281
|
+
if tag.frame_list(list).first and tag.frame_list(list).first.to_s.size > 0
|
282
|
+
instance_variable_set(field, "#{tag.frame_list(list).first}".send(func) )
|
278
283
|
end
|
279
284
|
end
|
280
285
|
end
|
data/lib/mediafile/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mediafile
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeff Harvey-Smith
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-04-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: taglib-ruby
|
@@ -38,11 +38,11 @@ executables:
|
|
38
38
|
extensions: []
|
39
39
|
extra_rdoc_files: []
|
40
40
|
files:
|
41
|
+
- "./bin/music_cp"
|
42
|
+
- "./lib/mediafile.rb"
|
43
|
+
- "./lib/mediafile/bulkmediacopy.rb"
|
41
44
|
- "./lib/mediafile/mediafile.rb"
|
42
45
|
- "./lib/mediafile/version.rb"
|
43
|
-
- "./lib/mediafile/bulkmediacopy.rb"
|
44
|
-
- "./lib/mediafile.rb"
|
45
|
-
- "./bin/music_cp"
|
46
46
|
- bin/music_cp
|
47
47
|
homepage: https://github.com/seginoviax/mediafile
|
48
48
|
licenses:
|
@@ -64,7 +64,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
64
64
|
version: '0'
|
65
65
|
requirements: []
|
66
66
|
rubyforge_project:
|
67
|
-
rubygems_version: 2.
|
67
|
+
rubygems_version: 2.4.6
|
68
68
|
signing_key:
|
69
69
|
specification_version: 4
|
70
70
|
summary: Parse media file metadata.
|