-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlibrary_tagger.rb
40 lines (27 loc) · 982 Bytes
/
library_tagger.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
require 'rubygems'
require 'id3lib'
require 'sqlite3'
db = SQLite3::Database.new( "LC.db" )
rows = db.execute("SELECT f.id, d.path, f.filename from files f INNER JOIN directories d on f.directory = d.id")
rows.each_with_index do |row,index|
puts "#{index}/#{rows.size} processing file /#{row[1]}#{row[2]}"
filetags = db.execute("SELECT f.id, f.filename, t.name, tt.weight FROM tracktags tt inner join files f on f.id = tt.file join tags t on tt.tag = t.id where f.id = ? order by tt.weight DESC", row[0])
if filetags.size > 0
top_tag = filetags.shift
tag = ID3Lib::Tag.new("/#{row[1]}#{row[2]}")
tag.genre = top_tag[2]
filetags.each do |filetag|
tag.comment = "#{tag.comment}\nlfm:tag:#{filetag[2]}"
end
puts "#{tag.title}: #{top_tag[2]}"
tag.update!
else
puts "not enough tag data"
end
end
# for each file
# load tag
# write primary tag to genre
# write other tags somewhere else
# save tag
# print progress to screen