Fix database loaded songs not having a thumbnail

Signed-off-by: trivernis <trivernis@protonmail.com>
pull/25/head
trivernis 3 years ago
parent af4a83e9ed
commit 4f250b5375
Signed by: Trivernis
GPG Key ID: DFFFCC2C7A02DB45

@ -289,16 +289,18 @@ async fn get_youtube_song_for_track(database: &Database, track: Track) -> BotRes
if let Some(id) = track.id { if let Some(id) = track.id {
let entry = database.get_song(&id).await?; let entry = database.get_song(&id).await?;
if let Some(song) = &entry { if let Some(song) = entry {
// check if the video is still available // check if the video is still available
if get_video_information(&song.url).await.is_err() { log::trace!("Found entry is {:?}", song);
if let Ok(info) = get_video_information(&song.url).await {
return Ok(Some(info.into()));
} else {
log::debug!("Video '{}' is not available. Deleting entry", song.url); log::debug!("Video '{}' is not available. Deleting entry", song.url);
database.delete_song(song.id).await?; database.delete_song(song.id).await?;
return Ok(None); return Ok(None);
} }
} }
log::trace!("Found entry is {:?}", entry); Ok(None)
Ok(entry.map(Song::from))
} else { } else {
log::debug!("Track has no ID"); log::debug!("Track has no ID");
Ok(None) Ok(None)

@ -85,11 +85,11 @@ pub enum SongSource {
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct Song { pub struct Song {
url: Option<String>, pub(crate) url: Option<String>,
title: String, pub(crate) title: String,
author: String, pub(crate) author: String,
thumbnail: Option<String>, pub(crate) thumbnail: Option<String>,
source: SongSource, pub(crate) source: SongSource,
} }
impl Song { impl Song {

Loading…
Cancel
Save