diff options
author | metamuffin <metamuffin@disroot.org> | 2025-02-15 16:24:16 +0100 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2025-02-15 16:24:16 +0100 |
commit | 079fec9f206751047248c8c7733d7eccbd89d94b (patch) | |
tree | 001a99d929439904fb14156694ad3a0a9453c33f | |
parent | 545164925f3d724b9313f8e871dbb444fc016168 (diff) | |
download | jellything-079fec9f206751047248c8c7733d7eccbd89d94b.tar jellything-079fec9f206751047248c8c7733d7eccbd89d94b.tar.bz2 jellything-079fec9f206751047248c8c7733d7eccbd89d94b.tar.zst |
clean uploader name in subtitles
-rw-r--r-- | import/src/lib.rs | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/import/src/lib.rs b/import/src/lib.rs index f97e70f..32f861e 100644 --- a/import/src/lib.rs +++ b/import/src/lib.rs @@ -240,11 +240,7 @@ fn import_file( let data = serde_json::from_reader::<_, YVideo>(BufReader::new(File::open(path)?))?; db.update_node_init(parent, |node| { node.kind = NodeKind::Channel; - let mut title = data.title.as_str(); - title = title.strip_suffix(" - Videos").unwrap_or(title); - title = title.strip_suffix(" - Topic").unwrap_or(title); - title = title.strip_prefix("Uploads from ").unwrap_or(title); - node.title = Some(title.to_owned()); + node.title = Some(clean_uploader_name(&data.title).to_owned()); if let Some(cid) = data.channel_id { node.external_ids.insert("youtube:channel".to_string(), cid); } @@ -410,7 +406,10 @@ fn import_media_file( NodeKind::Video }; node.title = Some(infojson.title); - node.subtitle = infojson.uploader; + node.subtitle = infojson + .uploader + .as_ref() + .map(|u| clean_uploader_name(u).to_owned()); if let Some(desc) = infojson.description { node.description = Some(desc) } @@ -696,3 +695,10 @@ fn make_kebab(i: &str) -> String { } o } + +fn clean_uploader_name(mut s: &str) -> &str { + s = s.strip_suffix(" - Videos").unwrap_or(s); + s = s.strip_suffix(" - Topic").unwrap_or(s); + s = s.strip_prefix("Uploads from ").unwrap_or(s); + s +} |