Code format

main
Micke Nordin 2 years ago
parent 4f719ac781
commit 0528d20f1d
Signed by: micke
GPG Key ID: 0DA0A7A5708FE257

@ -68,8 +68,13 @@ def add_video(video_id: str,
con.commit() 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: def get_all_svt_categories() -> list:
categories: list = list() categories: list = list()
@ -81,28 +86,32 @@ def get_all_svt_categories() -> list:
break break
return categories return categories
def get_svt_category(category: str) -> list: def get_svt_category(category: str) -> list:
url = 'https://www.svtplay.se/kategori/{}?tab=all'.format(category) url = 'https://www.svtplay.se/kategori/{}?tab=all'.format(category)
data = get_svt_data(url) data = get_svt_data(url)
programs = list() programs = list()
for entry in data: for entry in data:
if "categoryPage" in entry.keys(): if "categoryPage" in entry.keys():
for tab in entry["categoryPage"]["lazyLoadedTabs"]: for tab in entry["categoryPage"]["lazyLoadedTabs"]:
if "selections" in tab.keys(): if "selections" in tab.keys():
for selection in tab["selections"]: for selection in tab["selections"]:
programs += selection['items'] programs += selection['items']
break break
return programs return programs
def get_svt_data(url: str) -> list: def get_svt_data(url: str) -> list:
result:list = list() result: list = list()
res = requests.get(url) res = requests.get(url)
soup = BeautifulSoup(res.text, features="lxml") soup = BeautifulSoup(res.text, features="lxml")
data = json.loads(soup.find(id="__NEXT_DATA__").string)["props"]["urqlState"] data = json.loads(
soup.find(id="__NEXT_DATA__").string)["props"]["urqlState"]
for key in data.keys(): for key in data.keys():
result.append(json.loads(data[key]["data"])) result.append(json.loads(data[key]["data"]))
return result return result
def get_all_svt_programs() -> list: def get_all_svt_programs() -> list:
url = 'https://www.svtplay.se/program' url = 'https://www.svtplay.se/program'
data = get_svt_data(url) data = get_svt_data(url)
@ -352,7 +361,14 @@ def resolve_svt_channel(svt_id: str, path: str = '/usr/share/cast') -> dict:
} }
for category in get_all_svt_categories(): 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] return channels[svt_id]

Loading…
Cancel
Save