mirror of
https://github.com/crunchy-labs/crunchy-cli.git
synced 2026-01-21 04:02:00 -06:00
Fix duplicated download with archive
This commit is contained in:
parent
618d2206a2
commit
0234d46bf9
2 changed files with 73 additions and 22 deletions
|
|
@ -79,15 +79,15 @@ impl Filter for ArchiveFilter {
|
||||||
let mut remove_ids = vec![];
|
let mut remove_ids = vec![];
|
||||||
for season in seasons.iter_mut() {
|
for season in seasons.iter_mut() {
|
||||||
if !self.url_filter.is_season_valid(season.season_number)
|
if !self.url_filter.is_season_valid(season.season_number)
|
||||||
&& !season
|
|| (!season
|
||||||
.audio_locales
|
.audio_locales
|
||||||
.iter()
|
.iter()
|
||||||
.any(|l| self.archive.audio.contains(l))
|
.any(|l| self.archive.audio.contains(l))
|
||||||
&& !season
|
&& !season
|
||||||
.available_versions()
|
.available_versions()
|
||||||
.await?
|
.await?
|
||||||
.iter()
|
.iter()
|
||||||
.any(|l| self.archive.audio.contains(l))
|
.any(|l| self.archive.audio.contains(l)))
|
||||||
{
|
{
|
||||||
remove_ids.push(season.id.clone());
|
remove_ids.push(season.id.clone());
|
||||||
}
|
}
|
||||||
|
|
@ -172,20 +172,44 @@ impl Filter for ArchiveFilter {
|
||||||
let mut episodes = vec![];
|
let mut episodes = vec![];
|
||||||
for season in seasons {
|
for season in seasons {
|
||||||
self.season_sorting.push(season.id.clone());
|
self.season_sorting.push(season.id.clone());
|
||||||
let season_locale = season
|
let season_locale = if season.audio_locales.len() < 2 {
|
||||||
.audio_locales
|
Some(
|
||||||
.get(0)
|
season
|
||||||
.cloned()
|
.audio_locales
|
||||||
.unwrap_or(Locale::ja_JP);
|
.get(0)
|
||||||
|
.cloned()
|
||||||
|
.unwrap_or(Locale::ja_JP),
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
let mut eps = season.episodes().await?;
|
let mut eps = season.episodes().await?;
|
||||||
let before_len = eps.len();
|
let before_len = eps.len();
|
||||||
eps.retain(|e| e.audio_locale == season_locale);
|
|
||||||
if eps.len() != before_len {
|
for mut ep in eps.clone() {
|
||||||
|
if let Some(l) = &season_locale {
|
||||||
|
if &ep.audio_locale == l {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
eps.remove(eps.iter().position(|p| p.id == ep.id).unwrap());
|
||||||
|
} else {
|
||||||
|
let mut requested_locales = self.archive.audio.clone();
|
||||||
|
if let Some(idx) = requested_locales.iter().position(|p| p == &ep.audio_locale)
|
||||||
|
{
|
||||||
|
requested_locales.remove(idx);
|
||||||
|
} else {
|
||||||
|
eps.remove(eps.iter().position(|p| p.id == ep.id).unwrap());
|
||||||
|
}
|
||||||
|
eps.extend(ep.version(self.archive.audio.clone()).await?);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if eps.len() < before_len {
|
||||||
if eps.len() == 0 {
|
if eps.len() == 0 {
|
||||||
if matches!(self.visited, Visited::Series) {
|
if matches!(self.visited, Visited::Series) {
|
||||||
warn!(
|
warn!(
|
||||||
"Season {} is not available with {} audio",
|
"Season {} is not available with {} audio",
|
||||||
season.season_number, season_locale
|
season.season_number,
|
||||||
|
season_locale.unwrap_or(Locale::ja_JP)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -193,7 +217,7 @@ impl Filter for ArchiveFilter {
|
||||||
warn!(
|
warn!(
|
||||||
"Season {} is only available with {} audio until episode {} ({})",
|
"Season {} is only available with {} audio until episode {} ({})",
|
||||||
season.season_number,
|
season.season_number,
|
||||||
season_locale,
|
season_locale.unwrap_or(Locale::ja_JP),
|
||||||
last_episode.episode_number,
|
last_episode.episode_number,
|
||||||
last_episode.title
|
last_episode.title
|
||||||
)
|
)
|
||||||
|
|
@ -339,24 +363,45 @@ impl Filter for ArchiveFilter {
|
||||||
|
|
||||||
let mut single_format_collection = SingleFormatCollection::new();
|
let mut single_format_collection = SingleFormatCollection::new();
|
||||||
|
|
||||||
let mut pre_sorted: BTreeMap<(String, String), Self::T> = BTreeMap::new();
|
let mut pre_sorted: BTreeMap<String, Self::T> = BTreeMap::new();
|
||||||
for data in flatten_input {
|
for data in flatten_input {
|
||||||
pre_sorted
|
pre_sorted
|
||||||
.entry((data.season_id.clone(), data.sequence_number.to_string()))
|
.entry(data.identifier.clone())
|
||||||
.or_insert(vec![])
|
.or_insert(vec![])
|
||||||
.push(data)
|
.push(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut sorted: Vec<((String, String), Self::T)> = pre_sorted.into_iter().collect();
|
let mut sorted: Vec<(String, Self::T)> = pre_sorted.into_iter().collect();
|
||||||
sorted.sort_by(|((a, _), _), ((b, _), _)| {
|
sorted.sort_by(|(_, a), (_, b)| {
|
||||||
self.season_sorting
|
self.season_sorting
|
||||||
.iter()
|
.iter()
|
||||||
.position(|p| p == a)
|
.position(|p| p == &a.first().unwrap().season_id)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.cmp(&self.season_sorting.iter().position(|p| p == b).unwrap())
|
.cmp(
|
||||||
|
&self
|
||||||
|
.season_sorting
|
||||||
|
.iter()
|
||||||
|
.position(|p| p == &b.first().unwrap().season_id)
|
||||||
|
.unwrap(),
|
||||||
|
)
|
||||||
});
|
});
|
||||||
|
|
||||||
for (_, data) in sorted {
|
for (_, mut data) in sorted {
|
||||||
|
data.sort_by(|a, b| {
|
||||||
|
self.archive
|
||||||
|
.audio
|
||||||
|
.iter()
|
||||||
|
.position(|p| p == &a.audio)
|
||||||
|
.unwrap_or(usize::MAX)
|
||||||
|
.cmp(
|
||||||
|
&self
|
||||||
|
.archive
|
||||||
|
.audio
|
||||||
|
.iter()
|
||||||
|
.position(|p| p == &b.audio)
|
||||||
|
.unwrap_or(usize::MAX),
|
||||||
|
)
|
||||||
|
});
|
||||||
single_format_collection.add_single_formats(data)
|
single_format_collection.add_single_formats(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,8 @@ use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct SingleFormat {
|
pub struct SingleFormat {
|
||||||
|
pub identifier: String,
|
||||||
|
|
||||||
pub title: String,
|
pub title: String,
|
||||||
pub description: String,
|
pub description: String,
|
||||||
|
|
||||||
|
|
@ -42,6 +44,7 @@ impl SingleFormat {
|
||||||
relative_episode_number: Option<u32>,
|
relative_episode_number: Option<u32>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
identifier: episode.identifier.clone(),
|
||||||
title: episode.title.clone(),
|
title: episode.title.clone(),
|
||||||
description: episode.description.clone(),
|
description: episode.description.clone(),
|
||||||
audio: episode.audio_locale.clone(),
|
audio: episode.audio_locale.clone(),
|
||||||
|
|
@ -66,6 +69,7 @@ impl SingleFormat {
|
||||||
|
|
||||||
pub fn new_from_movie(movie: Movie, subtitles: Vec<Locale>) -> Self {
|
pub fn new_from_movie(movie: Movie, subtitles: Vec<Locale>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
identifier: movie.id.clone(),
|
||||||
title: movie.title.clone(),
|
title: movie.title.clone(),
|
||||||
description: movie.description.clone(),
|
description: movie.description.clone(),
|
||||||
audio: Locale::ja_JP,
|
audio: Locale::ja_JP,
|
||||||
|
|
@ -86,6 +90,7 @@ impl SingleFormat {
|
||||||
|
|
||||||
pub fn new_from_music_video(music_video: MusicVideo) -> Self {
|
pub fn new_from_music_video(music_video: MusicVideo) -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
identifier: music_video.id.clone(),
|
||||||
title: music_video.title.clone(),
|
title: music_video.title.clone(),
|
||||||
description: music_video.description.clone(),
|
description: music_video.description.clone(),
|
||||||
audio: Locale::ja_JP,
|
audio: Locale::ja_JP,
|
||||||
|
|
@ -106,6 +111,7 @@ impl SingleFormat {
|
||||||
|
|
||||||
pub fn new_from_concert(concert: Concert) -> Self {
|
pub fn new_from_concert(concert: Concert) -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
identifier: concert.id.clone(),
|
||||||
title: concert.title.clone(),
|
title: concert.title.clone(),
|
||||||
description: concert.description.clone(),
|
description: concert.description.clone(),
|
||||||
audio: Locale::ja_JP,
|
audio: Locale::ja_JP,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue