-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplaylist_transfer-gtk.rb
executable file
·155 lines (127 loc) · 4.26 KB
/
playlist_transfer-gtk.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
146
147
148
149
150
151
152
153
154
155
#!/usr/bin/env ruby
require 'gtk3'
require 'pathname'
require 'm3u8'
require 'playlist_transfer'
class PlaylistTransferGUI
def initialize(glade_path)
@builder = Gtk::Builder.new
@builder.add_from_file(glade_path)
@builder.connect_signals { |handler| method (handler) }
@main_window = @builder.get_object('mainwindow')
end
def run
@main_window.show
Gtk.main
end
def quit
Gtk.main_quit
end
def musicdir_selector_activate
musicdir_enabled = @builder.get_object('specify_musicdir_switch')
music_chooser = @builder.get_object('choose_musicdir')
music_chooser.set_sensitive(musicdir_enabled.active?)
return false
end
def show_error(message)
error_window = @builder.get_object('error_dialog')
error_window.text = "#{message}"
error_window.show
end
def close_error
error_window = @builder.get_object('error_dialog')
error_window.hide
end
def show_finished
finished_window = @builder.get_object('finished_dialog')
finished_window.show
end
def close_finished
finished_window = @builder.get_object('finished_dialog')
finished_window.hide
end
def cancel
@exit = true
end
def update_ui
while Gtk.events_pending?
Gtk.main_iteration
end
end
def start_transfer
@transfer_proc = Thread.new { run_transfer }
end
def run_transfer
compatible_sw = @builder.get_object('compatible_switch')
justcopy_sw = @builder.get_object('justcopy_switch')
skoda_sw = @builder.get_object('skoda_switch')
use_musicdir_sw = @builder.get_object('specify_musicdir_switch')
playlist_diag = @builder.get_object('choose_playlist')
output_diag = @builder.get_object('choose_output')
progressbar = @builder.get_object('progressbar')
run_button = @builder.get_object('run_button')
progressbar.set_fraction(0)
cancel_button = @builder.get_object('cancel_button')
@exit = false
abort "Input file or output folder not defined. Please specify one ! " if output_diag.filename == nil || playlist_diag.filename == nil
compatible = compatible_sw.active?
justcopy = justcopy_sw.active?
skoda = skoda_sw.active?
use_musicdir = use_musicdir_sw.active?
playlist = Pathname.new(playlist_diag.filename)
output = Pathname.new(output_diag.filename)
compatible_sw.set_sensitive(false)
justcopy_sw.set_sensitive(false)
skoda_sw.set_sensitive(false)
use_musicdir_sw.set_sensitive(false)
playlist_diag.set_sensitive(false)
output_diag.set_sensitive(false)
run_button.set_sensitive(false)
cancel_button.set_sensitive(true)
abort "Cannot read file #{playlist.to_s} . Does it exist?" unless playlist.expand_path.file? && playlist.expand_path.readable?
base_dir = playlist.expand_path.dirname if use_musicdir==false
compatible = true if skoda
Dir.chdir(playlist.expand_path.dirname)
playlist_file = File.open(playlist.expand_path)
input = M3u8::Playlist.read(playlist_file)
progres_part = 1.to_f/input.items.count.to_f
input.items.each do |item|
track_location = Pathname.new(item.segment)
track=MusicTrack.new(track_location,base_dir)
track.transfer(output, compatible, justcopy, skoda)
progressbar.set_fraction(progressbar.fraction + progres_part)
break if @exit
end
show_finished unless @exit
compatible_sw.set_sensitive(true)
justcopy_sw.set_sensitive(true)
skoda_sw.set_sensitive(true)
use_musicdir_sw.set_sensitive(true)
playlist_diag.set_sensitive(true)
output_diag.set_sensitive(true)
run_button.set_sensitive(true)
cancel_button.set_sensitive(false)
rescue Exception => e
show_error(e)
compatible_sw.set_sensitive(true)
justcopy_sw.set_sensitive(true)
skoda_sw.set_sensitive(true)
use_musicdir_sw.set_sensitive(true)
playlist_diag.set_sensitive(true)
output_diag.set_sensitive(true)
run_button.set_sensitive(true)
cancel_button.set_sensitive(false)
end
end
if __FILE__==$0
# Try to do some "Localization"
language="#{ENV['LANG']}"
case language
when /cs_CZ\./
resource='playlist_transfer_cz.glade'
else
resource='playlist_transfer.glade'
end
mainwindow=PlaylistTransferGUI.new("#{File.expand_path(File.dirname(__FILE__))}/#{resource}")
mainwindow.run
end