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

fix: handle age restricted videos #194

Merged
merged 2 commits into from
Apr 20, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions src/commands/play.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,11 +332,11 @@ async fn get_track_source(query_type: QueryType) -> Result<Restartable, ParrotEr
match query_type {
QueryType::VideoLink(query) => YouTubeRestartable::ytdl(query, true)
.await
.map_err(|_| ParrotError::TrackNotFound),
.map_err(ParrotError::TrackFail),

QueryType::Keywords(query) => YouTubeRestartable::ytdl_search(query, true)
.await
.map_err(|_| ParrotError::TrackNotFound),
.map_err(ParrotError::TrackFail),

_ => unreachable!(),
}
Expand Down
19 changes: 16 additions & 3 deletions src/errors.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use crate::strings::{
FAIL_ANOTHER_CHANNEL, FAIL_AUTHOR_DISCONNECTED, FAIL_AUTHOR_NOT_FOUND,
FAIL_NO_VOICE_CONNECTION, FAIL_WRONG_CHANNEL, NOTHING_IS_PLAYING, QUEUE_IS_EMPTY,
TRACK_NOT_FOUND,
TRACK_INAPPROPRIATE, TRACK_NOT_FOUND,
};
use rspotify::ClientError as RSpotifyClientError;
use serenity::{model::misc::Mention, prelude::SerenityError};
use songbird::input::error::Error as InputError;
use std::fmt::{Debug, Display};
use std::{error::Error, fmt};

Expand All @@ -19,7 +20,7 @@ pub enum ParrotError {
WrongVoiceChannel,
AuthorNotFound,
NothingPlaying,
TrackNotFound,
TrackFail(InputError),
AlreadyConnected(Mention),
Serenity(SerenityError),
RSpotify(RSpotifyClientError),
Expand Down Expand Up @@ -50,7 +51,19 @@ impl Display for ParrotError {
f.write_fmt(format_args!("{} {}", FAIL_ANOTHER_CHANNEL, mention))
}
Self::NothingPlaying => f.write_str(NOTHING_IS_PLAYING),
Self::TrackNotFound => f.write_str(TRACK_NOT_FOUND),
Self::TrackFail(err) => match err {
InputError::Json {
error: _,
parsed_text,
} => {
if parsed_text.contains("Sign in to confirm your age") {
f.write_str(TRACK_INAPPROPRIATE)
} else {
f.write_str(TRACK_NOT_FOUND)
}
}
_ => unimplemented!(),
},
Self::Serenity(err) => f.write_str(&format!("{err}")),
Self::RSpotify(err) => f.write_str(&format!("{err}")),
}
Expand Down
3 changes: 2 additions & 1 deletion src/strings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ pub const SPOTIFY_INVALID_QUERY: &str =
pub const SPOTIFY_PLAYLIST_FAILED: &str = "⚠️ **Failed to fetch playlist!**\nIt's likely that this playlist is either private or a personalized recommendation playlist generated by Spotify.";
pub const STOPPED: &str = "⏹️ Stopped!";
pub const TRACK_DURATION: &str = "Track duration: ";
pub const TRACK_NOT_FOUND: &str = "⚠️ Could not play track! It seems your query yielded no results.";
pub const TRACK_NOT_FOUND: &str = "⚠️ **Could not play track!**\nYour request yielded no results.";
pub const TRACK_INAPPROPRIATE: &str = "⚠️ **Could not play track!**\nThe video you requested may be inappropriate for some users, so sign-in is required.";
pub const TRACK_TIME_TO_PLAY: &str = "Estimated time until play: ";
pub const VERSION_LATEST: &str = "Find the latest version [here]";
pub const VERSION: &str = "Version";