basic functionality

This commit is contained in:
Max Bradbury 2020-09-11 11:02:42 +01:00
parent 6970d71164
commit f9e7958120
1 changed files with 25 additions and 4 deletions

View File

@ -1,7 +1,8 @@
use gio::prelude::*;
use gtk::prelude::*;
use std::env::args;
use gtk::Orientation;
use std::env::args;
use std::process::Command;
const SPACING: i32 = 16;
@ -14,25 +15,45 @@ fn build_ui(application: &gtk::Application) {
window.set_default_size(400, 100);
let vertical = gtk::Box::new(Orientation::Vertical, SPACING);
let url = gtk::Entry::new();
let input_url = gtk::Entry::new();
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!");
url.set_placeholder_text(Some("Enter URL here"));
input_url.set_placeholder_text(Some("Enter URL here"));
horizontal.set_spacing(SPACING);
horizontal.set_homogeneous(true);
window.add(&vertical);
vertical.add(&url);
vertical.add(&input_url);
vertical.add(&horizontal);
horizontal.add(&convert_to_mp3);
horizontal.add(&button);
window.show_all();
button.connect_clicked(move |_| {
let url = input_url.get_buffer().get_text();
println!("url: {}", url);
let mut youtube_dl = Command::new("youtube-dl");
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);
});
}
fn main() {