From a92a3a786a672dc93b3ad20904ffdcc1b94c5b6f Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Mon, 23 Sep 2024 14:46:13 +0200 Subject: [PATCH] freetube.playlists --- rwx/sw/freetube/playlists.py | 47 ++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 rwx/sw/freetube/playlists.py diff --git a/rwx/sw/freetube/playlists.py b/rwx/sw/freetube/playlists.py new file mode 100644 index 0000000..4183336 --- /dev/null +++ b/rwx/sw/freetube/playlists.py @@ -0,0 +1,47 @@ +"""FreeTube playlists.""" + +from rwx import Class + +from .videos import Video + + +class Playlist(Class): + """FreeTube playlist.""" + + def __init__(self, uid: str, name: str) -> None: + """Set uid & name. + + :param uid: identifier + :type uid: str + :param name: label + :type name: str + """ + self.uid = uid + self.name = name + self.videos: list[Video] = [] + + def add(self, video: Video) -> None: + """Add video. + + :param video: video to add + :type video: Video + """ + self.videos.append(video) + + def to_db(self) -> str: + """Return identifier, name & videos. + + :rtype: str + """ + videos = ",".join([video.to_db() for video in self.videos]) + return f"""\ +{{\ +"_id":"{self.uid}"\ +,\ +"playlistName":"{self.name}"\ +,\ +"protected":true\ +,\ +"videos":[{videos}]\ +}}\ +"""