[docs]classPlaylist:""" Playlist ======== A class to represent a playlist object. """## *** CLASS CONSTRUCTOR *** ##def__init__(self,TITLE:str,OWNER:str,VISIBILITY:str,DESCRIPTION:str=None,TAGS:list[str]=None,VIDEOS:list[dict]=None)->None:""" Class Constructor ================= Parameters ---------- TITLE : str The title of the playlist. OWNER : str The owner of the playlist. VISIBILITY : str The visibility of the playlist. DESCRIPTION : str, optional The description of the playlist. TAGS : list[str], optional The tags of the playlist. VIDEOS : list[dict], optional The videos of the playlist. """# Set arguments as class attributesself.TITLE=TITLEself.OWNER=OWNERself.VISIBILITY=VISIBILITY# Set optional arguments as class attributesself.DESCRIPTION=DESCRIPTIONor""self.TAGS=TAGSor[""]self.VIDEOS=VIDEOSor[]## *** CLASS PROPERTIES *** ### *** PLAYLIST JSON *** #@propertydefplaylist(self)->dict:""" Playlist JSON ============= Get a JSON object representing the playlist. Returns ------- dict A JSON object representing the playlist. """# Create a playlist JSON objectplaylist_json={"TITLE":self.TITLE,"OWNER":self.OWNER,"VISIBILITY":self.VISIBILITY,"DESCRIPTION":self.DESCRIPTION,"TAGS":self.TAGS,"VIDEOS":self.VIDEOS}returnplaylist_json## *** CLASS METHODS *** ### *** STRING REPRESENTATION *** #def__str__(self)->str:returnstr(self.playlist)# *** ADD VIDEO *** #
[docs]defadd_video(self,video_:Video)->None:""" Add Video ========= Add a video to the playlist. Parameters ---------- video_ : Video The video to add to the playlist. """try:# Check if the video already exists in the playlistifself.__video_exists(video_):raiseAlreadyExistsError("ERROR [Playlist]: The video already exists in the playlist")else:# Add the video to the playlistself.VIDEOS.append(video_.video)exceptExceptionaserror:# Parse error and print messageprint(error_parser(error))
# *** REMOVE VIDEO *** #
[docs]defremove_video(self,video_:Video)->None:""" Remove Video ============ Remove a video from the playlist. Parameters ---------- video_ : Video The video to remove from the playlist. """try:# Check if the video exists in the playlistifself.__video_exists(video_):# Remove the video from the playlistself.VIDEOS.remove(video_.video)else:raiseNotFoundError("ERROR [Playlist]: The video does not exist in the playlist")exceptExceptionaserror:# Parse error and print messageprint(error_parser(error))
## *** PRIVATE METHODS *** ### *** VIDEO EXISTS *** #def__video_exists(self,video_:Video)->bool:# Get the videos from the playlistvideos=[videoforvideoinself.VIDEOS]# Check if the video exists in the playlistreturnvideo_.videoinvideos