Skip to content

Commit

Permalink
fix: handle age restricted videos (#194)
Browse files Browse the repository at this point in the history
* handle age restricted videos

* print default InputError for other arms
  • Loading branch information
aquelemiguel authored Apr 20, 2022
1 parent 0bfd98c commit db9fa2f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
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)
}
}
_ => f.write_str(&format!("{err}")),
},
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";

0 comments on commit db9fa2f

Please sign in to comment.