Skip to content

Commit

Permalink
fix(core): infer season
Browse files Browse the repository at this point in the history
  • Loading branch information
yjl9903 committed Jun 11, 2024
1 parent f37e86b commit 8b68917
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
7 changes: 6 additions & 1 deletion packages/animegarden/src/task/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export async function generateDownloadTask(
}),
naming: 'auto',
fansub: fansub,
season: info.parsed.season ? +info.parsed.season : undefined,
episode: info.parsed.episode.number, // Raw episode number
source: {
type: 'AnimeGarden',
Expand All @@ -81,7 +82,11 @@ export async function generateDownloadTask(
}
}

videos.sort((lhs, rhs) => lhs.video.episode! - rhs.video.episode!);
videos.sort((lhs, rhs) => {
const ds = (lhs.video.season ?? 1) - (rhs.video.season ?? 1);
if (ds !== 0) return ds;
return lhs.video.episode! - rhs.video.episode!;
});

return videos;
}
Expand Down
4 changes: 2 additions & 2 deletions packages/animegarden/src/task/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,15 @@ export async function runDownloadTask(

// First resolve episode number
const resolvedEpisode = anime.resolveEpisode(task.video.episode, task.video.fansub);
const resolvedSeason = anime.resolveSeason(task.video.season);
const resolvedSeason = anime.resolveSeason(task.video.type, task.video.season);
const library = (await anime.library()).videos;

// Find old video to be removed
const oldVideo = library.find(
(v) =>
v.source.type === ANIMEGARDEN &&
anime.resolveEpisode(v.episode, v.fansub) === resolvedEpisode &&
(anime.resolveSeason(v.season) ?? 1) === (resolvedSeason ?? 1) // Find same episode after being resolved
(anime.resolveSeason(v.type, v.season) ?? 1) === (resolvedSeason ?? 1) // Find same episode after being resolved
);

// Upload progress bar
Expand Down

0 comments on commit 8b68917

Please sign in to comment.