Fix cms rate limiting error for episodes and movies (#180)

This commit is contained in:
bytedream 2023-04-13 19:17:55 +02:00 committed by ByteDream
parent c4c15f9b11
commit bfc50653b1
4 changed files with 25 additions and 10 deletions

View file

@ -5,7 +5,7 @@ use anyhow::Result;
use chrono::Duration;
use crunchyroll_rs::media::{Resolution, Stream, Subtitle, VariantData};
use crunchyroll_rs::{Concert, Episode, Locale, MediaCollection, Movie, MusicVideo};
use log::{debug, info};
use log::{debug, info, warn};
use std::cmp::Ordering;
use std::collections::BTreeMap;
use std::path::{Path, PathBuf};
@ -126,8 +126,24 @@ impl SingleFormat {
pub async fn stream(&self) -> Result<Stream> {
let stream = match &self.source {
MediaCollection::Episode(e) => e.streams().await?,
MediaCollection::Movie(m) => m.streams().await?,
MediaCollection::Episode(e) => {
if let Ok(stream) = e.legacy_streams().await {
stream
} else {
let stream = e.streams().await?;
warn!("Failed to get stream via legacy endpoint");
stream
}
}
MediaCollection::Movie(m) => {
if let Ok(stream) = m.legacy_streams().await {
stream
} else {
let stream = m.streams().await?;
warn!("Failed to get stream via legacy endpoint");
stream
}
}
MediaCollection::MusicVideo(mv) => mv.streams().await?,
MediaCollection::Concert(c) => c.streams().await?,
_ => unreachable!(),