Class: MultimediaParadise::GUI::Libui::YoutubeDownloader
- Inherits:
-
Object
- Object
- MultimediaParadise::GUI::Libui::YoutubeDownloader
show all
- Defined in:
- lib/multimedia_paradise/gui/libui/youtube_downloader/youtube_downloader.rb
Overview
Instance Method Summary
collapse
Constructor Details
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
|
# File 'lib/multimedia_paradise/gui/libui/youtube_downloader/youtube_downloader.rb', line 25
def initialize
@main_window = ui_main_window('Youtube Downloader', 1200, 200, 0)
outer_vbox = ui_vbox
hbox = ui_hbox
hbox << ui_text(
'Input the youtube URL on the left side, then click '\
'the download-button to download this URL via youtube-dl.'
)
hbox.is_padded
outer_vbox << hbox
hbox = ui_hbox
@entry_URL_to_use_for_the_youtube_video = ui_entry
hbox << @entry_URL_to_use_for_the_youtube_video
@button_download = ui_button('Download the video')
@button_download.on_clicked {
do_download_the_video
}
hbox << @button_download
outer_vbox << hbox
@main_window.child = outer_vbox
@main_window.intelligent_exit
end
|
Instance Method Details
#do_download_the_video(i = @entry_URL_to_use_for_the_youtube_video.text?) ⇒ Object
#
do_download_the_video
#
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
|
# File 'lib/multimedia_paradise/gui/libui/youtube_downloader/youtube_downloader.rb', line 54
def do_download_the_video(
i = @entry_URL_to_use_for_the_youtube_video.text?
)
if i.empty?
ui_error_msg(
@main_window,
'Please provide a remote URL.'
)
else
Dir.chdir('/tmp/')
e "Downloading `#{::Colours.sfancy(i)}` into the directory "\
"#{Dir.pwd} using youtube-dl."
result = 'youtube-dl '+i
e result
result = `#{result}`
_ = result.split("\n").select {|line|
line.include? '[ffmpeg] Merging formats'
}
_ = _.first
regex = /\[ffmpeg\] Merging formats into "(.+)"/ _.match(regex)
new_filename = $1.to_s
if File.exist? new_filename
if new_filename.include? ' '
old_filename = new_filename.dup
new_filename = new_filename.tr(' ','_')
FileUtils.mv(old_filename, new_filename)
end
if File.exist? new_filename message_to_the_user(main_window,
"The downloaded file should now be available at:\n\n"+
" #{new_filename.to_s}\n"
)
e 'All done!'
else
error_message_to_the_user(main_window,
'Something did not work - nothing is at : '+
new_filename.to_s+"\n\nPlease make sure that "\
"/tmp/ exists and that ffmpeg as well as youtube-dl "\
"are installed locally.\n"
)
end
end
end
end
|