forked from IndeedTheRoyale/SpotifyAutomator
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidators.py
More file actions
17 lines (14 loc) · 758 Bytes
/
validators.py
File metadata and controls
17 lines (14 loc) · 758 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#!/usr/bin/env python3
import regex
from prompt_toolkit.validation import ValidationError, Validator
class PlaylistURIValidator(Validator):
def validate(self, document):
if document.text == "back":
return "back"
uriCheck = regex.match("^(spotify:playlist:)([a-zA-Z0-9]+)(.*)$", document.text)
urlCheck = regex.match("^(https:\/\/open.spotify.com\/playlist\/)([a-zA-Z0-9]+)(.*)$", document.text)
if not (uriCheck or urlCheck):
raise ValidationError(
message="Please provide a valid playlist uri (example: 'spotify:playlist:<id>' or 'https://open.spotify.com/playlist/<id>)",
cursor_position=len(document.text), # move cursor to end
)