diff options
-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 +} |