freetube.profiles

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

View file

@ -0,0 +1,45 @@
"""FreeTube profiles."""
from rwx import Class
from .channels import Channel
class Profile(Class):
"""FreeTube profile."""
def __init__(self, uid: str, name: str) -> None:
"""Set uid & name.
:param uid: unique identifier
:type uid: str
:param name: label
:type name: str
"""
self.id = uid
self.name = name
self.channels: list[Channel] = []
def add(self, channel: Channel) -> None:
"""Add channel.
:param channel: channel to add
:type channel: Channel
"""
self.channels.append(channel)
def to_db(self) -> str:
"""Return identifier, name & channels.
:rtype: str
"""
channels = ",".join([channel.to_db() for channel in self.channels])
return f"""\
{{\
"_id":"{self.id}"\
,\
"name":"{self.name}"\
,\
"subscriptions":[{channels}]\
}}\
"""