~aleteoryx/pjsekai_emote_packs

ref: 77e184ef89cd4379069662adfb93c374717ce446 pjsekai_emote_packs/src/main.rs -rw-r--r-- 2.6 KiB
77e184efAleteoryx mostly done 10 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#![feature(iter_intersperse)]
mod en;
mod slug;

use std::collections::HashSet;
use std::fs::{File, self};
use std::path::PathBuf;

use bytes::Bytes;
use reqwest::blocking::Client;

fn get_stamp_asset_png(client: &Client, id: &str) -> Bytes {
  client
    .get(format!("https://storage.sekai.best/sekai-en-assets/stamp/{id}_rip/{id}.png"))
    .send()
    .expect("Couldn't download stamp asset")
    .error_for_status()
    .expect("Couldn't download stamp asset")
    .bytes()
    .expect("Couldn't download stamp asset")
}

fn main() {
  let repo_dir: PathBuf = std::env::var("CARGO_MANIFEST_DIR").unwrap_or_else(|_| ".".to_owned()).into();

  let client = Client::new();

  // English region (global)
  let sekai_en_dir = repo_dir.join("sekai_world/db_en_diff");
  let stamps_en_path = sekai_en_dir.join("stamps.json");
  let stamps_en =
    serde_json::from_reader::<_, Vec<en::RawStamp>>(
      File::open(&stamps_en_path)
        .expect("Couldn't open stamps.json"))
      .expect("stamps.json invalid")
      .into_iter()
      .map(|a| a.to_stamp())
      .collect::<Vec<_>>();

  let cache_dir = repo_dir.join("stamps_cache/en");
  fs::create_dir_all(&cache_dir);

  for stamp in &stamps_en {
    let download_path = cache_dir.join(&stamp.assetbundle_name).with_extension("png");
    if !fs::exists(&download_path).unwrap() {
      println!("Downlading asset {}...", &stamp.assetbundle_name);
      fs::write(&download_path, get_stamp_asset_png(&client, &stamp.assetbundle_name))
        .expect("Couldn't write out stamp cache file");
    }
  }

  let character_stamps =
    stamps_en.clone().into_iter()
      .filter(|a|
        match a.character {
          en::StampCharacter::Solo { .. } | en::StampCharacter::SoloExtra { .. } => true,
          _ => false
       })
       .collect::<Vec<_>>();
  let text_stamps =
    stamps_en.clone().into_iter()
      .filter(|a|
        match a.character {
          en::StampCharacter::Nobody => true,
          _ => false
       })
       .collect::<Vec<_>>();

  for stamp in text_stamps {
    println!("{} => {}", stamp.name, stamp.name.to_ascii_lowercase().replace(" ", "_"));
  }

  let name_stamps =
    stamps_en.clone().into_iter()
      .filter(|a|
        match a.character {
          en::StampCharacter::GCUID { .. } => true,
          _ => false
       })
       .collect::<Vec<_>>();
  let pair_stamps =
    stamps_en.clone().into_iter()
      .filter(|a|
        match a.character {
          en::StampCharacter::Duo { .. } => true,
          _ => false
       })
       .collect::<Vec<_>>();

  slug::SlugPrompter::run("en".into(), &repo_dir, character_stamps);


}