1
0
Fork 0

Add SpotifyLink class

This commit is contained in:
trueold89 2024-03-21 06:52:36 +03:00
parent 04d8acbe41
commit 3a8dbd6532
Signed by: trueold89
GPG Key ID: C122E85DD49E6B30
2 changed files with 38 additions and 1 deletions

View File

@ -0,0 +1,38 @@
from enum import Enum
class SpotifyLink:
class SMTH(Enum):
CTYPE = 0
CID = 1
def __init__(self, link: str) -> None:
"""
:rtype: None
"""
if not ("open.spotify.com" in link):
raise ValueError("This is not a SpotifyOpen link")
self.__link = link
def __getsmth(self, item: SMTH) -> str:
"""
:type item: SMTH
:rtype: str
"""
split = self.__link[8:].split("/")[1:]
return split[item.value]
def __gettype(self) -> str:
"""
:return: Content type
:rtype: str
"""
return self.__getsmth(self.SMTH.CTYPE)
def __getid(self) -> str:
return self.__getsmth(self.SMTH.CID)
def uri(self):
ctype = self.__gettype()
cid = self.__getid()
return f"spotify:{ctype}:{cid}"

View File

@ -1 +0,0 @@