Skip to content

Commit

Permalink
added youtube links to the first few hits and added youtube download …
Browse files Browse the repository at this point in the history
…when starting up the server
  • Loading branch information
Timtam committed Mar 4, 2024
1 parent 7635c2c commit 26c2d94
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 57 deletions.
2 changes: 2 additions & 0 deletions server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ edition = "2021"
dotenvy = "0.15.7"
hex = "0.4.3"
names = "0.14.0"
regex = "1.10.3"
rocket = { version = "0.5.0", features = ["json", "secrets"]}
rocket_db_pools = { version = "0.1.0", default-features = false, features = ["sqlx_sqlite" ]}
rocket_okapi = { version = "0.8.0", default-features = false, features = ["swagger", "rapidoc", "secrets", "rocket_db_pools"]}
rusty_ytdl = "0.6.6"
serde = { version = "1.0.197", features = ["derive"]}
serde_json = "1.0.114"
sha3 = "0.10.8"
Expand Down
21 changes: 14 additions & 7 deletions server/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,24 @@ fn main() {

for result in csv_reader.records() {
let record = result.unwrap();
file_content += format!(
"Hit {{

if record.get(3).unwrap() != "" {
file_content += format!(
"Hit {{
interpret: \"{}\".into(),
title: \"{}\".into(),
year: {},
yt_url: \"{}\".into(),
playback_offset: {},
}},",
record.get(0).unwrap(),
record.get(2).unwrap(),
record.get(1).unwrap()
)
.as_str();
record.get(0).unwrap(),
record.get(2).unwrap(),
record.get(1).unwrap(),
record.get(3).unwrap(),
record.get(4).unwrap_or("0"),
)
.as_str();
}
}

fs::write(
Expand Down
100 changes: 50 additions & 50 deletions server/etc/hits.csv
Original file line number Diff line number Diff line change
@@ -1,50 +1,50 @@
Interpret;Jahr;Titel
O-Zone;2003;Dragostea Din Tei
Dr. Alban;1993;Sing Hallelujah!
Sister Sledge;1979;We Are Family
Spider Murphy Gang;1987;So a Nacht
Jennifer Lopez;1999;If You Had My Love
Gebrüder Blattschuss;1978;Kreuzberger Nächte
Andrea Jürgens;1990;Wir tanzen Lambada
Culture Beat;1993;Mr. Vain
The Bangles;1986;Manic Monday
Udo Jürgens;1965;Siebzehn Jahr, blondes Haar
U96;1992;Das Boot
Hans Kröger;1988;Der blonde Hans
Andrea Jürgens;1991;Santa Catarina
Wencke Myhre;1970;Er hat ein knallrotes Gummiboot
Fats Domino;1955;Ain't That A Shame
Drafi Deutscher;1965;Marmor, Stein und Eisen bricht
Juli;2004;Perfekte Welle
Duffy;2008;Mercy
Sigrid & Marina;2010;Zwei Senoritas
Chicago;1976;If You Leave Me Right Now
Ben Zucker;2018;Der Sonne entgegen
P!nk (feat. Nate Reuss);2013;Just Give Me A Reason
Michael Holm;1974;Tränen lügen nicht
Maite Kelly;2016;Sieben Leben für dich
Stefan Raab;1999;Maschen-Draht-Zaun
Stefan Waggershausen, Viktor Lazlo;1990;Das erste Mal tat's noch weh
Oliver Haidt;1996;Lebenslänglich Du
The Kinks;1970;Lola
Nelly (feat.Kelly Rowland);2002;Dilemma
Demis Roussos;1973;Schönes Mädchen aus Arcadia
Dschinghis Khan;1979;Moskau
Liane ;2014;Ich lass' nur noch Sonne in mein Herz
Gitti und Erica;1977;Heidi
Connie Francis;1964;Schöner fremder Mann
Wildecker Herzbuben;1990;Herzilein
Carly Simon;1972;You're So Vain
Farank Lars;2010;Ich kann nicht ohne dich
Glenn Miller;1939;In The Mood
Brunner & Brunner;1994;Für dich
Die Toten Hosen;2012;Tage wie diese
Christoff;2012;Ich Hab Alain Delon geseh'n
Bill Medley & Jennifer Warnes;1987;(I've Had) The Time Of My Life
Ibo;1998;Ein Himmelbett im Internet
Klostertaler;1997;Ha-Le-Lu-Ja
Freddy Quinn;1956;Heimweh (Dort wo die Blumen blüh'n)
Oliver Pocher;2006;Schwarz und weiss
Wolkenfrei;2014;Ich versprech Dir nichts und geb' Dir alles
Eurythmics;1983;Sweet Dreams (Are Made Of This)
Peter Wackel;2005;Oberammergau
Interpret;Jahr;Titel;Yutube-Link;Abspiel-Beginn (in Sekunden)
O-Zone;2003;Dragostea Din Tei;https://www.youtube.com/watch?v=YnopHCL1Jk8;53
Dr. Alban;1993;Sing Hallelujah!;https://www.youtube.com/watch?v=pKxJca7LLNM;0
Sister Sledge;1979;We Are Family;https://www.youtube.com/watch?v=uyGY2NfYpeE;0
Spider Murphy Gang;1987;So a Nacht;https://www.youtube.com/watch?v=sox_-1x-VGw;0
Jennifer Lopez;1999;If You Had My Love;https://www.youtube.com/watch?v=lYfkl-HXfuU;35
Gebrüder Blattschuss;1978;Kreuzberger Nächte;https://www.youtube.com/watch?v=GNTo1LWnFjg;18
Andrea Jürgens;1990;Wir tanzen Lambada;;
Culture Beat;1993;Mr. Vain;;
The Bangles;1986;Manic Monday;;
Udo Jürgens;1965;Siebzehn Jahr, blondes Haar;;
U96;1992;Das Boot;;
Hans Kröger;1988;Der blonde Hans;;
Andrea Jürgens;1991;Santa Catarina;;
Wencke Myhre;1970;Er hat ein knallrotes Gummiboot;;
Fats Domino;1955;Ain't That A Shame;;
Drafi Deutscher;1965;Marmor, Stein und Eisen bricht;;
Juli;2004;Perfekte Welle;;
Duffy;2008;Mercy;;
Sigrid & Marina;2010;Zwei Senoritas;;
Chicago;1976;If You Leave Me Right Now;;
Ben Zucker;2018;Der Sonne entgegen;;
P!nk (feat. Nate Reuss);2013;Just Give Me A Reason;;
Michael Holm;1974;Tränen lügen nicht;;
Maite Kelly;2016;Sieben Leben für dich;;
Stefan Raab;1999;Maschen-Draht-Zaun;;
Stefan Waggershausen, Viktor Lazlo;1990;Das erste Mal tat's noch weh;;
Oliver Haidt;1996;Lebenslänglich Du;;
The Kinks;1970;Lola;;
Nelly (feat.Kelly Rowland);2002;Dilemma;;
Demis Roussos;1973;Schönes Mädchen aus Arcadia;;
Dschinghis Khan;1979;Moskau;;
Liane ;2014;Ich lass' nur noch Sonne in mein Herz;;
Gitti und Erica;1977;Heidi;;
Connie Francis;1964;Schöner fremder Mann;;
Wildecker Herzbuben;1990;Herzilein;;
Carly Simon;1972;You're So Vain;;
Farank Lars;2010;Ich kann nicht ohne dich;;
Glenn Miller;1939;In The Mood;;
Brunner & Brunner;1994;Für dich;;
Die Toten Hosen;2012;Tage wie diese;;
Christoff;2012;Ich Hab Alain Delon geseh'n;;
Bill Medley & Jennifer Warnes;1987;(I've Had) The Time Of My Life;;
Ibo;1998;Ein Himmelbett im Internet;;
Klostertaler;1997;Ha-Le-Lu-Ja;;
Freddy Quinn;1956;Heimweh (Dort wo die Blumen blüh'n);;
Oliver Pocher;2006;Schwarz und weiss;;
Wolkenfrei;2014;Ich versprech Dir nichts und geb' Dir alles;;
Eurythmics;1983;Sweet Dreams (Are Made Of This);;
Peter Wackel;2005;Oberammergau;;
68 changes: 68 additions & 0 deletions server/src/hits.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,75 @@
use regex::Regex;
use rocket::{
fairing::{Fairing, Info, Kind},
Orbit, Rocket,
};
use rusty_ytdl::{Video, VideoOptions, VideoQuality, VideoSearchOptions};
use std::{env, fs::create_dir_all, path::Path};

include!(concat!(env!("OUT_DIR"), "/hits.rs"));

pub struct Hit {
pub interpret: String,
pub title: String,
pub year: u32,
pub yt_url: String,
pub playback_offset: u16,
}

#[derive(Default)]
pub struct HitsterDownloader {}

#[rocket::async_trait]
impl Fairing for HitsterDownloader {
fn info(&self) -> Info {
Info {
kind: Kind::Liftoff,
name: "Download hits",
}
}

async fn on_liftoff(&self, _rocket: &Rocket<Orbit>) {
let yt_id: Regex = Regex::new(
r"^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#&?]*).*",
)
.unwrap();

let download_dir = env::var("DOWNLOAD_DIRECTORY").unwrap_or("./hits".to_string());

let _ = create_dir_all(download_dir.clone());

println!("Starting download of missing hits. This may take a while...");

for hit in get_all().iter() {
if let Some(caps) = yt_id.captures(hit.yt_url.as_str()) {
let id = &caps[7];

if !Path::new(&download_dir)
.join(format!("{}.opus", id))
.is_file()
{
let options = VideoOptions {
quality: VideoQuality::HighestAudio,
filter: VideoSearchOptions::Audio,
..Default::default()
};
let video = Video::new_with_options(id, options).unwrap();

println!(
"Download {}: {} to {}.opus",
hit.interpret.as_str(),
hit.title.as_str(),
id
);

video
.download(format!("{}/{}.mp4", download_dir.as_str(), id))
.await
.unwrap();
}
}
}

println!("Download finished.");
}
}
2 changes: 2 additions & 0 deletions server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ mod services;
mod users;

use dotenvy::dotenv;
use hits::HitsterDownloader;
use rocket::{
fairing::{self, AdHoc},
figment::{util::map, Figment},
Expand Down Expand Up @@ -49,6 +50,7 @@ fn rocket_from_config(figment: Figment) -> Rocket<Build> {
rocket::custom(figment)
.attach(HitsterConfig::init())
.attach(migrations_fairing)
.attach(HitsterDownloader::default())
.mount("/", routes![index,])
.mount(
"/",
Expand Down

0 comments on commit 26c2d94

Please sign in to comment.