mediafile 0.2.7 → 0.2.8

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cc13f96b854bf7530041bbb3fb933e4b823f2332
4
- data.tar.gz: 4d1460b5f152ba6d99697eb769fe27b2b9dc7b6e
3
+ metadata.gz: 7c4b1216b3ffd74a6488945a3be0cafc10a96af3
4
+ data.tar.gz: 7e4adb066b6eddfcd9a6862fb2383af1339e77e6
5
5
  SHA512:
6
- metadata.gz: 48d24d5bb657053fafd6e4c4c91e26419bffc71de1e2a38ac0a5fbda4b3a0ca603ca46c78b93bd10195f8b5c9763b62243598c9426e4563cf5cfce9f426ffd0e
7
- data.tar.gz: d806f7edd72ba8c5656558f9f1cf0ba825059a4ab3a87c53e40ce1a78e614dfd0ae944625dd00ff4f8d68e7791cd082fed0221639b0652ace78e1c1d8b2b4b9a
6
+ metadata.gz: e42b66074d3e6e7830c3262108a32d15885a784e186fbdb5b33184def4d49b733d9fcb55b2e61a0b4144253d3ea2623eb7e3c9aff1789345ec08fddfeb30d4c3
7
+ data.tar.gz: de6e8a15eeba5e7fb2c2d83dd57c777d4b7e2852407254097875bf46e1592ca85a4fea1b08262dbb0df3d8ef7bf8842c8e9ef71f82f2711af921526ee955b05a
data/bin/music_cp CHANGED
@@ -149,7 +149,7 @@ if files.empty?
149
149
  exit
150
150
  end
151
151
  puts "Full list of files to transfer to #{dest}:"
152
- files.each { |l| puts "\t" + l }
152
+ files.each { |l| puts " #{l}" }
153
153
  puts "#{files.count} files total"
154
154
  puts 'The following transcode table will be used:'
155
155
  puts transcode.any? ? transcode : 'none'
@@ -58,9 +58,17 @@ class BulkMediaCopy
58
58
  "(~%.2f songs/second))." % [(@count/duration)]
59
59
  dupes = @copies.select{ |_k,a| a.size > 1 }
60
60
  if dupes.any?
61
- puts "dupes"
62
- require 'pp'
63
- pp dupes
61
+ msg = "*** Same file with multiple names detected ***"
62
+ puts
63
+ puts msg
64
+ puts "=" * msg.size
65
+ dupes.each do |k,v|
66
+ puts "#{k}:"
67
+ v.each do |a|
68
+ puts " #{a}"
69
+ end
70
+ end
71
+ puts
64
72
  end
65
73
  if @failed.any?
66
74
  puts "Some files failed to transfer."
@@ -108,9 +116,8 @@ class BulkMediaCopy
108
116
  end
109
117
 
110
118
  def copy(mediafile)
111
- dest = mediafile.out_path transcode_table: @transcode
112
119
  lock {
113
- return unless copy_check? mediafile.source_md5, mediafile.source, dest
120
+ return unless copy_check?(mediafile)
114
121
  @count += 1
115
122
  if @progress
116
123
  left = @work.count - @count
@@ -121,7 +128,7 @@ class BulkMediaCopy
121
128
  finished = @count.to_f / @work.count * 100
122
129
  f = finished == 100.0
123
130
  action = case
124
- when File.exists?(dest)
131
+ when File.exist?(mediafile.out_path(transcode_table: @transcode))
125
132
  'target already exists'
126
133
  when @transcode[mediafile.type]
127
134
  'transcode'
@@ -156,11 +163,19 @@ class BulkMediaCopy
156
163
  err
157
164
  end
158
165
 
159
- def copy_check?(md5,name,dest)
166
+ def copy_check?(mediafile)
160
167
  # if multi-threaded, need to lock before calling
161
- @copies[md5] << "#{name} => #{dest}"
168
+ @copies[mediafile.source_md5] <<
169
+ "#{mediafile.source} => #{mediafile.out_path(transcode_table:@transcode)}"
170
+ debug("md5 for #{mediafile.name} is #{mediafile.source_md5}")
162
171
  # return true if this is the only one
163
- @copies[md5].count == 1
172
+ debug("#{@copies[mediafile.source_md5]}")
173
+ ret = @copies[mediafile.source_md5].count == 1
174
+ unless ret
175
+ info("Same file with multiple names detected:\n\t" +
176
+ "#{@copies[mediafile.source_md5].join("\n\t")}")
177
+ end
178
+ ret
164
179
  end
165
180
 
166
181
  end
@@ -30,7 +30,7 @@ class MediaFile
30
30
  end
31
31
 
32
32
  def source_md5
33
- @source_md5 ||= Digest::MD5.hexdigest( @source )
33
+ @source_md5 ||= Digest::MD5.hexdigest( File.read(@source) )
34
34
  end
35
35
 
36
36
  def out_path(base_dir: @base_dir, transcode_table: {})
@@ -43,6 +43,10 @@ class MediaFile
43
43
 
44
44
  def copy(dest: @base_dir, transcode_table: {})
45
45
  destination = out_path base_dir: dest, transcode_table: transcode_table
46
+ debug "destination is '#{destination}'"
47
+ if destination =~ /\/\.[a-zA-Z0-9]+$/
48
+ raise "This is the error you've been looking for!\n '#{@source}' => '#{destination}'"
49
+ end
46
50
  temp_dest = tmp_path base_dir: dest, typ: transcode_table[@type]
47
51
  debug "temp dest is '#{temp_dest}'"
48
52
 
@@ -53,7 +57,9 @@ class MediaFile
53
57
  end
54
58
 
55
59
  unless check_transfer(temp_dest)
56
- error "Two source files mapped to the same destination file!"
60
+ error "Another file is already getting " +
61
+ (transcode_table.has_key?(@type) ? 'transcoded' : 'copied') +
62
+ "to the same destination path!"
57
63
  error "This file: #{@source} => #{temp_dest}"
58
64
  return
59
65
  end
@@ -61,22 +67,17 @@ class MediaFile
61
67
  debug("Create parent directories at '#{File.dirname destination}'.")
62
68
  FileUtils.mkdir_p File.dirname destination
63
69
  FileUtils.touch temp_dest
64
- begin
65
- if transcode_table.has_key?(@type)
66
- transcode(transcode_table, temp_dest)
67
- @disposition = 'transcoded'
68
- else
69
- FileUtils.cp(@source, temp_dest)
70
- @disposition = 'copied'
71
- end
72
- set_album_artist(temp_dest)
73
- set_comment_and_title(temp_dest)
74
- set_cover_art(temp_dest)
75
- FileUtils.mv temp_dest, destination
76
- rescue => e
77
- FileUtils.rm temp_dest if File.exist? temp_dest
78
- raise e
70
+ if transcode_table.has_key?(@type)
71
+ transcode(transcode_table, temp_dest)
72
+ @disposition = 'transcoded'
73
+ else
74
+ FileUtils.cp(@source, temp_dest)
75
+ @disposition = 'copied'
79
76
  end
77
+ set_album_artist(temp_dest)
78
+ set_comment_and_title(temp_dest)
79
+ set_cover_art(temp_dest)
80
+ FileUtils.mv temp_dest, destination
80
81
  ensure
81
82
  FileUtils.rm temp_dest if File.exist? temp_dest
82
83
  end
@@ -176,8 +177,7 @@ class MediaFile
176
177
  tpids = pids.keys
177
178
  err = []
178
179
  begin
179
- Timeout::timeout(60 * ( File.size(@source) / 1024 / 1024 /2 ) ) {
180
- #Timeout::timeout(3 ) {
180
+ Timeout::timeout(60 * ( File.size(@source) / 1024 / 1024 /2 ) ) do
181
181
  while tpids.any? do
182
182
  sleep 0.2
183
183
  tpids.delete_if do |pid|
@@ -193,7 +193,7 @@ class MediaFile
193
193
  ret
194
194
  end
195
195
  end
196
- }
196
+ end
197
197
  rescue Timeout::Error
198
198
  error "Timeout exceeded!\n" << tpids.map { |p|
199
199
  Process.kill 15, p
@@ -1,3 +1,3 @@
1
1
  module MediaFile
2
- VERSION = "0.2.7" unless defined?(::MediaFile::VERSION)
2
+ VERSION = "0.2.8" unless defined?(::MediaFile::VERSION)
3
3
  end
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.2.7
4
+ version: 0.2.8
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: 2017-02-04 00:00:00.000000000 Z
11
+ date: 2017-02-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: taglib-ruby