Skip to content

Commit d8a5a8e

Browse files
committed
more pain and suffering, imdb scrapping 100% legit and legal
1 parent 2518f01 commit d8a5a8e

16 files changed

Lines changed: 3631 additions & 109 deletions

File tree

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@ indoc = { version = "2.0" }
1515
itertools = { version = "0.13" }
1616
once_cell = { version = "1.19" }
1717
regex = { version = "1.10" }
18+
reqwest = { version = "0.12" }
1819
serde = { version = "1.0", features = ["derive"] }
1920
serde_json = { version = "1.0" }
2021
time = { version = "0.3", features = ["local-offset"] }
2122
tokio = { version = "1.39", features = ["full"] }
22-
tower-http = { version = "0.5", features = ["fs"] }
23+
tower-http = { version = "0.5", features = ["fs", "trace"] }
2324
tracing = { version = "0.1" }
2425
tracing-appender = { version = "0.2" }
2526
tracing-subscriber = { version = "0.3", features = ["env-filter"] }

assets/default_thumbnail.png

3.75 KB
Loading

assets/script.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const cards = document.querySelectorAll(".card");
2+
cards.forEach(function (card) {
3+
const expand = card.querySelector(".card-expand");
4+
card.addEventListener("click", function (event) {
5+
if (event.target.tagName !== "IMG") {
6+
expand.classList.toggle("show");
7+
card.classList.toggle("expanded");
8+
}
9+
});
10+
});

assets/style.css

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
body {
2+
background-color: #0a0a0c;
3+
}
4+
.card-row {
5+
display: flex;
6+
flex-direction: row;
7+
gap: 20px;
8+
justify-content: center;
9+
align-items: stretch;
10+
}
11+
12+
.card-column {
13+
display: flex;
14+
flex-direction: column;
15+
}
16+
17+
.card {
18+
padding: 10px;
19+
border-radius: 10px;
20+
background-color: #121214;
21+
box-shadow: 0px -10px #0e0e10;
22+
margin-top: 25px;
23+
width: 42vw;
24+
}
25+
26+
.card-header {
27+
display: flex;
28+
align-items: center;
29+
text-wrap: stable;
30+
}
31+
32+
.card-header-thumbnail {
33+
img {
34+
border-radius: 5px;
35+
width: 126px;
36+
height: 188px;
37+
}
38+
}
39+
40+
.card-header-box {
41+
display: flex;
42+
flex-direction: column;
43+
padding: 35px;
44+
line-height: 0em;
45+
}
46+
47+
.card-header-box-title {
48+
color: #f5f5ed;
49+
line-height: 1.4em;
50+
}
51+
52+
.card-header-box-subtitle {
53+
img {
54+
height: 1em;
55+
}
56+
color: #d5d5cd;
57+
word-spacing: 1em;
58+
}
59+
60+
.card-expand {
61+
img {
62+
height: 1em;
63+
}
64+
p {
65+
color: #d5d5cd;
66+
}
67+
li {
68+
color: #d5d5cd;
69+
}
70+
display: none;
71+
flex-direction: column;
72+
padding: 10px;
73+
}
74+
75+
.card-expand.show {
76+
display: flex;
77+
}
78+
79+
.card.expanded {
80+
}
81+
82+
.page-header {
83+
img {
84+
width: 12vw;
85+
}
86+
h1 {
87+
color: #f5f5ed;
88+
}
89+
h3 {
90+
color: #e5e5dd;
91+
}
92+
display: block;
93+
text-align: center;
94+
}

src/card/cards.rs

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,77 @@
1+
use super::*;
2+
use axum::response::{Html, IntoResponse};
3+
use indoc::formatdoc;
14

5+
pub struct Cards(Vec<Card>);
6+
7+
static STYLE: &str = include_str!("../../assets/style.css");
8+
static SCRIPT: &str = include_str!("../../assets/script.js");
9+
10+
impl Cards {
11+
pub fn load() -> eyre::Result<Self> {
12+
let path = crate::config::get()
13+
.target_dir
14+
.to_owned()
15+
.ok_or_eyre("No target path set, use the init subcommand")?;
16+
17+
let cards: Vec<Card> = std::fs::read_dir(&path)?
18+
.filter_map(|dir| {
19+
let dir = match dir {
20+
Ok(dir) => dir.path(),
21+
Err(err) => {
22+
warn!("{err}");
23+
return None;
24+
}
25+
};
26+
if dir.is_dir() {
27+
match Card::from_path(&dir) {
28+
Ok(card) => Some(card),
29+
Err(err) => {
30+
warn!("{err}");
31+
None
32+
}
33+
}
34+
} else {
35+
None
36+
}
37+
})
38+
.collect();
39+
40+
Ok(Self(cards))
41+
}
42+
43+
pub fn generate_static_html_page(self) -> String {
44+
formatdoc! {
45+
"<!doctype html>
46+
<html lang=\"en\">
47+
<head>
48+
<meta charset=\"UTF-8\" />
49+
<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" />
50+
<meta name=\"description\" content=\"server\" />
51+
<meta name=\"author\" content=\"anesthetice\" />
52+
<title>Silvus</title>
53+
<style>
54+
{}
55+
</style>
56+
</head>
57+
<body>
58+
<div class=\"page-header\">
59+
<img src=\"/res/.assets/icon.svg\" />
60+
</div>
61+
<div class=\"card-row\">
62+
<div class=\"card-column\">
63+
{}
64+
</div>
65+
</div>
66+
<script>
67+
{}
68+
</script>
69+
</body>
70+
</html>
71+
",
72+
STYLE,
73+
self.0.into_iter().map(|card| card.into_html_string()).fold(String::new(), |acc, x| acc + &x +"\n"),
74+
SCRIPT,
75+
}
76+
}
77+
}

src/card/mod.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Modules
2-
mod cards;
2+
pub mod cards;
33
mod movie;
44
mod other;
55
mod show;
@@ -12,6 +12,7 @@ use eyre::{eyre, OptionExt};
1212
use itertools::Itertools;
1313
use once_cell::sync::Lazy;
1414
use regex::Regex;
15+
use std::fmt::Display;
1516
use std::path::{Path, PathBuf};
1617
use tracing::{instrument, warn};
1718

@@ -66,14 +67,14 @@ impl Card {
6667
// Movie route
6768
1 => movie::Movie::from_paths(base, path, vid_fps, dot_fps, otr_fps),
6869
// Show route
69-
2.. => Err(eyre!("'Show' route not ready")),
70+
2.. => show::Show::from_paths(base, path, vid_fps, dot_fps, otr_fps),
7071
}
7172
}
7273

7374
pub fn into_html_string(self) -> String {
7475
match self {
7576
Self::Movie(movie) => movie.into_html_string(),
76-
Self::Show(show) => String::from("SHOW NOT IMPLEMENTED"),
77+
Self::Show(show) => show.into_html_string(),
7778
Self::Other(other) => String::from("OTHER NOT IMPLEMENTED"),
7879
}
7980
}
@@ -100,3 +101,10 @@ impl From<u64> for FileSize {
100101
Self(u32::try_from(value / 1_000_000).unwrap_or(u32::MAX))
101102
}
102103
}
104+
105+
fn display<T: Display>(input: Option<T>, pre: &str, post: &str, alt: &str) -> String {
106+
match input {
107+
Some(val) => format!("{pre}{}{post}", val),
108+
None => alt.to_owned(),
109+
}
110+
}

src/card/movie.rs

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,6 @@ pub struct Movie {
1212
filesize: FileSize,
1313
}
1414

15-
// this is sane way of doing things, trust me bro
16-
macro_rules! E {
17-
($e:expr, $i:literal) => {
18-
if let Some(ref a) = $e {
19-
a
20-
} else {
21-
$i
22-
}
23-
};
24-
}
25-
26-
// this is sane way of doing things, trust me bro
27-
macro_rules! F {
28-
($e:expr, $p:literal, $i:literal) => {
29-
if let Some(ref a) = $e {
30-
a.to_string() + $p
31-
} else {
32-
$i.to_string()
33-
}
34-
};
35-
}
36-
3715
impl CardMethods for Movie {
3816
fn from_paths(
3917
base: &Path,
@@ -92,26 +70,27 @@ impl CardMethods for Movie {
9270
indoc::formatdoc! {
9371
"<div class=\"card\">
9472
<div class=\"card-header\">
95-
<div class=\"card-header-thumbnail\"><img src=\"{}\" /></div>
73+
<div class=\"card-header-thumbnail\"><img src=\"/res/{}\" /></div>
9674
<div class=\"card-header-box\">
9775
<div class=\"card-header-box-title\"><h2>{}</h2></div>
9876
<div class=\"card-header-box-subtitle\">
9977
<p>
100-
{}{:?} MB • <a href=\"{}\" download><img src=\".assets/download.svg\" /></a>
78+
{}{:?} MB • <a href=\"/res/{}\" download><img src=\"/res/.assets/download.svg\" /></a>
10179
</p>
10280
</div>
10381
</div>
10482
</div>
10583
<div class=\"card-expand\">
10684
<p>{}</p>
107-
</div>",
85+
</div>
86+
</div>",
10887

109-
E!(self.thumbnail, "./assets/thumbnail.jpg"),
88+
display(self.thumbnail, "", "", ".assets/default_thumbnail.png"),
11089
self.title,
111-
F!(self.year, " • ", ""),
90+
display(self.year, "", " • ", ""),
11291
self.filesize.0,
11392
self.filepath,
114-
E!(self.description, "No description provided"),
93+
display(self.description, "", "", "No description provided.")
11594
}
11695
}
11796
}

src/card/show.rs

Lines changed: 21 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -15,28 +15,6 @@ pub struct Show {
1515
episodes: Vec<(u8, u8, String, FileSize)>,
1616
}
1717

18-
// this is sane way of doing things, trust me bro
19-
macro_rules! Exp {
20-
($e:expr, $i:literal) => {
21-
if let Some(ref a) = $e {
22-
a
23-
} else {
24-
$i
25-
}
26-
};
27-
}
28-
29-
// this is sane way of doing things, trust me bro
30-
macro_rules! Pre {
31-
($e:expr, $p:literal, $i:literal) => {
32-
if let Some(ref a) = $e {
33-
$p.to_string() + a.to_string()
34-
} else {
35-
$i.to_string()
36-
}
37-
};
38-
}
39-
4018
impl CardMethods for Show {
4119
fn from_paths(
4220
base: &Path,
@@ -121,28 +99,38 @@ impl CardMethods for Show {
12199
indoc::formatdoc! {
122100
"<div class=\"card\">
123101
<div class=\"card-header\">
124-
<div class=\"card-header-thumbnail\"><img src=\"{}\" /></div>
102+
<div class=\"card-header-thumbnail\"><img src=\"/res/{}\" /></div>
125103
<div class=\"card-header-box\">
126104
<div class=\"card-header-box-title\"><h2>{}</h2></div>
127105
<div class=\"card-header-box-subtitle\">
128-
<p>2024 • Season  01</p>
129-
</div>
106+
<p>{} • {}</p>
130107
</div>
131108
</div>
132109
</div>
133110
<div class=\"card-expand\">
134-
<p>{}</p>
135111
<p>
136-
season  01 • episode  01 • 2405  MB • <a href=\"https://google.com\" download><img src=\".assets/download.svg\" /></a>
112+
{}
137113
</p>
138-
</div>",
114+
<p>
115+
{}
116+
</p>
117+
</div>
118+
</div>",
139119

140-
Exp!(self.thumbnail, "./assets/thumbnail.jpg"),
120+
display(self.thumbnail, "", "", ".assets/default_thumbnail.png"),
141121
self.title,
142-
Pre!(self.year, " • ", ""),
143-
Pre!(self.subtitle, " • ")
144-
self.filepath,
145-
Exp!(self.description, "No description provided"),
122+
display(self.year, "", "", "????"),
123+
display(self.subtitle, "", "", ""),
124+
display(self.description, "", "", "No description provided."),
125+
self.episodes.into_iter().map(|(s, e, fp, size)| {
126+
format!(
127+
"season  {:0>2} • episode  {:0>2} • {}  MB • <a href=\"/res/{}\" download><img src=\"/res/.assets/download.svg\" /></a>",
128+
s,
129+
e,
130+
size.0,
131+
fp,
132+
)
133+
}).fold(String::new(), |acc, x| acc + &x + "\n")
146134
}
147135
}
148136
}

0 commit comments

Comments
 (0)