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