Skip to content

Commit

Permalink
Merge pull request #86 from proshunsuke/v3.0.2
Browse files Browse the repository at this point in the history
v3.0.2
  • Loading branch information
proshunsuke authored Dec 26, 2022
2 parents 859b3f3 + 17ccda2 commit 904f8a4
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 18 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
## Packaging

# v3.0.2

https://github.com/proshunsuke/colmsg/pull/86

## Fix bugs

* fixed error when files other than message files exist in the download directory

# v3.0.1

https://github.com/proshunsuke/colmsg/pull/80
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "colmsg"
version = "3.0.1"
version = "3.0.2"
authors = ["proshunsuke <[email protected]>"]
categories = ["command-line-utilities"]
description="Save the messages of '櫻坂46メッセージ', '日向坂46メッセージ' and '乃木坂46メッセージ' apps to the local."
Expand Down
29 changes: 13 additions & 16 deletions src/message/saver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,17 +173,17 @@ impl<'b, C: SHNClient> Saver<'b, C> {
}

fn id_dates(&self, dir_buf: &PathBuf) -> Vec<IdDate> {
WalkDir::new(dir_buf)
.sort_by(move |a, b| {
id_by_filename_format(&a).cmp(&id_by_filename_format(&b))
})
let mut result = WalkDir::new(dir_buf)
.into_iter()
.filter(|r| !r.as_ref().unwrap().path().is_dir())
.map(|r| {
let dir_entry = r.unwrap();
IdDate { id: id_by_filename_format(&dir_entry), date: date_by_filename_format(&dir_entry) }
dir_entry_to_id_date(&dir_entry)
})
.collect::<Vec<_>>()
.flatten()
.collect::<Vec<_>>();
result.sort_by(|a, b| a.id.cmp(&b.id));
result
}

fn latest_date(&self, id_dates: &Vec<IdDate>) -> Result<String> {
Expand Down Expand Up @@ -214,14 +214,11 @@ struct IdDate {
date: String,
}

fn id_by_filename_format(filename: &DirEntry) -> u32 {
let re = Regex::new(r"(?x)(?P<id>\d+)_*").unwrap();
let caps = &re.captures(filename.file_name().to_str().unwrap()).unwrap();
caps["id"].parse::<u32>().unwrap()
}

fn date_by_filename_format(filename: &DirEntry) -> String {
let re = Regex::new(r"(?x)\d+_\d_(?P<date>\d+)").unwrap();
let caps = &re.captures(filename.file_name().to_str().unwrap()).unwrap();
caps["date"].to_string()
fn dir_entry_to_id_date(filename: &DirEntry) -> Option<IdDate> {
let re = Regex::new(r"(?x)(?P<id>\d+)_\d_(?P<date>\d+)").unwrap();
re.captures(filename.file_name().to_str().unwrap())
.and_then(|cap|Some(IdDate {
id: cap["id"].parse::<u32>().unwrap(),
date: cap["date"].to_string()
}))
}

0 comments on commit 904f8a4

Please sign in to comment.