-
Notifications
You must be signed in to change notification settings - Fork 0
/
export.rb
60 lines (47 loc) · 1.42 KB
/
export.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
require 'rubygems'
require 'bundler/setup'
require 'sqlite3'
require 'uri'
class Export
def initialize(exaile_db_path, clementine_db_path)
@exaile_db = SQLite3::Database.open exaile_db_path
@exaile_db.results_as_hash = true
@clementine_db = SQLite3::Database.open clementine_db_path
@clementine_db.results_as_hash = true
end
def process
stm = @exaile_db.prepare "select tracks.title, tracks.user_rating, paths.name from tracks inner join paths on (tracks.path=paths.id) where tracks.user_rating>'0'"
rows = stm.execute
i = 0
rows.each do |row|
i += 1
puts i
set_clementine_rating row['name'], row['user_rating']
end
puts 'Done'
end
def set_clementine_rating(path, rating)
#begin
stm = @clementine_db.prepare "update songs set rating=? where filename=? and rating<=?"
stm.bind_params rating_convert(rating), SQLite3::Blob.new(to_clementine_path(path)), 0
stm.execute
#rescue SQLite3::Exception => e
# puts 'SQLite exception'
# puts e
#end
end
def to_clementine_path(path)
"file://#{URI.escape(path)}"
end
def rating_convert(rating)
(rating.to_f*2)/10
end
end
if ARGV[0] == '--help'
puts 'Usage: $ ruby export.rb <exaile_db_path> <clementine_db_path>'
else
exaile_db_path = ARGV[0]
clementine_db_path = ARGV[1]
export = Export.new(exaile_db_path, clementine_db_path)
export.process
end