Add more channel & item metadata
This includes categories (from hashtags), descriptions and keywords.
This commit is contained in:
parent
cd831a5145
commit
a6c9275d93
|
@ -115,11 +115,14 @@ impl From<YouTubeChannelWithVideos> for Channel {
|
||||||
YouTubeChannelWithVideos(yt_channel, yt_videos_w_streams): YouTubeChannelWithVideos,
|
YouTubeChannelWithVideos(yt_channel, yt_videos_w_streams): YouTubeChannelWithVideos,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let mut link = Url::parse(CHANNEL_BASE_URL).expect("valid URL");
|
let mut link = Url::parse(CHANNEL_BASE_URL).expect("valid URL");
|
||||||
|
let title = format!("{0} (via YouTube)", yt_channel.name());
|
||||||
|
let description = yt_channel.description().to_string();
|
||||||
link.path_segments_mut()
|
link.path_segments_mut()
|
||||||
.expect("valid URL")
|
.expect("valid URL")
|
||||||
.push(&yt_channel.id());
|
.push(&yt_channel.id());
|
||||||
let author = Some(yt_channel.name().to_string());
|
let author = Some(yt_channel.name().to_string());
|
||||||
let categories = Vec::from([String::from("Video")]);
|
// FIXME: Don't hardcode the category!
|
||||||
|
let categories = Vec::from([String::from("Channel")]);
|
||||||
let image = yt_channel
|
let image = yt_channel
|
||||||
.avatar()
|
.avatar()
|
||||||
.max_by_key(|av| av.width * av.height)
|
.max_by_key(|av| av.width * av.height)
|
||||||
|
@ -127,9 +130,9 @@ impl From<YouTubeChannelWithVideos> for Channel {
|
||||||
let items = yt_videos_w_streams.into_iter().map(Item::from).collect();
|
let items = yt_videos_w_streams.into_iter().map(Item::from).collect();
|
||||||
|
|
||||||
Channel {
|
Channel {
|
||||||
title: format!("{0} (via YouTube)", yt_channel.name()),
|
title,
|
||||||
link,
|
link,
|
||||||
description: yt_channel.description().to_string(),
|
description,
|
||||||
author,
|
author,
|
||||||
categories,
|
categories,
|
||||||
image,
|
image,
|
||||||
|
@ -142,12 +145,14 @@ impl From<YouTubePlaylistWithVideos> for Channel {
|
||||||
fn from(
|
fn from(
|
||||||
YouTubePlaylistWithVideos(yt_playlist, yt_videos_w_streams): YouTubePlaylistWithVideos,
|
YouTubePlaylistWithVideos(yt_playlist, yt_videos_w_streams): YouTubePlaylistWithVideos,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
|
let title = format!("{0} (via YouTube)", yt_playlist.title());
|
||||||
let mut link = Url::parse(PLAYLIST_BASE_URL).expect("valid URL");
|
let mut link = Url::parse(PLAYLIST_BASE_URL).expect("valid URL");
|
||||||
|
let description = yt_playlist.description().to_string();
|
||||||
link.query_pairs_mut()
|
link.query_pairs_mut()
|
||||||
.append_pair("list", &yt_playlist.id().to_string());
|
.append_pair("list", &yt_playlist.id().to_string());
|
||||||
let author = yt_playlist.channel().map(|chan| chan.name().to_string());
|
let author = yt_playlist.channel().map(|chan| chan.name().to_string());
|
||||||
// FIXME: Don't hardcode the category!
|
// FIXME: Don't hardcode the category!
|
||||||
let categories = Vec::from([String::from("Video")]);
|
let categories = Vec::from([String::from("Playlist")]);
|
||||||
let image = yt_playlist
|
let image = yt_playlist
|
||||||
.thumbnails()
|
.thumbnails()
|
||||||
.iter()
|
.iter()
|
||||||
|
@ -156,9 +161,9 @@ impl From<YouTubePlaylistWithVideos> for Channel {
|
||||||
let items = yt_videos_w_streams.into_iter().map(Item::from).collect();
|
let items = yt_videos_w_streams.into_iter().map(Item::from).collect();
|
||||||
|
|
||||||
Channel {
|
Channel {
|
||||||
title: format!("{0} (via YouTube)", yt_playlist.title()),
|
title,
|
||||||
link,
|
link,
|
||||||
description: yt_playlist.description().to_string(),
|
description,
|
||||||
author,
|
author,
|
||||||
categories,
|
categories,
|
||||||
image,
|
image,
|
||||||
|
@ -190,8 +195,23 @@ impl From<YouTubeVideoWithStream> for Item {
|
||||||
|
|
||||||
let mut link = Url::parse(VIDEO_BASE_URL).expect("valid URL");
|
let mut link = Url::parse(VIDEO_BASE_URL).expect("valid URL");
|
||||||
link.query_pairs_mut().append_pair("v", &id);
|
link.query_pairs_mut().append_pair("v", &id);
|
||||||
let description = Some(format!("Taken from YouTube: {0}", link));
|
let video_description = video.description();
|
||||||
|
let description = Some(format!("{video_description}\n\nTaken from YouTube: {link}"));
|
||||||
|
let categories = video
|
||||||
|
.hashtags()
|
||||||
|
.filter(|hashtag| !hashtag.trim().is_empty())
|
||||||
|
.map(|hashtag| {
|
||||||
|
let url = Url::parse(&format!(
|
||||||
|
"https://www.youtube.com/hashtag/{}",
|
||||||
|
hashtag.trim_start_matches('#')
|
||||||
|
))
|
||||||
|
.expect("valid URL");
|
||||||
|
|
||||||
|
(hashtag.to_string(), url)
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
let duration = Some(video.duration().as_secs() as u32);
|
let duration = Some(video.duration().as_secs() as u32);
|
||||||
|
let keywords = video.keywords().clone();
|
||||||
let image = video
|
let image = video
|
||||||
.thumbnails()
|
.thumbnails()
|
||||||
.iter()
|
.iter()
|
||||||
|
@ -207,11 +227,11 @@ impl From<YouTubeVideoWithStream> for Item {
|
||||||
title: video.title().to_string(),
|
title: video.title().to_string(),
|
||||||
link,
|
link,
|
||||||
description,
|
description,
|
||||||
categories: Default::default(),
|
categories,
|
||||||
enclosure,
|
enclosure,
|
||||||
duration,
|
duration,
|
||||||
guid: id,
|
guid: id,
|
||||||
keywords: Default::default(),
|
keywords,
|
||||||
image,
|
image,
|
||||||
updated_at,
|
updated_at,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue