marecchione also gay

This commit is contained in:
uh wot 2021-07-15 00:33:03 +02:00
commit cef40028a9
Signed by: uhwot
GPG Key ID: CB2454984587B781
7 changed files with 2659 additions and 0 deletions

2049
Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

38
Cargo.toml Normal file
View File

@ -0,0 +1,38 @@
[package]
name = "dzgtk"
version = "0.1.0"
authors = ["uh wot <uhwot@protonmail.com>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
lazy_static = "1.4"
gladis = "0.4"
glib = "0.10"
sanitize-filename = "0.3"
[dependencies.reqwest]
version = "0.11"
features = ["rustls-tls", "stream"]
default-features = false
[dependencies.rodio]
version = "0.14"
features = ["mp3", "flac"]
default-features = false
[dependencies.gtk]
version = "0.9"
features = ["v3_24"]
[dependencies.gio]
version = "0.9"
features = ["v2_44"]
[dependencies.dzlib-rs]
path = "../dzlib-rs"
[dependencies.tokio]
version = "1.6"
features = ["rt-multi-thread", "macros"]

110
src/main.rs Normal file
View File

@ -0,0 +1,110 @@
use std::sync::Mutex;
use gtk::prelude::*;
use gio::prelude::*;
use gladis::Gladis;
use dzlib_rs::{Client, objects::TrkFormat};
use lazy_static::lazy_static;
use std::io::Cursor;
use rodio::{Decoder, OutputStream, source::Source};
lazy_static! {
static ref CLIENT: Mutex<Client> = Mutex::new(Client::new());
}
#[tokio::main]
async fn main() {
let application = gtk::Application::new(
Some("dev.uhwot.dzgtk"),
Default::default(),
).unwrap();
application.connect_activate(build_ui);
application.run(&[]);
}
#[derive(Gladis, Clone)]
pub struct Main {
pub win: gtk::ApplicationWindow,
pub search_button: gtk::Button,
pub search_box: gtk::Entry,
pub stack: gtk::Stack,
pub loading: gtk::Spinner,
pub tracks: gtk::ScrolledWindow,
pub track_list: gtk::ListBox,
}
impl Main {
pub fn new() -> Self {
Self::from_string(include_str!("main.ui")).unwrap()
}
}
#[derive(Gladis, Clone)]
pub struct TrackTile {
pub trk: gtk::Box,
pub title: gtk::Label,
pub artist: gtk::Label,
pub album: gtk::Label,
pub dl: gtk::Button,
}
impl TrackTile {
pub fn new() -> Self {
Self::from_string(include_str!("track_tile.ui")).unwrap()
}
}
fn build_ui(application: &gtk::Application) {
let ui = Main::new();
ui.win.set_application(Some(application));
ui.search_button.connect_clicked(glib::clone!(@weak ui.stack as stack, @weak ui.loading as loading, @weak ui.search_box as search_box, @weak ui.tracks as tracks, @weak ui.track_list as track_list => move |_| {
glib::MainContext::default().spawn_local(search_tracks(stack, loading, search_box, tracks, track_list));
}));
ui.search_box.connect_activate(glib::clone!(@weak ui.stack as stack, @weak ui.loading as loading, @weak ui.search_box as search_box, @weak ui.tracks as tracks, @weak ui.track_list as track_list => move |_| {
glib::MainContext::default().spawn_local(search_tracks(stack, loading, search_box, tracks, track_list));
}));
ui.win.show_all();
}
async fn search_tracks(stack: gtk::Stack, loading: gtk::Spinner, search_box: gtk::Entry, tracks: gtk::ScrolledWindow, track_list: gtk::ListBox) {
stack.set_visible_child(&loading);
let trks = CLIENT.lock().unwrap().search_track(&search_box.get_text()).await.unwrap();
track_list.forall(|c| {
track_list.remove(c);
});
for track in trks.data {
let tile = TrackTile::new();
tile.title.set_text(&track.title);
tile.artist.set_text(&track.artist.as_ref().unwrap().name);
tile.album.set_text(&track.album.as_ref().unwrap().title);
// on dl button click
tile.dl.connect_clicked(move |_| {
glib::MainContext::default().spawn_local(dl_track(track.stream_url(TrkFormat::MP3320).unwrap(), track.title.clone()));
});
track_list.insert(&tile.trk, -1);
}
stack.set_visible_child(&tracks);
}
async fn dl_track(url: String, title: String) {
println!("Playing {}...", title);
let (_stream, stream_handle) = OutputStream::try_default().unwrap();
let stream = reqwest::get(url)
.await.unwrap()
.bytes().await.unwrap();
let cursor = Cursor::new(stream);
let source = Decoder::new(cursor).unwrap();
stream_handle.play_raw(source.convert_samples());
std::thread::sleep(std::time::Duration::from_secs(5));
}

149
src/main.ui Normal file
View File

@ -0,0 +1,149 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.38.2
dzgtk - nigga balls
Copyright (C) 2021 uh wot
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Author: uh wot
-->
<interface>
<requires lib="gtk+" version="3.24"/>
<!-- interface-license-type gplv2 -->
<!-- interface-name dzgtk -->
<!-- interface-description nigga balls -->
<!-- interface-copyright 2021 uh wot -->
<!-- interface-authors uh wot -->
<object class="GtkApplicationWindow" id="win">
<property name="can-focus">False</property>
<property name="title" translatable="yes">dzgtk</property>
<property name="default-width">500</property>
<property name="default-height">250</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<child>
<object class="GtkEntry" id="search_box">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="margin-start">10</property>
<property name="margin-end">10</property>
<property name="margin-top">5</property>
<property name="margin-bottom">5</property>
<property name="hexpand">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="search_button">
<property name="label">gtk-find</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<property name="margin-end">10</property>
<property name="margin-top">5</property>
<property name="margin-bottom">5</property>
<property name="use-stock">True</property>
<property name="always-show-image">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkStack" id="stack">
<property name="visible">True</property>
<property name="can-focus">False</property>
<child>
<object class="GtkLabel" id="name">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">nigga balls</property>
</object>
<packing>
<property name="name">page0</property>
<property name="title" translatable="yes">page0</property>
</packing>
</child>
<child>
<object class="GtkSpinner" id="loading">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="margin-top">30</property>
<property name="margin-bottom">30</property>
<property name="active">True</property>
</object>
<packing>
<property name="name">page1</property>
<property name="title" translatable="yes">page1</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkScrolledWindow" id="tracks">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="shadow-type">in</property>
<child>
<object class="GtkViewport">
<property name="visible">True</property>
<property name="can-focus">False</property>
<child>
<object class="GtkListBox" id="track_list">
<property name="visible">True</property>
<property name="can-focus">False</property>
</object>
</child>
</object>
</child>
</object>
<packing>
<property name="name">page4</property>
<property name="title" translatable="yes">page4</property>
<property name="position">2</property>
</packing>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
</object>
</interface>

147
src/main.ui~ Normal file
View File

@ -0,0 +1,147 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.38.2
dzgtk - nigga balls
Copyright (C) 2021 uh wot
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Author: uh wot
-->
<interface>
<requires lib="gtk+" version="3.24"/>
<!-- interface-license-type gplv2 -->
<!-- interface-name dzgtk -->
<!-- interface-description nigga balls -->
<!-- interface-copyright 2021 uh wot -->
<!-- interface-authors uh wot -->
<object class="GtkApplicationWindow" id="win">
<property name="can-focus">False</property>
<property name="title" translatable="yes">dzgtk</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<child>
<object class="GtkEntry" id="search_box">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="margin-start">10</property>
<property name="margin-end">10</property>
<property name="margin-top">5</property>
<property name="margin-bottom">5</property>
<property name="hexpand">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="search_button">
<property name="label">gtk-find</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<property name="margin-end">10</property>
<property name="margin-top">5</property>
<property name="margin-bottom">5</property>
<property name="use-stock">True</property>
<property name="always-show-image">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkStack" id="stack">
<property name="visible">True</property>
<property name="can-focus">False</property>
<child>
<object class="GtkLabel" id="name">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">nigga balls</property>
</object>
<packing>
<property name="name">page0</property>
<property name="title" translatable="yes">page0</property>
</packing>
</child>
<child>
<object class="GtkSpinner" id="loading">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="margin-top">30</property>
<property name="margin-bottom">30</property>
<property name="active">True</property>
</object>
<packing>
<property name="name">page1</property>
<property name="title" translatable="yes">page1</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkScrolledWindow" id="tracks">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="shadow-type">in</property>
<child>
<object class="GtkViewport">
<property name="visible">True</property>
<property name="can-focus">False</property>
<child>
<object class="GtkListBox" id="track_list">
<property name="visible">True</property>
<property name="can-focus">False</property>
</object>
</child>
</object>
</child>
</object>
<packing>
<property name="name">page4</property>
<property name="title" translatable="yes">page4</property>
<property name="position">2</property>
</packing>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
</object>
</interface>

86
src/track_tile.ui Normal file
View File

@ -0,0 +1,86 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.38.2 -->
<interface>
<requires lib="gtk+" version="3.24"/>
<object class="GtkBox" id="trk">
<property name="visible">True</property>
<property name="can-focus">False</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkLabel" id="title">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">title</property>
<attributes>
<attribute name="weight" value="bold"/>
</attributes>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="artist">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">artist</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="album">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">album</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="dl">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<property name="margin-top">10</property>
<property name="margin-bottom">10</property>
<child>
<object class="GtkImage">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="icon-name">media-playback-start</property>
</object>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="padding">10</property>
<property name="pack-type">end</property>
<property name="position">1</property>
</packing>
</child>
</object>
</interface>

80
src/track_tile.ui~ Normal file
View File

@ -0,0 +1,80 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.38.2 -->
<interface>
<requires lib="gtk+" version="3.24"/>
<object class="GtkBox" id="trk">
<property name="visible">True</property>
<property name="can-focus">False</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkLabel" id="title">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">title</property>
<attributes>
<attribute name="weight" value="bold"/>
</attributes>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="artist">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">artist</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="album">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">album</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="dl">
<property name="label" translatable="yes">DL</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<property name="margin-top">10</property>
<property name="margin-bottom">10</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="padding">10</property>
<property name="pack-type">end</property>
<property name="position">1</property>
</packing>
</child>
</object>
</interface>