diff --git a/Cargo.toml b/Cargo.toml index 33b36df..d5c04df 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "downloader" -version = "0.3.1" +version = "0.3.2" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/src/lib.rs b/src/lib.rs index bbd42dc..f6f7d21 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -6,6 +6,7 @@ use std::future::Future; use std::io::stdin; use std::path::{Path, PathBuf}; use std::process::Stdio; +use std::str::Chars; use anyhow::{anyhow, Context, Result}; use chrono::{Datelike, Duration}; @@ -782,14 +783,16 @@ pub fn get_playlist_title_from_twitch_video(video: &data::VideoData) -> Result>(title: S) -> Result { let title = title.into(); - if title.len() > MAX_VIDEO_TITLE_LENGTH - PREFIX_LENGTH - SEPARATOR_LEN { - let shortened = format!( - "{}...", - &title[0..MAX_VIDEO_TITLE_LENGTH - PREFIX_LENGTH - SEPARATOR_LEN - 3] - ); - return Ok(shortened); + let mut chars = title.chars(); + if chars.clone().count() > MAX_VIDEO_TITLE_LENGTH - PREFIX_LENGTH - SEPARATOR_LEN { + let shortened_chars = + chars.take(MAX_VIDEO_TITLE_LENGTH - PREFIX_LENGTH - SEPARATOR_LEN - DOTDOTDOT_LEN); + let shortened_chars: String = shortened_chars.collect(); + let shortened = format!("{}...", shortened_chars); + Ok(shortened) + } else { + Ok(title) } - Ok(title.to_string()) } pub fn get_video_prefix_from_twitch_video(