diff --git a/rwx/sw/freetube/profiles.py b/rwx/sw/freetube/profiles.py new file mode 100644 index 0000000..ffb0adc --- /dev/null +++ b/rwx/sw/freetube/profiles.py @@ -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}]\ +}}\ +"""