diff --git a/cli/src/main.rs b/cli/src/main.rs index 50721a9..c815756 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -60,12 +60,12 @@ async fn download_single_video( video_id ))?; - let mut filter = StreamFilter::default(); + let mut filter = StreamFilter::new(); if let Some(res) = resolution { if res == 0 { - filter.no_video(); + filter = filter.no_video(); } else { - filter.video_max_res(res); + filter = filter.video_max_res(res); } } diff --git a/src/param/stream_filter.rs b/src/param/stream_filter.rs index f362316..d27fa60 100644 --- a/src/param/stream_filter.rs +++ b/src/param/stream_filter.rs @@ -61,11 +61,16 @@ impl FilterResult { } impl<'a> StreamFilter<'a> { + /// Create a new [`StreamFilter`] + pub fn new() -> Self { + Self::default() + } + /// Set the maximum audio bitrate in bits per second. /// /// This is a soft filter, so if there is no stream with a bitrate /// <= the limit, the stream with the next higher bitrate is returned. - pub fn audio_max_bitrate(&mut self, max_bitrate: u32) -> &mut Self { + pub fn audio_max_bitrate(mut self, max_bitrate: u32) -> Self { self.audio_max_bitrate = Some(max_bitrate); self } @@ -78,7 +83,7 @@ impl<'a> StreamFilter<'a> { } /// Set the supported audio container formats - pub fn audio_formats(&mut self, formats: &'a [AudioFormat]) -> &mut Self { + pub fn audio_formats(mut self, formats: &'a [AudioFormat]) -> Self { self.audio_formats = Some(formats); self } @@ -91,7 +96,7 @@ impl<'a> StreamFilter<'a> { } /// Set the supported audio codecs - pub fn audio_codecs(&mut self, codecs: &'a [AudioCodec]) -> &mut Self { + pub fn audio_codecs(mut self, codecs: &'a [AudioCodec]) -> Self { self.audio_codecs = Some(codecs); self } @@ -109,7 +114,7 @@ impl<'a> StreamFilter<'a> { /// /// If this filter is unset or no stream matches, /// the filter returns the default audio stream. - pub fn audio_language(&mut self, language: &'a str) -> &mut Self { + pub fn audio_language(mut self, language: &'a str) -> Self { self.audio_language = Some(language); self } @@ -135,7 +140,7 @@ impl<'a> StreamFilter<'a> { /// /// This is a soft filter, so if there is no stream with a resolution /// <= the limit, the stream with the next higher resolution is returned. - pub fn video_max_res(&mut self, max_res: u32) -> &mut Self { + pub fn video_max_res(mut self, max_res: u32) -> Self { self.video_max_res = Some(max_res); self } @@ -151,7 +156,7 @@ impl<'a> StreamFilter<'a> { /// /// This is a soft filter, so if there is no stream with a framerate /// <= the limit, the stream with the next higher framerate is returned. - pub fn video_max_fps(&mut self, max_fps: u8) -> &mut Self { + pub fn video_max_fps(mut self, max_fps: u8) -> Self { self.video_max_fps = Some(max_fps); self } @@ -164,7 +169,7 @@ impl<'a> StreamFilter<'a> { } /// Set the supported video container formats - pub fn video_formats(&mut self, formats: &'a [VideoFormat]) -> &mut Self { + pub fn video_formats(mut self, formats: &'a [VideoFormat]) -> Self { self.video_formats = Some(formats); self } @@ -177,7 +182,7 @@ impl<'a> StreamFilter<'a> { } /// Set the supported video codecs - pub fn video_codecs(&mut self, codecs: &'a [VideoCodec]) -> &mut Self { + pub fn video_codecs(mut self, codecs: &'a [VideoCodec]) -> Self { self.video_codecs = Some(codecs); self } @@ -190,7 +195,7 @@ impl<'a> StreamFilter<'a> { } /// Allow HDR videos - pub fn video_hdr(&mut self) -> &mut Self { + pub fn video_hdr(mut self) -> Self { self.video_hdr = true; self } @@ -203,7 +208,7 @@ impl<'a> StreamFilter<'a> { } /// Output no video stream (audio only) - pub fn no_video(&mut self) -> &mut Self { + pub fn no_video(mut self) -> Self { self.video_none = true; self } diff --git a/tests/snapshots/youtube__music_album_no_year.snap b/tests/snapshots/youtube__music_album_no_year.snap new file mode 100644 index 0000000..f5a730a --- /dev/null +++ b/tests/snapshots/youtube__music_album_no_year.snap @@ -0,0 +1,61 @@ +--- +source: tests/youtube.rs +expression: album +--- +MusicAlbum( + id: "MPREb_F3Af9UZZVxX", + playlist_id: Some("OLAK5uy_nim4i4eycEtlBtS3Ci6j4SvvTmdfBcRX4"), + name: "La Ultima Vez (Remix)", + cover: "[cover]", + artists: [ + ArtistId( + id: Some("UCAJwa_1l4rHzBJyWbeBtGZw"), + name: "Omega", + ), + ArtistId( + id: Some("UCbBaYg2UToDaoOwo-R6xi4g"), + name: "Anuel AA", + ), + ArtistId( + id: Some("UCiY3z8HAGD6BlSNKVn2kSvQ"), + name: "Bad Bunny", + ), + ], + artist_id: Some("UCAJwa_1l4rHzBJyWbeBtGZw"), + description: None, + album_type: Single, + year: None, + by_va: false, + tracks: [ + TrackItem( + id: "1Sz3lUVGBSM", + name: "La Ultima Vez (Remix)", + duration: Some(229), + cover: [], + artists: [ + ArtistId( + id: Some("UCAJwa_1l4rHzBJyWbeBtGZw"), + name: "Omega", + ), + ArtistId( + id: Some("UCbBaYg2UToDaoOwo-R6xi4g"), + name: "Anuel AA", + ), + ArtistId( + id: Some("UCiY3z8HAGD6BlSNKVn2kSvQ"), + name: "Bad Bunny", + ), + ], + artist_id: Some("UCAJwa_1l4rHzBJyWbeBtGZw"), + album: Some(AlbumId( + id: "MPREb_F3Af9UZZVxX", + name: "La Ultima Vez (Remix)", + )), + view_count: None, + is_video: false, + track_nr: Some(1), + by_va: false, + ), + ], + variants: [], +) diff --git a/tests/youtube.rs b/tests/youtube.rs index 1f0ddf8..48edd1a 100644 --- a/tests/youtube.rs +++ b/tests/youtube.rs @@ -1378,6 +1378,7 @@ async fn music_playlist_not_found() { #[case::audiobook("audiobook", "MPREb_gaoNzsQHedo")] #[case::show("show", "MPREb_cwzk8EUwypZ")] #[case::unavailable("unavailable", "MPREb_AzuWg8qAVVl")] +#[case::no_year("no_year", "MPREb_F3Af9UZZVxX")] #[tokio::test] async fn music_album(#[case] name: &str, #[case] id: &str) { let rp = RustyPipe::builder().strict().build();