diff --git a/examples/twilight/src/main.rs b/examples/twilight/src/main.rs index d7e1967..970ec1a 100644 --- a/examples/twilight/src/main.rs +++ b/examples/twilight/src/main.rs @@ -190,7 +190,7 @@ async fn play(msg: Message, state: State) -> Result<(), Box".to_string()), input diff --git a/src/input/dca.rs b/src/input/dca.rs index dd37b39..cdda781 100644 --- a/src/input/dca.rs +++ b/src/input/dca.rs @@ -118,7 +118,7 @@ pub(crate) struct Origin { impl From for Metadata { fn from(mut d: DcaMetadata) -> Self { - let (title, artist) = d + let (track, artist) = d .info .take() .map(|mut m| (m.title.take(), m.artist.take())) @@ -128,7 +128,7 @@ impl From for Metadata { let sample_rate = Some(d.opus.sample_rate); Self { - title, + track, artist, channels, diff --git a/src/input/metadata.rs b/src/input/metadata.rs index d14bc29..f05f81c 100644 --- a/src/input/metadata.rs +++ b/src/input/metadata.rs @@ -7,8 +7,8 @@ use std::time::Duration; /// [`Input`]: crate::input::Input #[derive(Clone, Debug, Default, Eq, PartialEq)] pub struct Metadata { - /// The title of this stream. - pub title: Option, + /// The track of this stream. + pub track: Option, /// The main artist of this stream. pub artist: Option, /// The date of creation of this stream. @@ -18,6 +18,8 @@ pub struct Metadata { /// /// Any number `>= 2` is treated as stereo. pub channels: Option, + /// The YouTube channel of this stream. + pub channel: Option, /// The time at which the first true sample is played back. /// /// This occurs as an artefact of coder delay. @@ -28,6 +30,8 @@ pub struct Metadata { pub sample_rate: Option, /// The source url of this stream. pub source_url: Option, + /// The YouTube title of this stream. + pub title: Option, /// The thumbnail url of this stream. pub thumbnail: Option, } @@ -52,7 +56,7 @@ impl Metadata { let tags = format.and_then(|m| m.get("tags")); - let title = tags + let track = tags .and_then(|m| m.get("title")) .and_then(Value::as_str) .map(str::to_string); @@ -88,7 +92,7 @@ impl Metadata { .map(|v| v as u32); Self { - title, + track, artist, date, @@ -110,12 +114,6 @@ impl Metadata { .and_then(Value::as_str) .map(str::to_string); - let title = track.or_else(|| { - obj.and_then(|m| m.get("title")) - .and_then(Value::as_str) - .map(str::to_string) - }); - let true_artist = obj .and_then(|m| m.get("artist")) .and_then(Value::as_str) @@ -138,6 +136,11 @@ impl Metadata { .map(str::to_string) }); + let channel = obj + .and_then(|m| m.get("channel")) + .and_then(Value::as_str) + .map(str::to_string); + let duration = obj .and_then(|m| m.get("duration")) .and_then(Value::as_f64) @@ -148,20 +151,27 @@ impl Metadata { .and_then(Value::as_str) .map(str::to_string); + let title = obj + .and_then(|m| m.get("title")) + .and_then(Value::as_str) + .map(str::to_string); + let thumbnail = obj .and_then(|m| m.get("thumbnail")) .and_then(Value::as_str) .map(str::to_string); Self { - title, + track, artist, date, channels: Some(2), + channel, duration, sample_rate: Some(SAMPLE_RATE_RAW as u32), source_url, + title, thumbnail, ..Default::default() @@ -171,15 +181,17 @@ impl Metadata { /// Move all fields from a `Metadata` object into a new one. pub fn take(&mut self) -> Self { Self { - title: self.title.take(), + track: self.track.take(), artist: self.artist.take(), date: self.date.take(), channels: self.channels.take(), + channel: self.channel.take(), start_time: self.start_time.take(), duration: self.duration.take(), sample_rate: self.sample_rate.take(), source_url: self.source_url.take(), + title: self.title.take(), thumbnail: self.thumbnail.take(), } }