Add episode browser

This commit is contained in:
2022-09-13 21:33:26 -06:00
parent 1e7d9db9cc
commit a38221cca2
9 changed files with 254 additions and 18 deletions
+48 -9
View File
@@ -3,6 +3,8 @@ from typing import Type
import sys
from urllib import parse
from collections import defaultdict
from PyQt5.QtWidgets import QApplication
from PyQt5.QtQml import qmlRegisterType, QQmlApplicationEngine
from PyQt5.QtQuick import QQuickImageProvider
@@ -20,11 +22,34 @@ from .qtmpv import MpvObject
import requests
class Show(QObject):
class Episode(QObject):
def __init__(self, source, parent=None):
super().__init__(parent)
self._source = source
@pyqtProperty("QString", constant=True)
def title(self):
return self._source["Title"]
@pyqtProperty(int, constant=True)
def season(self):
return self._source["Season"]
@pyqtProperty(int, constant=True)
def episode(self):
return self._source["Episode"]
@pyqtProperty("QString", constant=True)
def filename(self):
return self._source["OriginalFilename"]
class Show(QObject):
def __init__(self, source, episodes, parent=None):
super().__init__(parent)
self._source = source
self._episodes = episodes
@pyqtProperty("QString", constant=True)
def title(self) -> str:
return self._source["title"]
@@ -37,10 +62,6 @@ class Show(QObject):
def description(self) -> str:
return self._source["description"]
@pyqtProperty(int, constant=True)
def episodes(self) -> int:
return self._source["episodes"]
@pyqtProperty(int, constant=True)
def watched(self) -> int:
return self._source["watched"]
@@ -49,6 +70,10 @@ class Show(QObject):
def poster(self) -> str:
return self._source["poster"]
@pyqtProperty(list, constant=True)
def episodes(self) -> list[Episode]:
return self._episodes
class ProviderImageProvider(QQuickImageProvider):
def __init__(self, icon_data):
@@ -89,8 +114,20 @@ class Provider(QObject):
describe["icon"]
)
def default_val():
return []
episodes: dict = getUrl(self.url, "episodes")
_episodes: defaultdict[str, list[Episode]] = defaultdict(default_val)
for e in episodes["episodes"]:
_episodes[e["ShowTitle"]].append(Episode(e))
shows: dict = getUrl(self.url, "shows")
self._shows: dict[int, Show] = {e["id"]: Show(e) for e in shows["data"]}
self._shows: dict[int, Show] = {
e["id"]: Show(e, _episodes[e["title"]]) for e in shows["data"]
}
recently_added: dict = getUrl(self.url, "recently_added")
self._recently_added: list[int] = recently_added["data"]
@@ -159,11 +196,13 @@ def main():
data_source = DataSource(
[
"http://127.0.0.1:8080/a/",
"http://127.0.0.1:8080/b/",
"http://127.0.0.1:8080/c/",
# "http://127.0.0.1:8080/a/",
# "http://127.0.0.1:8080/b/",
# "http://127.0.0.1:8080/c/",
"http://127.0.0.1:32520/",
]
)
# data_source = DataSource([])
qmlRegisterType(DatabaseType(data_source), "Ikinuki.Client", 1, 0, "Database")
# qmlRegisterType(Provider, "Ikinuki.Client", 1, 0, "Provider")