Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 修复章节重名导致的下载错误问题 #41

Merged
merged 1 commit into from
Nov 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src-tauri/src/types/comic.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::collections::HashMap;

use crate::config::Config;
use crate::responses::{ComicRespData, EpisodeRespData};
use crate::types::AlbumPlus;
Expand Down Expand Up @@ -153,6 +155,8 @@ pub struct Comic {
pub album_plus: AlbumPlus,
}
impl Comic {
#[allow(clippy::too_many_lines)]
// TODO: 统一用from实现,以减少代码行数
pub fn from(app: &AppHandle, comic: ComicRespData, album_plus: AlbumPlus) -> Self {
let comic_title = filename_filter(&comic.title);
let mut episode_infos: Vec<EpisodeInfo> = comic
Expand Down Expand Up @@ -198,6 +202,27 @@ impl Comic {
Some(episode_info)
})
.collect();
// 解决章节标题重复的问题
let mut ep_title_count = HashMap::new();
// 统计章节标题出现的次数
for ep in &episode_infos {
let Some(count) = ep_title_count.get_mut(&ep.episode_title) else {
ep_title_count.insert(ep.episode_title.clone(), 1);
continue;
};
*count += 1;
}
// 只保留重复的章节标题
ep_title_count.retain(|_, v| *v > 1);
// 为重复的章节标题添加序号
for ep in &mut episode_infos {
let Some(count) = ep_title_count.get_mut(&ep.episode_title) else {
continue;
};
ep.episode_title = format!("{}-{}", ep.episode_title, count);
*count -= 1;
}

episode_infos.reverse();

let styles2 = comic
Expand Down