Compare commits
11 commits
2327d5388d
...
eb3c9814bb
Author | SHA1 | Date | |
---|---|---|---|
eb3c9814bb | |||
daccf01b8c | |||
5eae0334de | |||
edd8e15978 | |||
a92a3a786a | |||
46ec104b75 | |||
6ece695be4 | |||
2a01ef0066 | |||
45df475195 | |||
19153b3bc1 | |||
e61be6cf4f |
8 changed files with 223 additions and 0 deletions
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
|
import tomllib
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from rwx import ps
|
from rwx import ps
|
||||||
|
@ -94,6 +95,19 @@ def read_file_bytes(file_path: Path) -> bytes:
|
||||||
return file_object.read()
|
return file_object.read()
|
||||||
|
|
||||||
|
|
||||||
|
def read_file_dict(file_path: Path, charset: str = CHARSET) -> dict:
|
||||||
|
"""Read whole file as toml object.
|
||||||
|
|
||||||
|
:param file_path: source input file
|
||||||
|
:type file_path: Path
|
||||||
|
:param charset: charset to use for decoding input
|
||||||
|
:type charset: str
|
||||||
|
:rtype: dict
|
||||||
|
"""
|
||||||
|
text = read_file_text(file_path, charset)
|
||||||
|
return tomllib.loads(text)
|
||||||
|
|
||||||
|
|
||||||
def read_file_lines(file_path: Path, charset: str = CHARSET) -> list[str]:
|
def read_file_lines(file_path: Path, charset: str = CHARSET) -> list[str]:
|
||||||
"""Read whole file lines.
|
"""Read whole file lines.
|
||||||
|
|
||||||
|
|
1
rwx/sw/freetube/__init__.py
Normal file
1
rwx/sw/freetube/__init__.py
Normal file
|
@ -0,0 +1 @@
|
||||||
|
"""Configure FreeTube."""
|
29
rwx/sw/freetube/channels.py
Normal file
29
rwx/sw/freetube/channels.py
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
"""FreeTube channels."""
|
||||||
|
|
||||||
|
from rwx import Class
|
||||||
|
|
||||||
|
|
||||||
|
class Channel(Class):
|
||||||
|
"""FreeTube channel."""
|
||||||
|
|
||||||
|
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.uid = uid
|
||||||
|
self.name = name
|
||||||
|
|
||||||
|
def to_db(self) -> str:
|
||||||
|
"""Return identifier as db.
|
||||||
|
|
||||||
|
:rtype: str
|
||||||
|
"""
|
||||||
|
return f"""\
|
||||||
|
{{\
|
||||||
|
"id":"{self.uid}"\
|
||||||
|
}}\
|
||||||
|
"""
|
21
rwx/sw/freetube/db.py
Normal file
21
rwx/sw/freetube/db.py
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
"""Output FreeTube db."""
|
||||||
|
|
||||||
|
|
||||||
|
def to_db(value: object) -> str:
|
||||||
|
"""Render value as string.
|
||||||
|
|
||||||
|
:param value: value to render
|
||||||
|
:type value: object
|
||||||
|
:rtype: str
|
||||||
|
"""
|
||||||
|
match value:
|
||||||
|
case bool():
|
||||||
|
text = str(value).lower()
|
||||||
|
case dict():
|
||||||
|
sub = ",".join([f'"{i}":{to_db(v)}' for i, v in value.items()])
|
||||||
|
text = f"{{{sub}}}"
|
||||||
|
case float() | str():
|
||||||
|
text = f'"{value}"'
|
||||||
|
case _:
|
||||||
|
text = str(value)
|
||||||
|
return text
|
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}]\
|
||||||
|
}}\
|
||||||
|
"""
|
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}]\
|
||||||
|
}}\
|
||||||
|
"""
|
33
rwx/sw/freetube/settings.py
Normal file
33
rwx/sw/freetube/settings.py
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
"""FreeTube settings."""
|
||||||
|
|
||||||
|
from rwx import Class
|
||||||
|
|
||||||
|
from .db import to_db
|
||||||
|
|
||||||
|
|
||||||
|
class Setting(Class):
|
||||||
|
"""FreeTube setting."""
|
||||||
|
|
||||||
|
def __init__(self, uid: str, value: object) -> None:
|
||||||
|
"""Set uid & value.
|
||||||
|
|
||||||
|
:param uid: unique identifier
|
||||||
|
:type uid: str
|
||||||
|
:param value: value
|
||||||
|
:type value: object
|
||||||
|
"""
|
||||||
|
self.uid = uid
|
||||||
|
self.value = value
|
||||||
|
|
||||||
|
def to_db(self) -> str:
|
||||||
|
"""Return uid & value as db string.
|
||||||
|
|
||||||
|
:rtype: str
|
||||||
|
"""
|
||||||
|
return f"""\
|
||||||
|
{{\
|
||||||
|
"_id":"{self.uid}"\
|
||||||
|
,\
|
||||||
|
"value":{to_db(self.value)}\
|
||||||
|
}}\
|
||||||
|
"""
|
33
rwx/sw/freetube/videos.py
Normal file
33
rwx/sw/freetube/videos.py
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
"""FreeTube videos."""
|
||||||
|
|
||||||
|
from rwx import Class
|
||||||
|
|
||||||
|
|
||||||
|
class Video(Class):
|
||||||
|
"""FreeTube video."""
|
||||||
|
|
||||||
|
def __init__(self, uid: str, name: str) -> None:
|
||||||
|
"""Set id & name.
|
||||||
|
|
||||||
|
:param uid: identifier
|
||||||
|
:type uid: str
|
||||||
|
:param name: label
|
||||||
|
:type name: str
|
||||||
|
"""
|
||||||
|
self.uid = uid
|
||||||
|
self.name = name
|
||||||
|
|
||||||
|
def to_db(self) -> str:
|
||||||
|
"""Return identifier, zero length & title.
|
||||||
|
|
||||||
|
:rtype: str
|
||||||
|
"""
|
||||||
|
return f"""\
|
||||||
|
{{\
|
||||||
|
"videoId":"{self.uid}"\
|
||||||
|
,\
|
||||||
|
"lengthSeconds":0\
|
||||||
|
,\
|
||||||
|
"title":"{self.name}"\
|
||||||
|
}}\
|
||||||
|
"""
|
Loading…
Reference in a new issue