fix: A/B test 16 (pageHeaderRenderer on playlist pages)
This commit is contained in:
parent
f3f2e1d3ca
commit
e65f14556f
17 changed files with 6435 additions and 182 deletions
75
codegen/src/collect_chan_prefixes.rs
Normal file
75
codegen/src/collect_chan_prefixes.rs
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
use std::{collections::BTreeMap, fs::File, io::BufReader};
|
||||
|
||||
use path_macro::path;
|
||||
use rustypipe::{
|
||||
client::RustyPipe,
|
||||
param::{Language, LANGUAGES},
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::util::{self, DICT_DIR};
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
struct Entry {
|
||||
prefix: String,
|
||||
suffix: String,
|
||||
}
|
||||
|
||||
pub async fn collect_chan_prefixes() {
|
||||
let cname = "kiernanchrisman";
|
||||
let json_path = path!(*DICT_DIR / "chan_prefixes.json");
|
||||
let mut res = BTreeMap::new();
|
||||
|
||||
let rp = RustyPipe::new();
|
||||
|
||||
for lang in LANGUAGES {
|
||||
let playlist = rp
|
||||
.query()
|
||||
.lang(lang)
|
||||
.playlist("PLZN_exA7d4RVmCQrG5VlWIjMOkMFZVVOc")
|
||||
.await
|
||||
.unwrap();
|
||||
let n = playlist.channel.unwrap().name;
|
||||
let offset = n.find(cname).unwrap();
|
||||
let prefix = &n[..offset];
|
||||
let suffix = &n[(offset + cname.len())..];
|
||||
|
||||
res.insert(
|
||||
lang,
|
||||
Entry {
|
||||
prefix: prefix.to_owned(),
|
||||
suffix: suffix.to_owned(),
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
let file = File::create(json_path).unwrap();
|
||||
serde_json::to_writer_pretty(file, &res).unwrap();
|
||||
}
|
||||
|
||||
pub fn write_samples_to_dict() {
|
||||
let json_path = path!(*DICT_DIR / "chan_prefixes.json");
|
||||
|
||||
let json_file = File::open(json_path).unwrap();
|
||||
let collected: BTreeMap<Language, Entry> =
|
||||
serde_json::from_reader(BufReader::new(json_file)).unwrap();
|
||||
let mut dict = util::read_dict();
|
||||
let langs = dict.keys().copied().collect::<Vec<_>>();
|
||||
|
||||
for lang in langs {
|
||||
let dict_entry = dict.entry(lang).or_default();
|
||||
|
||||
let e = collected.get(&lang).unwrap();
|
||||
dict_entry.chan_prefix = e.prefix.trim().to_owned();
|
||||
dict_entry.chan_suffix = e.suffix.trim().to_owned();
|
||||
|
||||
for lang in &dict_entry.equivalent {
|
||||
let ee = collected.get(lang).unwrap();
|
||||
if ee.prefix != e.prefix || ee.suffix != e.suffix {
|
||||
panic!("equivalent lang conflict, lang: {lang}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
util::write_dict(dict);
|
||||
}
|
||||
Reference in a new issue