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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#[derive(Debug)]
pub struct Torrent {
pub category: Category,
pub name: String,
pub links: (Option<String>, Option<String>),
pub size: u64,
pub date: u64,
pub seeders: u32,
pub leechers: u32,
pub completed_downloads: u32,
}
impl Torrent {
pub fn torrent_file(&self) -> Option<String> {
let mut result = String::from("https://nyaa.si");
let (first, second) = &self.links;
if let Some(torrent_file) = first {
if torrent_file.starts_with("/download") {
result.push_str(torrent_file);
return Some(result.clone());
}
}
if let Some(torrent_file) = second {
if torrent_file.starts_with("/download") {
result.push_str(torrent_file);
return Some(result.clone());
}
}
None
}
pub fn magnet_link(&self) -> Option<String> {
let (first, second) = &self.links;
if let Some(magnet) = first {
if magnet.starts_with("magnet") {
return Some(magnet.clone());
}
}
if let Some(magnet) = second {
if magnet.starts_with("magnet") {
return Some(magnet.clone());
}
}
None
}
}
#[derive(Debug)]
pub enum Category {
Anime(Anime),
Audio(Audio),
Literature(Literature),
LiveAction(LiveAction),
Pictures(Pictures),
Software(Software),
}
#[derive(Debug)]
pub enum Anime {
AnimeMusicVideo,
EnglishTranslated,
NonEnglishTranslated,
Raw,
}
#[derive(Debug)]
pub enum Audio {
Lossless,
Lossy,
}
#[derive(Debug)]
pub enum Literature {
EnglishTranslated,
NonEnglishTranslated,
Raw,
}
#[derive(Debug)]
pub enum LiveAction {
EnglishTranslated,
IdolPromotionalVideo,
NonEnglishTranslated,
Raw,
}
#[derive(Debug)]
pub enum Pictures {
Graphics,
Photos,
}
#[derive(Debug)]
pub enum Software {
Applications,
Games,
}
#[derive(Debug)]
pub enum Error {
Request,
Scraping,
}