-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathid3tag.rb
145 lines (124 loc) · 3.82 KB
/
id3tag.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
require 'mp3info'
#------------------------------={ INTRODUCTION }=------------------------------#
intro = "
Once upon a time, there lived a little DJ, in a big, wild world with
weirdly tagged or untagged or re-tagged mp3 files all over the place - and all
he would've asked for was just a wee bit of order. Back then (he still vividly
remembered the days when he used to walk through man-high snow, barefoot, uphill
both ways and... well, you get the idea), the DJing business was hard enough to
be honest.
Now, one day, a fairy little fairy (true story!) would listen to one of his gigs
by chance, and was so amazed by the deep house and tech house and what-not he
mixed, that she'd approach him and granted him a wish - and oh, our dear DJ did
know _exactly_ what he wanted!
He placed the tiny bot he was given by our fair fairy in his folder with freshly
hunted-down tracks, and the bot would make sure all ID3 tags were kept clean...
that meaning, discarded of; and the artist & title taken from the file names of
all .mp3s present in said directory written in ID3v2.
If this, all of a sudden, does not sound like a good idea to you or you're not
feeling like our little DJ - then you have 3 seconds to interrupt this script.
Otherwise, again, ALL TAGS OF ALL MP3 FILES WITHIN THIS DIRECTORY WILL BE LOST.
Amen.
\n"
#------------------------------------------------------------------------------#
puts intro
sleep 23
low_bitrate = Array.new()
filename_error = Array.new()
fopen_error = Array.new()
count = 0
Dir.entries('.').each do |file|
# we're only interested in .mp3 files
next if file !~ /\.mp3$/
# we need a 'proper' filename to work with
if file !~ / - /
filename_error << file
next
end
begin
Mp3Info.open(file) do |mp3|
filename = mp3.filename.split(" - ")
title = filename[1].gsub(/.mp3$/, '')
artist = filename[0]
# delete ALL the tags o/
mp3.removetag1
mp3.removetag2
# write artist & title ID3v2 tags
mp3.tag2.TIT2 = title
mp3.tag2.TPE1 = artist
=begin
You may also access the following tags, if you like:
__ID3v1 tags__
title
artist
album
year
tracknum
comments
genre
genre_s
__ID3v2 tags__
TRCK # track #/#
TIT1 # content
TIT2 # title
TIT3 # subtitle
TPE1 # artist
TPE2 # orchestra
TPE3 # conductor
TALB # album
TYER # year
TCON # genre
COMM # comment
TCOM # composer
TCOP # copyright
TOPE # orig. artist
TENC # encoded by
WXXX # URL
TCMP # part of compilation?
TEXT # lyricist
TPUB # publisher
TPOS # part of set #/#
disc_number # part of set
disc_total # number of parts of set
TSRC # ISRC
TBPM # bpm
TKEY # key
USLT # lyrics
APIC # pictures
=end
if (mp3.bitrate < 320)
low_bitrate << mp3.filename
end
puts "Tags written to #{artist} - #{title}"
count += 1
end
rescue Mp3InfoError
fopen_error << file
end
end
#-----------------------={ EXECUTIVE SUMMARY OF FAIL: }=-----------------------#
puts "
Processed & tagged #{count} mp3 files."
if (low_bitrate.count > 0)
puts "
WARNING! The following mp3s have under 320kbps:"
low_bitrate.each do |file|
puts file
end
puts "I would rather not recommend using these for DJing purposes, honey!"
end
if (fopen_error.count > 0)
puts "
ERROR! The following mp3s could not be processed; plz check on the files' permissions and/or integrity:"
fopen_error.each do |file|
puts file
end
end
if (filename_error.count > 0)
puts "
ERROR! The following mp3s (or their tags, respectively) did not get modified:"
filename_error.each do |file|
puts file
end
puts "A filename should be formatted to resemble the following example: Artist - Title.mp3"
end