Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enqueuing playlists: skip songs that cannot be added #243

Merged
merged 2 commits into from
Aug 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading