Improve genre parsing

Fix game list sorting
This commit is contained in:
2025-12-14 22:42:31 +08:00
parent 12e8bd2b92
commit 111de9a8b0
4 changed files with 52 additions and 38 deletions

View File

@@ -6,10 +6,9 @@ use crossterm::style::{style, Stylize};
use futures::StreamExt;
use indicatif::{ProgressBar, ProgressStyle};
use itertools::Itertools;
use tokio::sync::Mutex;
use tokio::time::Instant;
use crawler::DLSiteCrawler;
use db::{RocksDBFactory};
use db::RocksDBFactory;
use models::config::ApplicationConfig;
use models::dlsite::{DLSiteCategory, DLSiteGenre, DLSiteManiax, DLSiteTranslation};
use crate::helpers;
@@ -48,7 +47,10 @@ impl DLSiteSyncCommand {
pub async fn handle(&self) -> Result<()> {
let now = Instant::now();
let app_conf = ApplicationConfig::get_config()?;
let db_factory = RocksDBFactory::default();
let mut db_factory = RocksDBFactory::default();
db_factory.register::<DLSiteManiax>();
db_factory.register::<DLSiteGenre>();
db_factory.register::<DLSiteCategory>();
let crawler = DLSiteCrawler::new()?;
if self.do_sync_genre {
let genre_now = Instant::now();
@@ -125,9 +127,10 @@ impl DLSiteSyncCommand {
let progress = ProgressBar::new(game_infos.len() as u64)
.with_style(ProgressStyle::default_bar());
let shared_progress = Mutex::new(progress);
while let Some(info) = game_infos.next().await {
let maniax = info?;
let Some(maniax) = info? else {
continue;
};
let existing_maniax = existing_game_infos.iter()
.find(|v| v.rj_num == maniax.rj_num);
if let Some(existing_maniax) = existing_maniax {
@@ -145,7 +148,6 @@ impl DLSiteSyncCommand {
value.folder_path = maniax_folder;
modified_maniaxes.push(value);
}
let progress = shared_progress.lock().await;
progress.inc(1);
}
db.set_values(&modified_maniaxes)?;

View File

@@ -39,7 +39,20 @@ enum Status {
impl MainView {
pub fn new(mut db_factory: RocksDBFactory) -> color_eyre::Result<Self> {
let db = db_factory.get_current_context()?;
let games = db.get_all_values::<DLSiteManiax>()?;
let mut games = db.get_all_values::<DLSiteManiax>()?;
games.sort_by(|a, b| {
let left = a.rj_num
.chars().skip(2)
.collect::<String>()
.parse::<u32>()
.unwrap();
let right = b.rj_num
.chars().skip(2)
.collect::<String>()
.parse::<u32>()
.unwrap();
left.cmp(&right)
});
let dl_game_list = GameList::new(games)?;
let view = Self {
state: MainViewState {