Skip to content

Commit fc87bc1

Browse files
committed
clippy fixes vsd
1 parent 9a0ec57 commit fc87bc1

11 files changed

Lines changed: 45 additions & 68 deletions

File tree

vsd/src/automation.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,11 @@ impl SelectOptions {
107107
let _ = auto.video.resolutions.insert((7680, 4320));
108108
}
109109
x => {
110-
if let Some((w, h)) = x.split_once('x') {
111-
if let (Ok(w), Ok(h)) = (w.parse::<u16>(), h.parse::<u16>())
110+
if let Some((w, h)) = x.split_once('x')
111+
&& let (Ok(w), Ok(h)) = (w.parse::<u16>(), h.parse::<u16>())
112112
{
113113
auto.video.resolutions.insert((w, h));
114114
}
115-
}
116115
}
117116
}
118117
}

vsd/src/commands/capture.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -161,11 +161,10 @@ impl Capture {
161161
if self.save_cookies {
162162
println!("{} session cookies", "Downloading".colorize("bold green"));
163163

164-
if let Some(directory) = &self.directory {
165-
if !directory.exists() {
164+
if let Some(directory) = &self.directory
165+
&& !directory.exists() {
166166
fs::create_dir_all(directory).unwrap();
167-
}
168-
};
167+
};
169168

170169
let mut path = PathBuf::from("cookies.json");
171170

@@ -199,11 +198,10 @@ fn handler(
199198
);
200199

201200
if let Ok(body) = get_response_body() {
202-
if let Some(directory) = directory {
203-
if !directory.exists() {
201+
if let Some(directory) = directory
202+
&& !directory.exists() {
204203
fs::create_dir_all(directory).unwrap();
205-
}
206-
};
204+
};
207205

208206
let mut path = PathBuf::from(
209207
params

vsd/src/dash/playlist.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,14 @@ pub(crate) fn parse_as_master(mpd: &MPD, uri: &str) -> MasterPlaylist {
4949
MediaType::Undefined
5050
};
5151

52-
if media_type == MediaType::Undefined {
53-
if let Some(codecs) = &codecs {
52+
if media_type == MediaType::Undefined
53+
&& let Some(codecs) = &codecs {
5454
media_type = match codecs.as_str() {
5555
"wvtt" | "stpp" => MediaType::Subtitles,
5656
x if x.starts_with("stpp.") => MediaType::Subtitles,
5757
_ => media_type,
5858
};
5959
}
60-
}
6160

6261
streams.push(MediaPlaylist {
6362
bandwidth: representation.bandwidth,

vsd/src/dash/template.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,13 @@ impl Template {
4343
] {
4444
let ident = format!("${var}$");
4545

46-
if template.contains(&ident) {
47-
if let Some(value) = self.vars.get(var) {
46+
if template.contains(&ident)
47+
&& let Some(value) = self.vars.get(var) {
4848
template = template.replace(&ident, value);
4949
}
50-
}
5150

52-
if let Some(cap) = ident_re.captures(&template) {
53-
if let Some(value) = self.vars.get(var) {
51+
if let Some(cap) = ident_re.captures(&template)
52+
&& let Some(value) = self.vars.get(var) {
5453
let count = format!(
5554
"{:0>width$}",
5655
value,
@@ -59,7 +58,6 @@ impl Template {
5958
let m = ident_re.find(&template).unwrap();
6059
template = template[..m.start()].to_owned() + &count + &template[m.end()..];
6160
}
62-
}
6361
}
6462

6563
template

vsd/src/downloader/encryption.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,13 @@ pub fn check_key_exists_for_kid(
106106

107107
pub fn check_unsupported_encryptions(streams: &Vec<MediaPlaylist>) -> Result<()> {
108108
for stream in streams {
109-
if let Some(Segment { key: Some(x), .. }) = stream.segments.first() {
110-
if let KeyMethod::Other(x) = &x.method {
109+
if let Some(Segment { key: Some(x), .. }) = stream.segments.first()
110+
&& let KeyMethod::Other(x) = &x.method {
111111
bail!(
112112
"{} decryption is not supported. Use --no-decrypt flag to download encrypted streams.",
113113
x,
114114
);
115115
}
116-
}
117116
}
118117

119118
Ok(())

vsd/src/downloader/fetch.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,11 +191,10 @@ fn scrape_playlist_links(text: &str) -> Vec<String> {
191191
links
192192
.into_iter()
193193
.map(|x| {
194-
if x.starts_with("http") {
195-
if let Some(y) = x.split("http").last() {
194+
if x.starts_with("http")
195+
&& let Some(y) = x.split("http").last() {
196196
return format!("http{y}");
197197
}
198-
}
199198
x
200199
})
201200
.collect()

vsd/src/downloader/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,10 @@ pub fn download(
4545
encryption::check_key_exists_for_kid(&decrypter, &default_kids)?;
4646
}
4747

48-
if let Some(directory) = &directory {
49-
if !directory.exists() {
48+
if let Some(directory) = &directory
49+
&& !directory.exists() {
5050
fs::create_dir_all(directory)?;
5151
}
52-
}
5352

5453
for stream in &mut streams {
5554
if stream.media_type != MediaType::Subtitles {

vsd/src/downloader/mux.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,15 @@ pub fn delete_temp_files(directory: Option<&PathBuf>, temp_files: &[Stream]) ->
2727
fs::remove_file(&temp_file.path)?;
2828
}
2929

30-
if let Some(directory) = directory {
31-
if directory.read_dir()?.next().is_none() {
30+
if let Some(directory) = directory
31+
&& directory.read_dir()?.next().is_none() {
3232
println!(
3333
" {} {}",
3434
"Deleting".colorize("bold red"),
3535
directory.to_string_lossy()
3636
);
3737
fs::remove_dir(directory)?;
3838
}
39-
}
4039

4140
Ok(())
4241
}

vsd/src/hls/playlist.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,11 +236,10 @@ pub(crate) fn push_segments(m3u8: &m3u8_rs::MediaPlaylist, stream: &mut playlist
236236
}
237237

238238
if let Some(segment) = stream.segments.first() {
239-
if let Some(init) = &segment.map {
240-
if init.uri.split('?').next().unwrap().ends_with(".mp4") {
239+
if let Some(init) = &segment.map
240+
&& init.uri.split('?').next().unwrap().ends_with(".mp4") {
241241
stream.extension = Some("m4s".to_owned());
242242
}
243-
}
244243

245244
let uri = segment.uri.split('?').next().unwrap();
246245

vsd/src/playlist.rs

Lines changed: 20 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -231,15 +231,14 @@ impl MasterPlaylist {
231231
};
232232

233233
for (i, stream) in &video_streams {
234-
if let Some((w, h)) = &stream.resolution {
235-
if select_opts
234+
if let Some((w, h)) = &stream.resolution
235+
&& select_opts
236236
.video
237237
.resolutions
238238
.contains(&(*w as u16, *h as u16))
239239
{
240240
selected_vstreams.insert(*i);
241241
}
242-
}
243242
}
244243

245244
if select_opts.video.skip && !selected_vstreams.is_empty() {
@@ -249,11 +248,10 @@ impl MasterPlaylist {
249248
}
250249
}
251250
} else if !select_opts.video.skip {
252-
if selected_vstreams.is_empty() {
253-
if let Some((i, _)) = video_streams.first() {
251+
if selected_vstreams.is_empty()
252+
&& let Some((i, _)) = video_streams.first() {
254253
selected_vstreams.insert(*i);
255254
}
256-
}
257255

258256
for i in selected_vstreams {
259257
selected_streams.insert(i);
@@ -275,19 +273,17 @@ impl MasterPlaylist {
275273
}
276274

277275
for (i, stream) in &audio_streams {
278-
if let Some(stream_lang) = &stream.language {
279-
if select_opts.audio.contains_exact_lang(&stream_lang) {
276+
if let Some(stream_lang) = &stream.language
277+
&& select_opts.audio.contains_exact_lang(stream_lang) {
280278
selected_astreams.insert(*i);
281279
}
282-
}
283280
}
284281

285282
for (i, stream) in &audio_streams {
286-
if let Some(stream_lang) = &stream.language {
287-
if select_opts.audio.contains_siml_lang(&stream_lang) {
283+
if let Some(stream_lang) = &stream.language
284+
&& select_opts.audio.contains_siml_lang(stream_lang) {
288285
selected_astreams.insert(*i);
289286
}
290-
}
291287
}
292288

293289
if select_opts.audio.skip && !selected_astreams.is_empty() {
@@ -297,11 +293,10 @@ impl MasterPlaylist {
297293
}
298294
}
299295
} else if !select_opts.audio.skip {
300-
if selected_astreams.is_empty() {
301-
if let Some((i, _)) = audio_streams.first() {
296+
if selected_astreams.is_empty()
297+
&& let Some((i, _)) = audio_streams.first() {
302298
selected_astreams.insert(*i);
303299
}
304-
}
305300

306301
for i in selected_astreams {
307302
selected_streams.insert(i);
@@ -323,19 +318,17 @@ impl MasterPlaylist {
323318
}
324319

325320
for (i, stream) in &sub_streams {
326-
if let Some(stream_lang) = &stream.language {
327-
if select_opts.subs.contains_exact_lang(&stream_lang) {
321+
if let Some(stream_lang) = &stream.language
322+
&& select_opts.subs.contains_exact_lang(stream_lang) {
328323
selected_sstreams.insert(*i);
329324
}
330-
}
331325
}
332326

333327
for (i, stream) in &sub_streams {
334-
if let Some(stream_lang) = &stream.language {
335-
if select_opts.subs.contains_siml_lang(&stream_lang) {
328+
if let Some(stream_lang) = &stream.language
329+
&& select_opts.subs.contains_siml_lang(stream_lang) {
336330
selected_sstreams.insert(*i);
337331
}
338-
}
339332
}
340333

341334
if select_opts.subs.skip && !selected_sstreams.is_empty() {
@@ -345,11 +338,10 @@ impl MasterPlaylist {
345338
}
346339
}
347340
} else if !select_opts.subs.skip {
348-
if selected_sstreams.is_empty() {
349-
if let Some((i, _)) = sub_streams.first() {
341+
if selected_sstreams.is_empty()
342+
&& let Some((i, _)) = sub_streams.first() {
350343
selected_sstreams.insert(*i);
351344
}
352-
}
353345

354346
for i in selected_sstreams {
355347
selected_streams.insert(i);
@@ -682,11 +674,10 @@ impl MediaPlaylist {
682674
let url = base_url.join(&segment.uri)?;
683675
let mut request = client.head(url.clone()).query(query);
684676

685-
if total_segments > 1 {
686-
if let Some(range) = &segment.range {
677+
if total_segments > 1
678+
&& let Some(range) = &segment.range {
687679
request = request.header(header::RANGE, range.as_header_value());
688680
}
689-
}
690681

691682
let response = request.send()?;
692683
let content_length = response
@@ -719,11 +710,10 @@ impl MediaPlaylist {
719710
};
720711

721712
if let Some(segment) = self.segments.first() {
722-
if let Some(init) = &segment.map {
723-
if init.uri.ends_with(".mp4") {
713+
if let Some(init) = &segment.map
714+
&& init.uri.ends_with(".mp4") {
724715
ext = "mp4";
725716
}
726-
}
727717

728718
if segment.uri.ends_with(".mp4") {
729719
ext = "mp4";

0 commit comments

Comments
 (0)