refactor: remove microformat parsing for player

This commit is contained in:
ThetaDev 2022-10-10 21:58:35 +02:00
parent ab61cfb4ca
commit 6ee24081da
10 changed files with 22 additions and 108 deletions

View file

@ -3,7 +3,6 @@ use std::{
collections::{BTreeMap, HashMap},
};
use chrono::{Local, NaiveDateTime, NaiveTime, TimeZone};
use fancy_regex::Regex;
use once_cell::sync::Lazy;
use serde::Serialize;
@ -157,21 +156,6 @@ impl MapResponse<VideoPlayer> for response::Player {
self.video_details,
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 {
return Err(ExtractionError::WrongResult(format!(
@ -190,15 +174,10 @@ impl MapResponse<VideoPlayer> for response::Player {
id: video_details.channel_id,
name: video_details.author,
},
publish_date,
view_count: video_details.view_count,
keywords: match video_details.keywords {
Some(keywords) => keywords,
None => tags.unwrap_or_default(),
},
category,
keywords: video_details.keywords,
is_live,
is_live_content: video_details.is_live_content,
is_family_safe,
};
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.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 {
let video = player_data
.video_only_streams

View file

@ -1,6 +1,5 @@
use std::ops::Range;
use chrono::NaiveDate;
use serde::Deserialize;
use serde_with::serde_as;
use serde_with::{json::JsonString, DefaultOnError};
@ -15,7 +14,6 @@ pub struct Player {
pub streaming_data: Option<StreamingData>,
pub captions: Option<Captions>,
pub video_details: Option<VideoDetails>,
pub microformat: Option<Microformat>,
}
#[derive(Debug, Deserialize)]
@ -204,7 +202,8 @@ pub struct VideoDetails {
pub title: String,
#[serde_as(as = "JsonString")]
pub length_seconds: u32,
pub keywords: Option<Vec<String>>,
#[serde(default)]
pub keywords: Vec<String>,
pub channel_id: String,
pub short_description: Option<String>,
#[serde(default)]
@ -214,22 +213,3 @@ pub struct VideoDetails {
pub author: String,
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>>,
}

View file

@ -34,7 +34,6 @@ VideoPlayer(
id: "UCbxxEi-ImPlbLx5F-fHetEg",
name: "RomanSenykMusic - Royalty Free Music",
),
publish_date: "~",
view_count: 426567,
keywords: [
"no copyright music",
@ -59,9 +58,8 @@ VideoPlayer(
"motivational music",
"montage music",
],
category: None,
is_live: false,
is_live_content: false,
is_family_safe: None,
),
video_streams: [
VideoStream(

View file

@ -39,7 +39,6 @@ VideoPlayer(
id: "UCbxxEi-ImPlbLx5F-fHetEg",
name: "RomanSenykMusic - Royalty Free Music",
),
publish_date: "2019-05-30T00:00:00",
view_count: 426567,
keywords: [
"no copyright music",
@ -64,9 +63,8 @@ VideoPlayer(
"motivational music",
"montage music",
],
category: Some("Music"),
is_live: false,
is_live_content: false,
is_family_safe: Some(true),
),
video_streams: [
VideoStream(

View file

@ -29,34 +29,10 @@ VideoPlayer(
id: "UCbxxEi-ImPlbLx5F-fHetEg",
name: "Romansenykmusic",
),
publish_date: "2019-05-30T00:00:00",
view_count: 426583,
keywords: [
"no copyright music",
"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"),
keywords: [],
is_live: false,
is_live_content: false,
is_family_safe: Some(true),
),
video_streams: [
VideoStream(

View file

@ -29,7 +29,6 @@ VideoPlayer(
id: "UCbxxEi-ImPlbLx5F-fHetEg",
name: "RomanSenykMusic - Royalty Free Music",
),
publish_date: "~",
view_count: 426567,
keywords: [
"no copyright music",
@ -54,9 +53,8 @@ VideoPlayer(
"motivational music",
"montage music",
],
category: None,
is_live: false,
is_live_content: false,
is_family_safe: None,
),
video_streams: [],
video_only_streams: [

View file

@ -39,7 +39,6 @@ VideoPlayer(
id: "UCbxxEi-ImPlbLx5F-fHetEg",
name: "RomanSenykMusic - Royalty Free Music",
),
publish_date: "~",
view_count: 426567,
keywords: [
"no copyright music",
@ -64,9 +63,8 @@ VideoPlayer(
"motivational music",
"montage music",
],
category: None,
is_live: false,
is_live_content: false,
is_family_safe: None,
),
video_streams: [
VideoStream(

View file

@ -71,17 +71,14 @@ pub struct VideoPlayerDetails {
pub thumbnail: Vec<Thumbnail>,
/// Channel of the video
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.
pub view_count: u64,
/// List of words that describe the topic of the video
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
pub is_live_content: bool,
/// True if the video is not age-restricted
pub is_family_safe: Option<bool>,
}
/// Video stream

View file

@ -32,7 +32,6 @@
}
],
"channel": { "id": "UCYq-iAOSZBvoUxvfzwKIZWA", "name": "Jacob + Katie Schwarz" },
"publish_date": "2018-06-12T00:00:00Z",
"view_count": 216221243,
"keywords": [
"4K",
@ -55,9 +54,8 @@
"ultra HD video",
"red digital cinema"
],
"category": "Film & Animation",
"is_live_content": false,
"is_family_safe": true
"is_live": false,
"is_live_content": false
},
"video_streams": [
{
@ -1124,5 +1122,7 @@
}
],
"subtitles": [],
"expires_in_seconds": 21540
"expires_in_seconds": 21540,
"hls_manifest_url": null,
"dash_manifest_url": null
}

View file

@ -35,9 +35,8 @@
"publish_date": "2022-07-23T00:00:00Z",
"view_count": 71877575,
"keywords": [],
"category": "Entertainment",
"is_live_content": false,
"is_family_safe": true
"is_live": false,
"is_live_content": false
},
"video_streams": [
{
@ -1069,5 +1068,7 @@
"auto_generated": false
}
],
"expires_in_seconds": 21540
"expires_in_seconds": 21540,
"hls_manifest_url": null,
"dash_manifest_url": null
}