freetube.playlists

This commit is contained in:
Marc Beninca 2024-09-23 14:46:13 +02:00
parent 46ec104b75
commit a92a3a786a
Signed by: marc.beninca
GPG key ID: 9C7613450C80C24F

View file

@ -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}]\
}}\
"""