implemented tags for videos

This commit is contained in:
Simon
2025-06-03 15:34:02 +00:00
parent 082b3b5c1d
commit 2e8b8bea0c
3 changed files with 68 additions and 9 deletions

View File

@@ -11,7 +11,6 @@ mod util;
#[ntex::main] #[ntex::main]
async fn main() -> std::io::Result<()> { async fn main() -> std::io::Result<()> {
std::env::set_var("RUST_LOG", "ntex=info");
std::env::set_var("RUST_BACKTRACE", "1"); std::env::set_var("RUST_BACKTRACE", "1");
env_logger::init(); // You need this to actually see logs env_logger::init(); // You need this to actually see logs

View File

@@ -152,15 +152,17 @@ impl PerverzijaProvider {
.split("video-item post") .split("video-item post")
.collect::<Vec<&str>>()[1..] .collect::<Vec<&str>>()[1..]
.to_vec(); .to_vec();
// println!("Raw Videos: {:?}", raw_videos);
for video_segment in &raw_videos { for video_segment in &raw_videos {
let vid = video_segment.split("\n").collect::<Vec<&str>>(); let vid = video_segment.split("\n").collect::<Vec<&str>>();
// let mut index = 0;
if vid.len() > 20 { if vid.len() > 20 {
println!("Skipping video segment with unexpected length: {}", vid.len()); println!("Skipping video segment with unexpected length: {}", vid.len());
continue; continue;
} }
for (i, line) in vid.iter().enumerate() {
if line.trim().is_empty() {
println!("Empty line at index {}: {}", i, line);
}
}
let mut title = vid[1].split(">").collect::<Vec<&str>>()[1] let mut title = vid[1].split(">").collect::<Vec<&str>>()[1]
.split("<") .split("<")
.collect::<Vec<&str>>()[0] .collect::<Vec<&str>>()[0]
@@ -208,6 +210,17 @@ impl PerverzijaProvider {
.collect::<Vec<&str>>()[0] .collect::<Vec<&str>>()[0]
.to_string(); .to_string();
let embed = Video_Embed::new(embed_html, url.clone()); let embed = Video_Embed::new(embed_html, url.clone());
let mut tags: Vec<String> = Vec::new(); // Placeholder for tags, adjust as needed
for tag in vid[0].split(" ").collect::<Vec<&str>>(){
if tag.starts_with("tag-") {
let tag_name = tag.split("tag-").collect::<Vec<&str>>()[1]
.to_string();
if !tag_name.is_empty() {
tags.push(tag_name.replace("-", " ").to_string());
}
}
}
let mut video_item = Video_Item::new( let mut video_item = Video_Item::new(
id, id,
title, title,
@@ -215,8 +228,8 @@ impl PerverzijaProvider {
"perverzija".to_string(), "perverzija".to_string(),
thumb, thumb,
duration, duration,
); ).tags(tags)
video_item.embed = Some(embed); .embed(embed.clone());
let mut format = let mut format =
videos::Video_Format::new(url.clone(), "1080".to_string(), "m3u8".to_string()); videos::Video_Format::new(url.clone(), "1080".to_string(), "m3u8".to_string());
format.add_http_header("Referer".to_string(), referer_url.clone()); format.add_http_header("Referer".to_string(), referer_url.clone());
@@ -268,7 +281,6 @@ impl PerverzijaProvider {
18 => 14, 18 => 14,
13 => 8, 13 => 8,
_ => { _ => {
println!("Unexpected video segment length: {}", vid.len());
continue; continue;
} }
}; };
@@ -296,6 +308,17 @@ impl PerverzijaProvider {
.collect::<Vec<&str>>()[0] .collect::<Vec<&str>>()[0]
.to_string(); .to_string();
let embed = Video_Embed::new(embed_html, url.clone()); let embed = Video_Embed::new(embed_html, url.clone());
let mut tags: Vec<String> = Vec::new(); // Placeholder for tags, adjust as needed
for tag in vid[0].split(" ").collect::<Vec<&str>>(){
if tag.starts_with("tag-") {
let tag_name = tag.split("tag-").collect::<Vec<&str>>()[1]
.to_string();
if !tag_name.is_empty() {
tags.push(tag_name.replace("-", " ").to_string());
}
}
}
let mut video_item = Video_Item::new( let mut video_item = Video_Item::new(
id, id,
title, title,
@@ -303,8 +326,9 @@ impl PerverzijaProvider {
"perverzija".to_string(), "perverzija".to_string(),
thumb, thumb,
duration, duration,
); )
video_item.embed = Some(embed); .tags(tags)
.embed(embed.clone());
let mut format = let mut format =
videos::Video_Format::new(url.clone(), "1080".to_string(), "m3u8".to_string()); videos::Video_Format::new(url.clone(), "1080".to_string(), "m3u8".to_string());
format.add_http_header("Referer".to_string(), referer_url.clone()); format.add_http_header("Referer".to_string(), referer_url.clone());

View File

@@ -76,6 +76,42 @@ impl Video_Item {
embed: None, // Placeholder for embed information embed: None, // Placeholder for embed information
} }
} }
pub fn tags(mut self, tags: Vec<String>) -> Self {
self.tags = Some(tags);
self
}
pub fn uploader(mut self, uploader: String) -> Self {
self.uploader = Some(uploader);
self
}
pub fn uploader_url(mut self, uploader_url: String) -> Self {
self.uploaderUrl = Some(uploader_url);
self
}
pub fn verified(mut self, verified: bool) -> Self {
self.verified = Some(verified);
self
}
pub fn views(mut self, views: u32) -> Self {
self.views = Some(views);
self
}
pub fn rating(mut self, rating: f32) -> Self {
self.rating = Some(rating);
self
}
pub fn uploaded_at(mut self, uploaded_at: u64) -> Self {
self.uploadedAt = Some(uploaded_at);
self
}
pub fn formats(mut self, formats: Vec<Video_Format>) -> Self {
self.formats = Some(formats);
self
}
pub fn embed(mut self, embed: Video_Embed) -> Self {
self.embed = Some(embed);
self
}
} }
#[derive(serde::Serialize, Debug, Clone)] #[derive(serde::Serialize, Debug, Clone)]