refactor: use fancy-regex only for backtracking
This commit is contained in:
parent
4cc069fba2
commit
92a358a079
12 changed files with 69 additions and 108 deletions
|
|
@ -111,30 +111,22 @@ impl UrlTarget {
|
|||
/// Validate the YouTube ID from the URL target
|
||||
pub(crate) fn validate(&self) -> Result<(), Error> {
|
||||
match self {
|
||||
UrlTarget::Video { id, .. } => {
|
||||
match util::VIDEO_ID_REGEX.is_match(id).unwrap_or_default() {
|
||||
true => Ok(()),
|
||||
false => Err(Error::Other("invalid video id".into())),
|
||||
}
|
||||
}
|
||||
UrlTarget::Channel { id } => {
|
||||
match util::CHANNEL_ID_REGEX.is_match(id).unwrap_or_default() {
|
||||
true => Ok(()),
|
||||
false => Err(Error::Other("invalid channel id".into())),
|
||||
}
|
||||
}
|
||||
UrlTarget::Playlist { id } => {
|
||||
match util::PLAYLIST_ID_REGEX.is_match(id).unwrap_or_default() {
|
||||
true => Ok(()),
|
||||
false => Err(Error::Other("invalid playlist id".into())),
|
||||
}
|
||||
}
|
||||
UrlTarget::Album { id } => {
|
||||
match util::ALBUM_ID_REGEX.is_match(id).unwrap_or_default() {
|
||||
true => Ok(()),
|
||||
false => Err(Error::Other("invalid album id".into())),
|
||||
}
|
||||
}
|
||||
UrlTarget::Video { id, .. } => match util::VIDEO_ID_REGEX.is_match(id) {
|
||||
true => Ok(()),
|
||||
false => Err(Error::Other("invalid video id".into())),
|
||||
},
|
||||
UrlTarget::Channel { id } => match util::CHANNEL_ID_REGEX.is_match(id) {
|
||||
true => Ok(()),
|
||||
false => Err(Error::Other("invalid channel id".into())),
|
||||
},
|
||||
UrlTarget::Playlist { id } => match util::PLAYLIST_ID_REGEX.is_match(id) {
|
||||
true => Ok(()),
|
||||
false => Err(Error::Other("invalid playlist id".into())),
|
||||
},
|
||||
UrlTarget::Album { id } => match util::ALBUM_ID_REGEX.is_match(id) {
|
||||
true => Ok(()),
|
||||
false => Err(Error::Other("invalid album id".into())),
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Reference in a new issue