got_mp3 0.1.0 → 0.1.1
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
- checksums.yaml.gz.sig +0 -0
- data/lib/got_mp3.rb +75 -12
- data.tar.gz.sig +0 -0
- metadata +2 -2
- metadata.gz.sig +1 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 838f650beb51908cd19f1c17ea92c14fc017311a27294e1870f65ba5910110e2
|
|
4
|
+
data.tar.gz: 79bc380538aa93ebd4ecc1e007699cad0d1f01f0082c85a7077d1ca2ae52c7dd
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: '09309170f4a66c730c1e1a7dca2c27a67a65576eac016b7f8808301d2378cf859b42971661dabb18571e1e6c46cfd865955ba5b35cf4ef6af36a214edcf85ed5'
|
|
7
|
+
data.tar.gz: 12f09a40443a40ed6524107b98fb984afce361a721af3584324401cbde2f7e5b60a2ef85000fcfee7dad2bc052306041d212f7fd962dedb7ae24a477f030c225
|
checksums.yaml.gz.sig
CHANGED
|
Binary file
|
data/lib/got_mp3.rb
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env ruby
|
|
2
|
+
|
|
2
3
|
# file: got_mp3.rb
|
|
3
4
|
|
|
4
5
|
require "mp3info"
|
|
@@ -11,32 +12,47 @@ class GotMP3
|
|
|
11
12
|
end
|
|
12
13
|
|
|
13
14
|
|
|
15
|
+
# Adds album art to each MP3 file
|
|
16
|
+
#
|
|
14
17
|
# Example usage:
|
|
15
18
|
# gotmp3 = GotMP3.new(dir: '/tmp/tree/Da Fustra - Over The Waves To Shetland')
|
|
16
19
|
# gotmp3.add_jpg
|
|
17
|
-
#
|
|
20
|
+
#
|
|
18
21
|
def add_jpg()
|
|
19
22
|
|
|
20
|
-
|
|
21
|
-
puts 'a: ' + a.inspect if @debug
|
|
22
|
-
directories = a.inject({}) {|r, x| r[File.dirname(x)] = File.basename(x); r }
|
|
23
|
-
|
|
24
|
-
directories.each do |directory, img_filename|
|
|
23
|
+
find_by_ext('.jpg').each do |directory, img_filename|
|
|
25
24
|
add_image directory, img_filename
|
|
26
25
|
end
|
|
27
26
|
|
|
28
27
|
end
|
|
29
28
|
|
|
29
|
+
# Adds a track title to each MP3 file
|
|
30
|
+
#
|
|
31
|
+
# Example usage:
|
|
32
|
+
# gotmp3 = GotMP3.new(dir: '/tmp/tree/Da Fustra - Over The Waves To Shetland')
|
|
33
|
+
# gotmp3.add_titles
|
|
34
|
+
#
|
|
35
|
+
def add_titles()
|
|
36
|
+
|
|
37
|
+
find_by_ext('.txt').each do |directory, txt_filename|
|
|
38
|
+
add_tracktitles directory, txt_filename
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
#def go()
|
|
44
|
+
#end
|
|
45
|
+
|
|
30
46
|
private
|
|
31
47
|
|
|
32
48
|
# adds album art to each mp3 file in a file directory
|
|
33
49
|
#
|
|
34
50
|
def add_image(directory, img_filename)
|
|
35
51
|
|
|
36
|
-
image_file = File.new(File.join(directory, img_filename),'rb')
|
|
52
|
+
image_file = File.new(File.join(directory, img_filename),'rb')
|
|
37
53
|
img = image_file.read
|
|
38
54
|
|
|
39
|
-
each_mp3(directory) do |mp3|
|
|
55
|
+
each_mp3(directory) do |mp3, _, _|
|
|
40
56
|
|
|
41
57
|
mp3.tag2.remove_pictures
|
|
42
58
|
mp3.tag2.add_picture img
|
|
@@ -45,16 +61,63 @@ class GotMP3
|
|
|
45
61
|
|
|
46
62
|
end
|
|
47
63
|
|
|
48
|
-
def
|
|
64
|
+
def add_tracktitles(directory, txt_filename)
|
|
65
|
+
|
|
66
|
+
txt_file = File.join(directory, txt_filename)
|
|
67
|
+
track_titles = File.read(txt_file).lines[1..-1].map(&:strip)
|
|
68
|
+
|
|
69
|
+
each_mp3(directory) do |mp3, trackno, _|
|
|
70
|
+
|
|
71
|
+
mp3.tag.title = track_titles[trackno-1]
|
|
72
|
+
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def add_image_and_titles(directory, img_filename, txt_filename)
|
|
77
|
+
|
|
78
|
+
image_file = File.new(File.join(directory, img_filename),'rb')
|
|
79
|
+
img = image_file.read
|
|
80
|
+
|
|
81
|
+
txt_file = File.join(directory, txt_filename)
|
|
82
|
+
track_titles = File.read(txt_file).lines[1..-1].map(&:strip)
|
|
49
83
|
|
|
50
|
-
Dir[File.join(directory, "*.mp3")].
|
|
84
|
+
found = Dir[File.join(directory, "*.mp3")].sort_by { |x| File.mtime(x) }
|
|
85
|
+
found.each.with_index do |mp3_filepath, i|
|
|
51
86
|
|
|
52
|
-
Mp3Info.open
|
|
53
|
-
|
|
87
|
+
Mp3Info.open(mp3_filepath) do |mp3|
|
|
88
|
+
mp3.tag2.remove_pictures
|
|
89
|
+
mp3.tag2.add_picture img
|
|
90
|
+
mp3.tag.title = track_titles[trackno-1]
|
|
54
91
|
end
|
|
55
92
|
|
|
93
|
+
File.rename(mp3_filepath, File.join(directory,
|
|
94
|
+
track_titles[i][/^[^\/]+/].gsub(/\W/,'').rstrip + '.mp3'))
|
|
56
95
|
end
|
|
57
96
|
|
|
58
97
|
end
|
|
59
98
|
|
|
99
|
+
def each_mp3(directory, &blk)
|
|
100
|
+
|
|
101
|
+
found = Dir[File.join(directory, "*.mp3")].sort_by { |x| File.mtime(x) }
|
|
102
|
+
found.each.with_index do |mp3_filepath, i|
|
|
103
|
+
|
|
104
|
+
Mp3Info.open(mp3_filepath) {|mp3| blk.call(mp3, i+1, mp3_filepath) }
|
|
105
|
+
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
def find_by_ext(extension)
|
|
111
|
+
|
|
112
|
+
a = Dir[File.join(@dir, "**", "*" + extension)]
|
|
113
|
+
puts 'a: ' + a.inspect if @debug
|
|
114
|
+
|
|
115
|
+
a.inject({}) do |r, x|
|
|
116
|
+
|
|
117
|
+
r[File.dirname(x)] = File.basename(x)
|
|
118
|
+
r
|
|
119
|
+
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
|
|
60
123
|
end
|
data.tar.gz.sig
CHANGED
|
Binary file
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: got_mp3
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- James Robertson
|
|
@@ -35,7 +35,7 @@ cert_chain:
|
|
|
35
35
|
RFrZsrDO1Cwk4v03qCUvuZ8H/nCojYYJGMrJE1JhBBJNJXCAULivh/zlOYcDhG69
|
|
36
36
|
uPtZOD7YKrG45OftX8aNxlNv
|
|
37
37
|
-----END CERTIFICATE-----
|
|
38
|
-
date: 2021-11-
|
|
38
|
+
date: 2021-11-25 00:00:00.000000000 Z
|
|
39
39
|
dependencies:
|
|
40
40
|
- !ruby/object:Gem::Dependency
|
|
41
41
|
name: ruby-mp3info
|
metadata.gz.sig
CHANGED