freetube.playlists
This commit is contained in:
parent
46ec104b75
commit
a92a3a786a
1 changed files with 47 additions and 0 deletions
47
rwx/sw/freetube/playlists.py
Normal file
47
rwx/sw/freetube/playlists.py
Normal 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}]\
|
||||
}}\
|
||||
"""
|
Loading…
Reference in a new issue