Check-in [7b3a146fb3]
Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | More efficiently encoding audio - handlers can send us an audio-only URL (and extension) now. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
7b3a146fb31df9eff6d22351776adb0e |
User & Date: | Cthulhux 2020-11-08 19:16:09 |
Context
2020-11-08
| ||
19:21 | Updated the README to reflect the new audio download. check-in: 329e1abb8c user: Cthulhux tags: trunk | |
19:16 | More efficiently encoding audio - handlers can send us an audio-only URL (and extension) now. check-in: 7b3a146fb3 user: Cthulhux tags: trunk | |
18:01 | Fixed link check-in: ee258c7577 user: Cthulhux tags: trunk | |
Changes
Changes to README.md.
︙ | ︙ | |||
88 89 90 91 92 93 94 | } fn find_video_title<'a>(&'a self, url: &'a str) -> Result<String> { // Return the video title from <url> here. Ok("".to_string()) } | | | | | | 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 | } fn find_video_title<'a>(&'a self, url: &'a str) -> Result<String> { // Return the video title from <url> here. Ok("".to_string()) } fn find_video_direct_url<'a>(&'a self, url: &'a str, onlyaudio: bool) -> Result<String> { // Return the direct download URL of the video (or its audio version) here. Ok("".to_string()) } fn find_video_file_extension<'a>(&'a self, url: &'a str, onlyaudio: bool) -> Result<String> { // Return the designated file extension of the video (or audio) file here. Ok("mp4".to_string()) } fn display_name<'a>(&'a self) -> String { // For cosmetics, this is the display name of this handler. "NoopExample" } |
︙ | ︙ |
Changes to src/definitions.rs.
︙ | ︙ | |||
26 27 28 29 30 31 32 | // true, if the video exists. fn does_video_exist<'a>(&'a self, url: &'a str) -> Result<bool>; // returns the title of a video. fn find_video_title<'a>(&'a self, url: &'a str) -> Result<String>; // returns the download URL of a video. | | | | 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | // true, if the video exists. fn does_video_exist<'a>(&'a self, url: &'a str) -> Result<bool>; // returns the title of a video. fn find_video_title<'a>(&'a self, url: &'a str) -> Result<String>; // returns the download URL of a video. fn find_video_direct_url<'a>(&'a self, url: &'a str, onlyaudio: bool) -> Result<String>; // returns the file extension of the video (e.g. "mp4"). fn find_video_file_extension<'a>(&'a self, url: &'a str, onlyaudio: bool) -> Result<String>; // returns the name of the site (e.g. "YouTube"). fn display_name<'a>(&'a self) -> String; } |
Changes to src/handlers/youtube.rs.
︙ | ︙ | |||
64 65 66 67 68 69 70 | let video_info = get_video_info(id)?; let video_info_title = video_info["videoDetails"]["title"].as_str().unwrap_or(""); Ok(String::from(video_info_title)) } } | | | 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 | let video_info = get_video_info(id)?; let video_info_title = video_info["videoDetails"]["title"].as_str().unwrap_or(""); Ok(String::from(video_info_title)) } } fn find_video_direct_url<'a>(&'a self, url: &'a str, onlyaudio: bool) -> Result<String> { let id_regex = Regex::new(r"(?:v=|.be/)(.*$)").unwrap(); let id = id_regex.captures(url).unwrap().get(1).unwrap().as_str(); unsafe { let video_info = get_video_info(id)?; let video_info_itags = match video_info["streamingData"]["formats"].as_array() { None => return Ok("".to_string()), Some(itags) => itags, |
︙ | ︙ | |||
118 119 120 121 122 123 124 | && (this_vq == vq3 || this_vq == vq4 || this_vq == vq5 || this_vq == vq6)) || (last_vq == vq3 && (this_vq == vq4 || this_vq == vq5 || this_vq == vq6)) || (last_vq == vq4 && (this_vq == vq5 || this_vq == vq6)) || (last_vq == vq5 && this_vq == vq6); let is_same_or_better_video = (last_vq == this_vq) || is_better_video; let is_better_quality = is_better_audio && is_same_or_better_video | | | | | 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 | && (this_vq == vq3 || this_vq == vq4 || this_vq == vq5 || this_vq == vq6)) || (last_vq == vq3 && (this_vq == vq4 || this_vq == vq5 || this_vq == vq6)) || (last_vq == vq4 && (this_vq == vq5 || this_vq == vq6)) || (last_vq == vq5 && this_vq == vq6); let is_same_or_better_video = (last_vq == this_vq) || is_better_video; let is_better_quality = is_better_audio && is_same_or_better_video || (onlyaudio || is_better_video) && is_same_or_better_audio; if (!onlyaudio || itag["mimeType"].to_string().contains("video/")) && (!onlyaudio || itag["quality"] != json!(null)) && itag["audioQuality"] != json!(null) && (last_vq == "" || last_aq == "" || is_better_quality) { VIDEO_MIME = itag["mimeType"].to_string(); url_to_choose = itag["url"].as_str().unwrap(); last_vq = String::from(this_vq); last_aq = String::from(this_aq); |
︙ | ︙ | |||
156 157 158 159 160 161 162 | } } fn display_name<'a>(&'a self) -> String { "YouTube".to_string() } | | | > > > | 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 | } } fn display_name<'a>(&'a self) -> String { "YouTube".to_string() } fn find_video_file_extension<'a>(&'a self, _url: &'a str, _onlyaudio: bool) -> Result<String> { // By this point, we have already filled VIDEO_MIME. Let's just use that. unsafe { let mut ext = "mp4"; if VIDEO_MIME.contains("/webm") { ext = "webm"; } else if VIDEO_MIME.contains("audio/mp4") { ext = "m4a"; } Ok(ext.to_string()) } } } // Push the site definition to the list of known handlers: inventory::submit! { &YouTubeHandler as &dyn SiteDefinition } |
Changes to src/main.rs.
︙ | ︙ | |||
162 163 164 165 166 167 168 | if vt.is_empty() { println!("The video title could not be extracted. Invalid link?"); } else { if args.is_present("verbose") { println!("Title: {}", vt); } | > | > | > > > > > > | | | 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 | if vt.is_empty() { println!("The video title could not be extracted. Invalid link?"); } else { if args.is_present("verbose") { println!("Title: {}", vt); } let ext = handler.find_video_file_extension(in_url, args.is_present("onlyaudio"))?; let url = handler.find_video_direct_url(in_url, args.is_present("onlyaudio"))?; // Now let's download it: let mut targetfile = format!( "{}.{}", vt.replace(&['\"', ':', '\'', '\\', '/'][..], "-"), ext ); if let Some(in_targetfile) = args.value_of("outputfile") { targetfile = in_targetfile.to_string(); } if args.is_present("verbose") { println!("Starting the download."); } download(&url, &targetfile)?; // Convert the file if needed. let mut outputext = "mp3"; if let Some(in_outputext) = args.value_of("audioformat") { outputext = &in_outputext; } if args.is_present("onlyaudio") && ext != outputext { if args.is_present("verbose") { println!("Post-processing."); } // Convert the file if needed. let mut outputext = "mp3"; if let Some(in_outputext) = args.value_of("audioformat") { outputext = &in_outputext; } let inpath = Path::new(&targetfile); let mut outpathbuf = PathBuf::from(&targetfile); |
︙ | ︙ |