diff --git a/src/Utils/__init__.py b/src/Utils/__init__.py index b171b45..729a901 100644 --- a/src/Utils/__init__.py +++ b/src/Utils/__init__.py @@ -68,44 +68,53 @@ def add_video(video_id: str, con.commit() -def get_svt_thumb_from_id_changed(id: str, changed: str, size: str = "480") -> str: - return "https://www.svtstatic.se/image/custom/{}/{}/{}".format(size, id, changed) + +def get_svt_thumb_from_id_changed(id: str, + changed: str, + size: str = "480") -> str: + return "https://www.svtstatic.se/image/custom/{}/{}/{}".format( + size, id, changed) + def get_all_svt_categories() -> list: categories: list = list() url = "https://www.svtplay.se/kategori" - data = get_svt_data(url) + data = get_svt_data(url) for entry in data: if 'genres' in entry.keys(): categories = entry['genres'] break return categories + def get_svt_category(category: str) -> list: url = 'https://www.svtplay.se/kategori/{}?tab=all'.format(category) - data = get_svt_data(url) - programs = list() + data = get_svt_data(url) + programs = list() for entry in data: - if "categoryPage" in entry.keys(): - for tab in entry["categoryPage"]["lazyLoadedTabs"]: - if "selections" in tab.keys(): - for selection in tab["selections"]: - programs += selection['items'] - break + if "categoryPage" in entry.keys(): + for tab in entry["categoryPage"]["lazyLoadedTabs"]: + if "selections" in tab.keys(): + for selection in tab["selections"]: + programs += selection['items'] + break return programs + def get_svt_data(url: str) -> list: - result:list = list() + result: list = list() res = requests.get(url) - soup = BeautifulSoup(res.text, features="lxml") - data = json.loads(soup.find(id="__NEXT_DATA__").string)["props"]["urqlState"] + soup = BeautifulSoup(res.text, features="lxml") + data = json.loads( + soup.find(id="__NEXT_DATA__").string)["props"]["urqlState"] for key in data.keys(): - result.append(json.loads(data[key]["data"])) + result.append(json.loads(data[key]["data"])) return result + def get_all_svt_programs() -> list: url = 'https://www.svtplay.se/program' - data = get_svt_data(url) + data = get_svt_data(url) programs = list() for entry in data: if "programAtillO" in entry.keys(): @@ -352,7 +361,14 @@ def resolve_svt_channel(svt_id: str, path: str = '/usr/share/cast') -> dict: } for category in get_all_svt_categories(): - channels[category['id']] = {"name": category["name"], "thumbnail": make_bitmap_from_url(get_svt_thumb_from_id_changed(category['image']['id'], category['image']['changed']))} + channels[category['id']] = { + "name": + category["name"], + "thumbnail": + make_bitmap_from_url( + get_svt_thumb_from_id_changed(category['image']['id'], + category['image']['changed'])) + } return channels[svt_id]