Metadata: Add source_url and thumbnail fields (#28)

This commit is contained in:
Saanu Reghunadh
2020-12-07 20:24:29 +05:30
committed by GitHub
parent f222ce9969
commit 700f20dff9

View File

@@ -26,6 +26,10 @@ pub struct Metadata {
pub duration: Option<Duration>, pub duration: Option<Duration>,
/// The sample rate of this stream. /// The sample rate of this stream.
pub sample_rate: Option<u32>, pub sample_rate: Option<u32>,
/// The source url of this stream.
pub source_url: Option<String>,
/// The thumbnail url of this stream.
pub thumbnail: Option<String>,
} }
impl Metadata { impl Metadata {
@@ -92,6 +96,8 @@ impl Metadata {
start_time, start_time,
duration, duration,
sample_rate, sample_rate,
..Default::default()
} }
} }
@@ -137,6 +143,16 @@ impl Metadata {
.and_then(Value::as_f64) .and_then(Value::as_f64)
.map(Duration::from_secs_f64); .map(Duration::from_secs_f64);
let source_url = obj
.and_then(|m| m.get("webpage_url"))
.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 { Self {
title, title,
artist, artist,
@@ -145,6 +161,8 @@ impl Metadata {
channels: Some(2), channels: Some(2),
duration, duration,
sample_rate: Some(SAMPLE_RATE_RAW as u32), sample_rate: Some(SAMPLE_RATE_RAW as u32),
source_url,
thumbnail,
..Default::default() ..Default::default()
} }
@@ -161,6 +179,8 @@ impl Metadata {
start_time: self.start_time.take(), start_time: self.start_time.take(),
duration: self.duration.take(), duration: self.duration.take(),
sample_rate: self.sample_rate.take(), sample_rate: self.sample_rate.take(),
source_url: self.source_url.take(),
thumbnail: self.thumbnail.take(),
} }
} }
} }