2020-09-13 16:15:40 +01:00
|
|
|
#![windows_subsystem = "windows"]
|
|
|
|
|
|
2020-09-11 09:37:02 +01:00
|
|
|
use gio::prelude::*;
|
|
|
|
|
use gtk::prelude::*;
|
2020-09-13 16:14:52 +01:00
|
|
|
use gtk::{Orientation, InputPurpose};
|
2020-09-11 11:02:42 +01:00
|
|
|
use std::env::args;
|
|
|
|
|
use std::process::Command;
|
2020-09-11 09:37:02 +01:00
|
|
|
|
|
|
|
|
const SPACING: i32 = 16;
|
|
|
|
|
|
|
|
|
|
fn build_ui(application: >k::Application) {
|
|
|
|
|
let window = gtk::ApplicationWindow::new(application);
|
|
|
|
|
|
2020-11-11 12:48:47 +00:00
|
|
|
window.set_title("media downloader");
|
2020-09-11 11:19:54 +01:00
|
|
|
window.set_border_width(SPACING as u32);
|
2020-09-11 09:37:02 +01:00
|
|
|
window.set_position(gtk::WindowPosition::Center);
|
|
|
|
|
window.set_default_size(400, 100);
|
|
|
|
|
|
|
|
|
|
let vertical = gtk::Box::new(Orientation::Vertical, SPACING);
|
2020-09-11 11:02:42 +01:00
|
|
|
let input_url = gtk::Entry::new();
|
2020-09-11 09:37:02 +01:00
|
|
|
let horizontal = gtk::Box::new(Orientation::Horizontal, SPACING);
|
|
|
|
|
let convert_to_mp3 = gtk::CheckButton::with_label("convert to mp3");
|
|
|
|
|
let button = gtk::Button::with_label("Go!");
|
|
|
|
|
|
2020-09-11 11:02:42 +01:00
|
|
|
input_url.set_placeholder_text(Some("Enter URL here"));
|
2020-09-13 16:14:52 +01:00
|
|
|
input_url.set_input_purpose(InputPurpose::Url);
|
2020-11-11 12:48:47 +00:00
|
|
|
|
2020-09-11 09:37:02 +01:00
|
|
|
horizontal.set_homogeneous(true);
|
|
|
|
|
|
|
|
|
|
window.add(&vertical);
|
|
|
|
|
|
2020-09-11 11:02:42 +01:00
|
|
|
vertical.add(&input_url);
|
2020-09-11 09:37:02 +01:00
|
|
|
vertical.add(&horizontal);
|
|
|
|
|
|
|
|
|
|
horizontal.add(&convert_to_mp3);
|
|
|
|
|
horizontal.add(&button);
|
|
|
|
|
|
|
|
|
|
window.show_all();
|
2020-09-11 11:02:42 +01:00
|
|
|
|
|
|
|
|
button.connect_clicked(move |_| {
|
|
|
|
|
let url = input_url.get_buffer().get_text();
|
|
|
|
|
println!("url: {}", url);
|
2021-02-20 16:18:07 +00:00
|
|
|
let mut youtube_dl = Command::new("youtube-dl");
|
2020-09-11 11:02:42 +01:00
|
|
|
|
|
|
|
|
if convert_to_mp3.get_active() {
|
|
|
|
|
println!("convert to mp3: true");
|
|
|
|
|
youtube_dl.arg("--extract-audio");
|
|
|
|
|
youtube_dl.arg("--audio-format");
|
|
|
|
|
youtube_dl.arg("mp3");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
youtube_dl.arg("--output");
|
|
|
|
|
youtube_dl.arg("~/Downloads/%(title)s.%(ext)s");
|
|
|
|
|
youtube_dl.arg(url);
|
|
|
|
|
|
|
|
|
|
let output = youtube_dl.output().expect("failed to execute process");
|
|
|
|
|
println!("exit status: {:#?}", output);
|
|
|
|
|
});
|
2020-09-11 09:37:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
|
let application = gtk::Application::new(
|
2021-02-20 16:18:07 +00:00
|
|
|
Some("dev.tinybird.max.media-downloader"),
|
2020-09-11 09:37:02 +01:00
|
|
|
Default::default()
|
|
|
|
|
).expect("Initialization failed...");
|
|
|
|
|
|
|
|
|
|
application.connect_activate(|app| {
|
|
|
|
|
build_ui(app);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
application.run(&args().collect::<Vec<_>>());
|
|
|
|
|
}
|