//! `YoutubeDl` track metadata. use super::AuxMetadata; use crate::constants::SAMPLE_RATE_RAW; use serde::{Deserialize, Serialize}; use std::{collections::HashMap, time::Duration}; /// Information returned by yt-dlp about a URL. /// /// Returned by [`crate::input::YoutubeDl::query`]. #[derive(Deserialize, Serialize, Debug)] pub struct Output { /// The main artist. pub artist: Option, /// The album name. pub album: Option, /// The channel name. pub channel: Option, /// The duration of the stream in seconds. pub duration: Option, /// The size of the stream. pub filesize: Option, /// Required HTTP headers to fetch the track stream. pub http_headers: Option>, /// Release date of this track. pub release_date: Option, /// The thumbnail URL for this track. pub thumbnail: Option, /// The title of this track. pub title: Option, /// The track name. pub track: Option, /// The date this track was uploaded on. pub upload_date: Option, /// The name of the uploader. pub uploader: Option, /// The stream URL. pub url: String, /// The URL of the public-facing webpage for this track. pub webpage_url: Option, /// The stream protocol. pub protocol: Option, } impl Output { /// Requests auxiliary metadata which can be accessed without parsing the file. pub fn as_aux_metadata(&self) -> AuxMetadata { let album = self.album.clone(); let track = self.track.clone(); let true_artist = self.artist.as_ref(); let artist = true_artist.or(self.uploader.as_ref()).cloned(); let r_date = self.release_date.as_ref(); let date = r_date.or(self.upload_date.as_ref()).cloned(); let channel = self.channel.clone(); let duration = self.duration.map(Duration::from_secs_f64); let source_url = self.webpage_url.clone(); let title = self.title.clone(); let thumbnail = self.thumbnail.clone(); AuxMetadata { track, artist, album, date, channels: Some(2), channel, duration, sample_rate: Some(SAMPLE_RATE_RAW as u32), source_url, title, thumbnail, ..AuxMetadata::default() } } }