refactor: remove microformat parsing for player
This commit is contained in:
parent
ab61cfb4ca
commit
6ee24081da
10 changed files with 22 additions and 108 deletions
|
|
@ -3,7 +3,6 @@ use std::{
|
||||||
collections::{BTreeMap, HashMap},
|
collections::{BTreeMap, HashMap},
|
||||||
};
|
};
|
||||||
|
|
||||||
use chrono::{Local, NaiveDateTime, NaiveTime, TimeZone};
|
|
||||||
use fancy_regex::Regex;
|
use fancy_regex::Regex;
|
||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
|
@ -157,21 +156,6 @@ impl MapResponse<VideoPlayer> for response::Player {
|
||||||
self.video_details,
|
self.video_details,
|
||||||
Err(ExtractionError::InvalidData("no video details".into()))
|
Err(ExtractionError::InvalidData("no video details".into()))
|
||||||
);
|
);
|
||||||
let microformat = self.microformat.map(|m| m.player_microformat_renderer);
|
|
||||||
let (publish_date, category, tags, is_family_safe) =
|
|
||||||
microformat.map_or((None, None, None, None), |m| {
|
|
||||||
(
|
|
||||||
Local
|
|
||||||
.from_local_datetime(&NaiveDateTime::new(
|
|
||||||
m.publish_date,
|
|
||||||
NaiveTime::from_hms(0, 0, 0),
|
|
||||||
))
|
|
||||||
.single(),
|
|
||||||
Some(m.category),
|
|
||||||
m.tags,
|
|
||||||
Some(m.is_family_safe),
|
|
||||||
)
|
|
||||||
});
|
|
||||||
|
|
||||||
if video_details.video_id != id {
|
if video_details.video_id != id {
|
||||||
return Err(ExtractionError::WrongResult(format!(
|
return Err(ExtractionError::WrongResult(format!(
|
||||||
|
|
@ -190,15 +174,10 @@ impl MapResponse<VideoPlayer> for response::Player {
|
||||||
id: video_details.channel_id,
|
id: video_details.channel_id,
|
||||||
name: video_details.author,
|
name: video_details.author,
|
||||||
},
|
},
|
||||||
publish_date,
|
|
||||||
view_count: video_details.view_count,
|
view_count: video_details.view_count,
|
||||||
keywords: match video_details.keywords {
|
keywords: video_details.keywords,
|
||||||
Some(keywords) => keywords,
|
is_live,
|
||||||
None => tags.unwrap_or_default(),
|
|
||||||
},
|
|
||||||
category,
|
|
||||||
is_live_content: video_details.is_live_content,
|
is_live_content: video_details.is_live_content,
|
||||||
is_family_safe,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut formats = streaming_data.formats.c;
|
let mut formats = streaming_data.formats.c;
|
||||||
|
|
@ -671,17 +650,6 @@ mod tests {
|
||||||
assert_eq!(player_data.details.keywords[0], "spektrem");
|
assert_eq!(player_data.details.keywords[0], "spektrem");
|
||||||
assert_eq!(player_data.details.is_live_content, false);
|
assert_eq!(player_data.details.is_live_content, false);
|
||||||
|
|
||||||
if client_type == ClientType::Desktop || client_type == ClientType::DesktopMusic {
|
|
||||||
assert!(player_data
|
|
||||||
.details
|
|
||||||
.publish_date
|
|
||||||
.unwrap()
|
|
||||||
.to_string()
|
|
||||||
.starts_with("2013-05-05 00:00:00"));
|
|
||||||
assert_eq!(player_data.details.category.unwrap(), "Music");
|
|
||||||
assert_eq!(player_data.details.is_family_safe.unwrap(), true);
|
|
||||||
}
|
|
||||||
|
|
||||||
if client_type == ClientType::Ios {
|
if client_type == ClientType::Ios {
|
||||||
let video = player_data
|
let video = player_data
|
||||||
.video_only_streams
|
.video_only_streams
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
use std::ops::Range;
|
use std::ops::Range;
|
||||||
|
|
||||||
use chrono::NaiveDate;
|
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use serde_with::serde_as;
|
use serde_with::serde_as;
|
||||||
use serde_with::{json::JsonString, DefaultOnError};
|
use serde_with::{json::JsonString, DefaultOnError};
|
||||||
|
|
@ -15,7 +14,6 @@ pub struct Player {
|
||||||
pub streaming_data: Option<StreamingData>,
|
pub streaming_data: Option<StreamingData>,
|
||||||
pub captions: Option<Captions>,
|
pub captions: Option<Captions>,
|
||||||
pub video_details: Option<VideoDetails>,
|
pub video_details: Option<VideoDetails>,
|
||||||
pub microformat: Option<Microformat>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize)]
|
||||||
|
|
@ -204,7 +202,8 @@ pub struct VideoDetails {
|
||||||
pub title: String,
|
pub title: String,
|
||||||
#[serde_as(as = "JsonString")]
|
#[serde_as(as = "JsonString")]
|
||||||
pub length_seconds: u32,
|
pub length_seconds: u32,
|
||||||
pub keywords: Option<Vec<String>>,
|
#[serde(default)]
|
||||||
|
pub keywords: Vec<String>,
|
||||||
pub channel_id: String,
|
pub channel_id: String,
|
||||||
pub short_description: Option<String>,
|
pub short_description: Option<String>,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
|
|
@ -214,22 +213,3 @@ pub struct VideoDetails {
|
||||||
pub author: String,
|
pub author: String,
|
||||||
pub is_live_content: bool,
|
pub is_live_content: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
|
||||||
#[serde(rename_all = "camelCase")]
|
|
||||||
pub struct Microformat {
|
|
||||||
#[serde(alias = "microformatDataRenderer")]
|
|
||||||
pub player_microformat_renderer: PlayerMicroformatRenderer,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[serde_as]
|
|
||||||
#[derive(Debug, Deserialize)]
|
|
||||||
#[serde(rename_all = "camelCase")]
|
|
||||||
pub struct PlayerMicroformatRenderer {
|
|
||||||
#[serde(alias = "familySafe")]
|
|
||||||
pub is_family_safe: bool,
|
|
||||||
pub category: String,
|
|
||||||
pub publish_date: NaiveDate,
|
|
||||||
// Only on YT Music
|
|
||||||
pub tags: Option<Vec<String>>,
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,6 @@ VideoPlayer(
|
||||||
id: "UCbxxEi-ImPlbLx5F-fHetEg",
|
id: "UCbxxEi-ImPlbLx5F-fHetEg",
|
||||||
name: "RomanSenykMusic - Royalty Free Music",
|
name: "RomanSenykMusic - Royalty Free Music",
|
||||||
),
|
),
|
||||||
publish_date: "~",
|
|
||||||
view_count: 426567,
|
view_count: 426567,
|
||||||
keywords: [
|
keywords: [
|
||||||
"no copyright music",
|
"no copyright music",
|
||||||
|
|
@ -59,9 +58,8 @@ VideoPlayer(
|
||||||
"motivational music",
|
"motivational music",
|
||||||
"montage music",
|
"montage music",
|
||||||
],
|
],
|
||||||
category: None,
|
is_live: false,
|
||||||
is_live_content: false,
|
is_live_content: false,
|
||||||
is_family_safe: None,
|
|
||||||
),
|
),
|
||||||
video_streams: [
|
video_streams: [
|
||||||
VideoStream(
|
VideoStream(
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,6 @@ VideoPlayer(
|
||||||
id: "UCbxxEi-ImPlbLx5F-fHetEg",
|
id: "UCbxxEi-ImPlbLx5F-fHetEg",
|
||||||
name: "RomanSenykMusic - Royalty Free Music",
|
name: "RomanSenykMusic - Royalty Free Music",
|
||||||
),
|
),
|
||||||
publish_date: "2019-05-30T00:00:00",
|
|
||||||
view_count: 426567,
|
view_count: 426567,
|
||||||
keywords: [
|
keywords: [
|
||||||
"no copyright music",
|
"no copyright music",
|
||||||
|
|
@ -64,9 +63,8 @@ VideoPlayer(
|
||||||
"motivational music",
|
"motivational music",
|
||||||
"montage music",
|
"montage music",
|
||||||
],
|
],
|
||||||
category: Some("Music"),
|
is_live: false,
|
||||||
is_live_content: false,
|
is_live_content: false,
|
||||||
is_family_safe: Some(true),
|
|
||||||
),
|
),
|
||||||
video_streams: [
|
video_streams: [
|
||||||
VideoStream(
|
VideoStream(
|
||||||
|
|
|
||||||
|
|
@ -29,34 +29,10 @@ VideoPlayer(
|
||||||
id: "UCbxxEi-ImPlbLx5F-fHetEg",
|
id: "UCbxxEi-ImPlbLx5F-fHetEg",
|
||||||
name: "Romansenykmusic",
|
name: "Romansenykmusic",
|
||||||
),
|
),
|
||||||
publish_date: "2019-05-30T00:00:00",
|
|
||||||
view_count: 426583,
|
view_count: 426583,
|
||||||
keywords: [
|
keywords: [],
|
||||||
"no copyright music",
|
is_live: false,
|
||||||
"background music",
|
|
||||||
"copyright free music",
|
|
||||||
"non copyrighted music",
|
|
||||||
"free music",
|
|
||||||
"no copyright music cinematic",
|
|
||||||
"inspiring music",
|
|
||||||
"inspiring background music",
|
|
||||||
"cinematic music",
|
|
||||||
"cinematic background music",
|
|
||||||
"no copyright music inspiring",
|
|
||||||
"free music no copyright",
|
|
||||||
"uplifting music",
|
|
||||||
"trailer music no copyright",
|
|
||||||
"trailer music",
|
|
||||||
"download music",
|
|
||||||
"free background music",
|
|
||||||
"orchestral music",
|
|
||||||
"romansenykmusic",
|
|
||||||
"motivational music",
|
|
||||||
"montage music",
|
|
||||||
],
|
|
||||||
category: Some("Music"),
|
|
||||||
is_live_content: false,
|
is_live_content: false,
|
||||||
is_family_safe: Some(true),
|
|
||||||
),
|
),
|
||||||
video_streams: [
|
video_streams: [
|
||||||
VideoStream(
|
VideoStream(
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,6 @@ VideoPlayer(
|
||||||
id: "UCbxxEi-ImPlbLx5F-fHetEg",
|
id: "UCbxxEi-ImPlbLx5F-fHetEg",
|
||||||
name: "RomanSenykMusic - Royalty Free Music",
|
name: "RomanSenykMusic - Royalty Free Music",
|
||||||
),
|
),
|
||||||
publish_date: "~",
|
|
||||||
view_count: 426567,
|
view_count: 426567,
|
||||||
keywords: [
|
keywords: [
|
||||||
"no copyright music",
|
"no copyright music",
|
||||||
|
|
@ -54,9 +53,8 @@ VideoPlayer(
|
||||||
"motivational music",
|
"motivational music",
|
||||||
"montage music",
|
"montage music",
|
||||||
],
|
],
|
||||||
category: None,
|
is_live: false,
|
||||||
is_live_content: false,
|
is_live_content: false,
|
||||||
is_family_safe: None,
|
|
||||||
),
|
),
|
||||||
video_streams: [],
|
video_streams: [],
|
||||||
video_only_streams: [
|
video_only_streams: [
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,6 @@ VideoPlayer(
|
||||||
id: "UCbxxEi-ImPlbLx5F-fHetEg",
|
id: "UCbxxEi-ImPlbLx5F-fHetEg",
|
||||||
name: "RomanSenykMusic - Royalty Free Music",
|
name: "RomanSenykMusic - Royalty Free Music",
|
||||||
),
|
),
|
||||||
publish_date: "~",
|
|
||||||
view_count: 426567,
|
view_count: 426567,
|
||||||
keywords: [
|
keywords: [
|
||||||
"no copyright music",
|
"no copyright music",
|
||||||
|
|
@ -64,9 +63,8 @@ VideoPlayer(
|
||||||
"motivational music",
|
"motivational music",
|
||||||
"montage music",
|
"montage music",
|
||||||
],
|
],
|
||||||
category: None,
|
is_live: false,
|
||||||
is_live_content: false,
|
is_live_content: false,
|
||||||
is_family_safe: None,
|
|
||||||
),
|
),
|
||||||
video_streams: [
|
video_streams: [
|
||||||
VideoStream(
|
VideoStream(
|
||||||
|
|
|
||||||
|
|
@ -71,17 +71,14 @@ pub struct VideoPlayerDetails {
|
||||||
pub thumbnail: Vec<Thumbnail>,
|
pub thumbnail: Vec<Thumbnail>,
|
||||||
/// Channel of the video
|
/// Channel of the video
|
||||||
pub channel: ChannelId,
|
pub channel: ChannelId,
|
||||||
/// Video publishing date. Start date in case of a livestream.
|
|
||||||
pub publish_date: Option<DateTime<Local>>,
|
|
||||||
/// Number of views / current viewers in case of a livestream.
|
/// Number of views / current viewers in case of a livestream.
|
||||||
pub view_count: u64,
|
pub view_count: u64,
|
||||||
/// List of words that describe the topic of the video
|
/// List of words that describe the topic of the video
|
||||||
pub keywords: Vec<String>,
|
pub keywords: Vec<String>,
|
||||||
pub category: Option<String>,
|
/// True if the video is an active livestream
|
||||||
|
pub is_live: bool,
|
||||||
/// True if the video is/was livestreamed
|
/// True if the video is/was livestreamed
|
||||||
pub is_live_content: bool,
|
pub is_live_content: bool,
|
||||||
/// True if the video is not age-restricted
|
|
||||||
pub is_family_safe: Option<bool>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Video stream
|
/// Video stream
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,6 @@
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"channel": { "id": "UCYq-iAOSZBvoUxvfzwKIZWA", "name": "Jacob + Katie Schwarz" },
|
"channel": { "id": "UCYq-iAOSZBvoUxvfzwKIZWA", "name": "Jacob + Katie Schwarz" },
|
||||||
"publish_date": "2018-06-12T00:00:00Z",
|
|
||||||
"view_count": 216221243,
|
"view_count": 216221243,
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"4K",
|
"4K",
|
||||||
|
|
@ -55,9 +54,8 @@
|
||||||
"ultra HD video",
|
"ultra HD video",
|
||||||
"red digital cinema"
|
"red digital cinema"
|
||||||
],
|
],
|
||||||
"category": "Film & Animation",
|
"is_live": false,
|
||||||
"is_live_content": false,
|
"is_live_content": false
|
||||||
"is_family_safe": true
|
|
||||||
},
|
},
|
||||||
"video_streams": [
|
"video_streams": [
|
||||||
{
|
{
|
||||||
|
|
@ -1124,5 +1122,7 @@
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"subtitles": [],
|
"subtitles": [],
|
||||||
"expires_in_seconds": 21540
|
"expires_in_seconds": 21540,
|
||||||
|
"hls_manifest_url": null,
|
||||||
|
"dash_manifest_url": null
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -35,9 +35,8 @@
|
||||||
"publish_date": "2022-07-23T00:00:00Z",
|
"publish_date": "2022-07-23T00:00:00Z",
|
||||||
"view_count": 71877575,
|
"view_count": 71877575,
|
||||||
"keywords": [],
|
"keywords": [],
|
||||||
"category": "Entertainment",
|
"is_live": false,
|
||||||
"is_live_content": false,
|
"is_live_content": false
|
||||||
"is_family_safe": true
|
|
||||||
},
|
},
|
||||||
"video_streams": [
|
"video_streams": [
|
||||||
{
|
{
|
||||||
|
|
@ -1069,5 +1068,7 @@
|
||||||
"auto_generated": false
|
"auto_generated": false
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"expires_in_seconds": 21540
|
"expires_in_seconds": 21540,
|
||||||
|
"hls_manifest_url": null,
|
||||||
|
"dash_manifest_url": null
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Reference in a new issue