Skip to content

Commit

Permalink
fix playlists (#243)
Browse files Browse the repository at this point in the history
  • Loading branch information
jheuel authored Aug 19, 2023
1 parent 0f2022c commit d13c701
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
18 changes: 12 additions & 6 deletions src/commands/play.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,9 @@ pub async fn play(
.ok_or(ParrotError::Other("failed to fetch playlist"))?;

for url in urls.iter() {
let queue =
enqueue_track(&call, &QueryType::VideoLink(url.to_string())).await?;
let Ok(queue) = enqueue_track(&call, &QueryType::VideoLink(url.to_string())).await else {
continue;
};
update_queue_messages(&ctx.http, &ctx.data, &queue, guild_id).await;
}
}
Expand All @@ -193,7 +194,9 @@ pub async fn play(
.ok_or(ParrotError::Other("failed to fetch playlist"))?;

for (idx, url) in urls.into_iter().enumerate() {
let queue = insert_track(&call, &QueryType::VideoLink(url), idx + 1).await?;
let Ok(queue) = insert_track(&call, &QueryType::VideoLink(url), idx + 1).await else {
continue;
};
update_queue_messages(&ctx.http, &ctx.data, &queue, guild_id).await;
}
}
Expand Down Expand Up @@ -224,8 +227,9 @@ pub async fn play(
let mut insert_idx = 1;

for (i, url) in urls.into_iter().enumerate() {
let mut queue =
insert_track(&call, &QueryType::VideoLink(url), insert_idx).await?;
let Ok(mut queue) = insert_track(&call, &QueryType::VideoLink(url), insert_idx).await else {
continue;
};

if i == 0 && !queue_was_empty {
queue = force_skip_top_track(&call.lock().await).await?;
Expand Down Expand Up @@ -260,7 +264,9 @@ pub async fn play(
.ok_or(ParrotError::Other("failed to fetch playlist"))?;

for url in urls.into_iter() {
let queue = enqueue_track(&call, &QueryType::VideoLink(url)).await?;
let Ok(queue) = enqueue_track(&call, &QueryType::VideoLink(url)).await else {
continue;
};
update_queue_messages(&ctx.http, &ctx.data, &queue, guild_id).await;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/sources/youtube.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub struct YouTube {}

impl YouTube {
pub fn extract(query: &str) -> Option<QueryType> {
if query.contains("playlist?list=") {
if query.contains("list=") {
Some(QueryType::PlaylistLink(query.to_string()))
} else {
Some(QueryType::VideoLink(query.to_string()))
Expand Down

0 comments on commit d13c701

Please sign in to comment.