-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsorter.rb
More file actions
153 lines (138 loc) · 6.17 KB
/
sorter.rb
File metadata and controls
153 lines (138 loc) · 6.17 KB
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
146
147
148
149
150
151
152
require "rubygems"
require "mp3info"
require 'find'
require 'fileutils'
require 'yaml'
require 'set'
WORKING_DIR = "/Volumes/Media/Music/RSS"
LOG_FILE = 'genres.txt'
DELETION_LOG = 'deleted.txt'
UNKNOWN_DIR = "/Volumes/Media/Music/RSS_Unknown_Category"
def strip_numerical_genre(genre_s)
genre_s = "Unknown" if genre_s.nil? or genre_s == ""
genre_s.gsub(/\([0-9]+\)/, '')
end
genres = [
"Blues", "Classic Rock", "Country", "Dance", "Disco", "Funk",
"Grunge", "Hip-Hop", "Jazz", "Metal", "New Age", "Oldies", "Other",
"Pop", "R&B", "Rap", "Reggae", "Rock", "Techno", "Industrial",
"Alternative", "Ska", "Death Metal", "Pranks", "Soundtrack",
"Euro-Techno", "Ambient", "Trip-Hop", "Vocal", "Jazz+Funk", "Fusion",
"Trance", "Classical", "Instrumental", "Acid", "House", "Game",
"Sound Clip", "Gospel", "Noise", "Alt. Rock", "Bass", "Soul",
"Punk", "Space", "Meditative", "Instrum. Pop", "Instrum. Rock",
"Ethnic", "Gothic", "Darkwave", "Techno-Indust.", "Electronic",
"Pop-Folk", "Eurodance", "Dream", "Southern Rock", "Comedy",
"Cult", "Gangsta", "Top 40", "Christian Rap", "Pop/Funk", "Jungle",
"Native American", "Cabaret", "New Wave", "Psychadelic", "Rave",
"Showtunes", "Trailer", "Lo-Fi", "Tribal", "Acid Punk", "Acid Jazz",
"Polka", "Retro", "Musical", "Rock & Roll", "Hard Rock", "Folk",
"Folk-Rock", "National Folk", "Swing", "Fusion", "Bebob", "Latin",
"Revival", "Celtic", "Bluegrass", "Avantgarde", "Gothic Rock",
"Progress. Rock", "Psychadel. Rock", "Symphonic Rock", "Slow Rock",
"Big Band", "Chorus", "Easy Listening", "Acoustic", "Humour",
"Speech", "Chanson", "Opera", "Chamber Music", "Sonata", "Symphony",
"Booty Bass", "Primus", "Porn Groove", "Satire", "Slow Jam",
"Club", "Tango", "Samba", "Folklore", "Ballad", "Power Ballad",
"Rhythmic Soul", "Freestyle", "Duet", "Punk Rock", "Drum Solo",
"A Capella", "Euro-House", "Dance Hall", "Goa", "Drum_&_Bass",
"Club-House", "Hardcore", "Terror", "Indie", "BritPop", "Negerpunk",
"Polsk Punk", "Beat", "Christian Gangsta Rap", "Heavy Metal",
"Black Metal", "Crossover", "Contemporary Christian", "Christian Rock",
"Merengue", "Salsa", "Thrash Metal", "Anime", "Jpop", "Synthpop"
]
genres_to_keep = [
"Dance", "Hip-Hop", "Jazz", "Other", "Pop", "R&B", "Rap", "Techno", "Industrial", "Soundtrack",
"Euro-Techno", "Ambient", "Trip-Hop", "Jazz+Funk", "Fusion", "Trance", "Classical", "Instrumental",
"Acid", "House", "Game", "Bass", "Meditative", "Instrum. Pop", "Techno-Indust.", "Electronic", "Eurodance",
"Top 40", "Pop/Funk", "Jungle", "Rave", "Lo-Fi", "Acid Punk", "Acid Jazz", "Fusion", "Acoustic", "Sonata",
"Symphony", "Club", "Euro-House", "Dance Hall", "Goa", "Drum & Bass", "Club-House", "Hardcore", "Indie",
"Beat", "Jpop", "Synthpop"
]
genre_partials_to_delete = [
"country", "rock", "metal", "noise", "punk", "humour", "death", "celtic", "folk", "christian", "gospel",
"oldies", "gothic", "blue", "funk", "soul", "acoustic", "latin", "hardcore", "chanson", "new wave",
"disco", "rap", "reggae", "raggy", "a capella", "dance hall", "salsa", "ethnic", "comedy", "darkwave",
"international", "musical", "polka", "tribal", "big band", "crossover", "swing", "jumpstyle", "cabaret",
"ska", "merengue", "speech", "ballad", "gangsta", "tango"
]
release_partials_to_keep = [
"scott_brown", "kutski", "elysium", "orbital",
"bbc_radio1",
"kid_kudi", "gucci_mane", "n.w.a", "chamillionaire", "talib_kweli", "t-pain", "wiz_khalifa", "j._cole",
"lil_wayne", "lil_jon", "jill_scott", "eminem", "dj_khaled", "pitbull", "50_cent", "insane_clown_posse",
"the_game", "nicki_minaj", "drake", "lupe_fiasco", "tyga", "shaggy",
"blu_mar_ten", "chase_and_status",
"avicii", "armin_van_buuren", "ferry_corsten", "laptop_symphony", "laidback_luke", "wolfgang_gartner",
"hed_kandi", "chuckie", "carl_cox", "blank_and_jones",
"whitelabel", "weird_al_yankovic", "limp_bizkit"
]
genre_hash = Hash.new(0)
genre_hash_of_sets = {}# = Hash.new(Set.new)
genre = "Unknown"
ctr = 0
Dir.foreach(WORKING_DIR) do |dir|
next if dir == '.' or dir == '..' or dir == '.DS_Store'
#break if ctr == 200
puts "still going...#{ctr}" if ctr % 1000 == 0
genre_found = false
Dir.foreach(File.join(WORKING_DIR, dir)) do |file|
next if file == '.' or file == '..' or file == '.DS_Store'
next if genre_found
if File.fnmatch('*.mp3', File.basename(file)) and not genre_found
begin
Mp3Info.open(File.join(WORKING_DIR, dir, file)) do |mp3|
#puts dir
#puts "#{File.basename(file)}"
#puts " #{strip_numerical_genre(mp3.tag.genre_s)}"
genre_found = true
genre = strip_numerical_genre(mp3.tag.genre_s).gsub(/\w+/) { |s| s.capitalize }
#puts genre
break
end
rescue
puts "Problem reading tag info for: #{File.join(dir, file)}"
genre = "Unknown"
end
end
if genre_found
genre_hash["#{genre}"] = genre_hash["#{genre}"] + 1
if genre_hash_of_sets["#{genre}"].nil?
genre_hash_of_sets["#{genre}"] = Set.new("#{dir}")
else
genre_hash_of_sets["#{genre}"].add("#{dir}")
end
end
end
ctr = ctr + 1
end
File.open(LOG_FILE, 'w') do |f|
genre_hash_of_sets.each do |genre, dirs|
f.puts "#{genre}"
delete_genre = false
genre_partials_to_delete.each do |genre_partial| # check if genre is in our blacklist
if genre.downcase.include? genre_partial
puts "DELETING GENRE: #{genre}"
delete_genre = true
end
end
dirs.each do |dir|
f.puts " #{dir}"
delete_release = true
if delete_genre
release_partials_to_keep.each do |release_partial| # check if release is in our whitelist
if dir.downcase.include? release_partial
delete_release = false
break
end
end
if delete_release
puts " #{dir}"
FileUtils.rm_rf(File.join(WORKING_DIR, dir))
genre_hash["#{genre}"] = genre_hash["#{genre}"] - 1
end
end
end
end
end
puts genre_hash.to_yaml