fix: reworked retry system

This commit is contained in:
ThetaDev 2023-05-12 17:19:56 +02:00
parent d128ca4214
commit a2bbc850a7
17 changed files with 273 additions and 121 deletions

View file

@ -2,6 +2,7 @@ use serde::Deserialize;
use serde_with::{rust::deserialize_ignore_any, serde_as, DefaultOnError, VecSkipError};
use crate::{
error::ExtractionError,
model::{
self, traits::FromYtItem, AlbumId, AlbumItem, AlbumType, ArtistId, ArtistItem, ChannelId,
MusicItem, MusicItemType, MusicPlaylistItem, TrackItem,
@ -428,6 +429,8 @@ pub(crate) struct MusicListMapper {
artist_page: bool,
items: Vec<MusicItem>,
warnings: Vec<String>,
/// True if unknown items were mapped
has_unknown: bool,
}
#[derive(Debug)]
@ -447,6 +450,7 @@ impl MusicListMapper {
artist_page: false,
items: Vec::new(),
warnings: Vec::new(),
has_unknown: false,
}
}
@ -459,6 +463,7 @@ impl MusicListMapper {
artist_page: true,
items: Vec::new(),
warnings: Vec::new(),
has_unknown: false,
}
}
@ -471,6 +476,7 @@ impl MusicListMapper {
artist_page: false,
items: Vec::new(),
warnings: Vec::new(),
has_unknown: false,
}
}
@ -759,6 +765,10 @@ impl MusicListMapper {
}
// Tracks were already handled above
MusicPageType::Track { .. } => unreachable!(),
MusicPageType::Unknown => {
self.has_unknown = true;
Ok(None)
}
}
}
None => {
@ -893,6 +903,10 @@ impl MusicListMapper {
Ok(Some(MusicItemType::Playlist))
}
MusicPageType::None => Ok(None),
MusicPageType::Unknown => {
self.has_unknown = true;
Ok(None)
}
},
None => Err("could not determine item type".to_owned()),
}
@ -1028,6 +1042,10 @@ impl MusicListMapper {
Some(MusicItemType::Playlist)
}
MusicPageType::None => None,
MusicPageType::Unknown => {
self.has_unknown = true;
None
}
},
None => {
self.warnings
@ -1102,6 +1120,13 @@ impl MusicListMapper {
warnings: self.warnings,
}
}
pub fn check_unknown(&self) -> Result<(), ExtractionError> {
match self.has_unknown {
true => Err(ExtractionError::InvalidData("unknown YTM items".into())),
false => Ok(()),
}
}
}
/// Map TextComponents containing artist names to a list of artists and a 'Various Artists' flag

View file

@ -160,15 +160,18 @@ pub(crate) enum PageType {
Channel,
#[serde(rename = "MUSIC_PAGE_TYPE_PLAYLIST", alias = "WEB_PAGE_TYPE_PLAYLIST")]
Playlist,
#[serde(rename = "MUSIC_PAGE_TYPE_UNKNOWN")]
Unknown,
}
impl PageType {
pub(crate) fn to_url_target(self, id: String) -> UrlTarget {
pub(crate) fn to_url_target(self, id: String) -> Option<UrlTarget> {
match self {
PageType::Artist => UrlTarget::Channel { id },
PageType::Album => UrlTarget::Album { id },
PageType::Channel => UrlTarget::Channel { id },
PageType::Playlist => UrlTarget::Playlist { id },
PageType::Artist => Some(UrlTarget::Channel { id }),
PageType::Album => Some(UrlTarget::Album { id }),
PageType::Channel => Some(UrlTarget::Channel { id }),
PageType::Playlist => Some(UrlTarget::Playlist { id }),
PageType::Unknown => None,
}
}
}
@ -179,6 +182,7 @@ pub(crate) enum MusicPageType {
Album,
Playlist,
Track { is_video: bool },
Unknown,
None,
}
@ -189,6 +193,7 @@ impl From<PageType> for MusicPageType {
PageType::Album => MusicPageType::Album,
PageType::Playlist => MusicPageType::Playlist,
PageType::Channel => MusicPageType::None,
PageType::Unknown => MusicPageType::Unknown,
}
}
}