-
Notifications
You must be signed in to change notification settings - Fork 41
/
common.rs
94 lines (83 loc) · 2.1 KB
/
common.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#![allow(unused)]
use std::path::PathBuf;
use rand::Rng;
use rustube::{Id, IdBuf};
pub const SIGNATURE_CIPHER: &[&str] = &[
"5jlI4uzZGjU",
"JgGuRKgvWQ4",
];
pub const PRE_SIGNED: &[&str] = &[
"2lAe1cqCOXo",
"QRS8MkLhQmM",
"xQDsI2ptfgg",
"MAoOAa_izh0",
"qG7kqns7SVM",
"JsGOGPTVkKg",
"hK4dUSV9erk",
"zCKk7HiKdko",
"UN3uF3990Q0",
"CbxQWAFv7sA",
];
pub const AGE_RESTRICTED: &[&str] = &[
"VXDsM-1McE0",
"irauhITDrsE"
];
pub const PRIVATE: &[&str] = &[
"m8uHb5jIGN8"
];
pub const REGION_BLOCKED: &[&str] = &[];
pub const MISSING_RECORDING: &[&str] = &[
"5YceQ8YqYMc"
];
pub const LIVE_STREAM: &[&str] = &[
"ASGNUnPINdM",
"FwwgBB8l2vs",
"X437XmpsopA",
];
pub const DOWNLOAD_DIR: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/videos");
macro_rules! correct_path {
($path:expr, $expected:expr) => {
dbg!(&$path);
assert_eq!(
$path.canonicalize().unwrap(),
$expected.canonicalize().unwrap(),
);
};
}
#[cfg(feature = "descramble")]
macro_rules! video {
($id:expr) => {
dbg!(
dbg!(
VideoFetcher::from_id($id)
.expect("Failed to construct a VideoFetcher ")
.fetch()
.await
.expect("Failed to fetch the video")
)
.descramble()
.expect("Failed to descramble the video")
)
};
}
pub async fn download_path_from_id(id: Id<'_>) -> PathBuf {
tokio::fs::create_dir_all(DOWNLOAD_DIR).await.unwrap();
std::env::set_current_dir(DOWNLOAD_DIR).unwrap();
let path = std::path::Path::new(DOWNLOAD_DIR)
.join(id.as_str())
.with_extension("mp4");
let _ = tokio::fs::remove_file(&path).await;
assert!(!path.is_file());
path
}
pub fn random_id(ids: &'static [&'static str]) -> IdBuf {
let i = rand::thread_rng()
.gen_range(0..ids.len());
Id::from_str(ids[i])
.unwrap()
}
pub fn random_entry<T>(vec: &Vec<T>) -> &T {
let i = rand::thread_rng()
.gen_range(0..vec.len());
&vec[i]
}