Working categories. still not really usable
This commit is contained in:
parent
30544ac026
commit
4f719ac781
3 changed files with 116 additions and 40 deletions
42
scripts/cast
Normal file → Executable file
42
scripts/cast
Normal file → Executable file
|
@ -12,7 +12,8 @@ from vlc import Instance
|
||||||
|
|
||||||
from Channel import SVT
|
from Channel import SVT
|
||||||
from ChannelProvider import ChannelProvider
|
from ChannelProvider import ChannelProvider
|
||||||
from Utils import make_bitmap_from_file, make_sized_button
|
from Utils import (get_all_svt_categories, make_bitmap_from_file,
|
||||||
|
make_sized_button)
|
||||||
|
|
||||||
WIDTH = int(720 / 2)
|
WIDTH = int(720 / 2)
|
||||||
HEIGHT = int(1440 / 2)
|
HEIGHT = int(1440 / 2)
|
||||||
|
@ -28,6 +29,7 @@ FLAGS.Center()
|
||||||
|
|
||||||
|
|
||||||
class Cast(wx.Frame):
|
class Cast(wx.Frame):
|
||||||
|
|
||||||
def __init__(self, *args, **kw):
|
def __init__(self, *args, **kw):
|
||||||
"""__init__.
|
"""__init__.
|
||||||
:param args:
|
:param args:
|
||||||
|
@ -117,7 +119,8 @@ class Cast(wx.Frame):
|
||||||
|
|
||||||
if not self.m_chromecast_thr.is_alive(
|
if not self.m_chromecast_thr.is_alive(
|
||||||
) and not self.m_selected_chromecast:
|
) and not self.m_selected_chromecast:
|
||||||
btm = make_bitmap_from_file('{}/assets/Cast.png'.format(self.asset_path), wx.Size(24,24))
|
btm = make_bitmap_from_file(
|
||||||
|
'{}/assets/Cast.png'.format(self.asset_path), wx.Size(24, 24))
|
||||||
cast_button = wx.BitmapButton(self.m_panel,
|
cast_button = wx.BitmapButton(self.m_panel,
|
||||||
-1,
|
-1,
|
||||||
bitmap=btm,
|
bitmap=btm,
|
||||||
|
@ -129,7 +132,6 @@ class Cast(wx.Frame):
|
||||||
)
|
)
|
||||||
inner_sizer.Add(cast_button, FLAGS)
|
inner_sizer.Add(cast_button, FLAGS)
|
||||||
|
|
||||||
|
|
||||||
if self.m_selected_chromecast:
|
if self.m_selected_chromecast:
|
||||||
self.cast(wx.media.EVT_MEDIA_LOADED, uri),
|
self.cast(wx.media.EVT_MEDIA_LOADED, uri),
|
||||||
play_button.Bind(wx.EVT_BUTTON, self.play_cast)
|
play_button.Bind(wx.EVT_BUTTON, self.play_cast)
|
||||||
|
@ -153,24 +155,22 @@ class Cast(wx.Frame):
|
||||||
def get_providers(self) -> list[ChannelProvider]:
|
def get_providers(self) -> list[ChannelProvider]:
|
||||||
|
|
||||||
providers = list()
|
providers = list()
|
||||||
svt = ChannelProvider(
|
channels: list = list()
|
||||||
"SVT",
|
ids = [
|
||||||
channels=[
|
"feed", "ch-svt1", "ch-svt2", "ch-svt24", "ch-barnkanalen",
|
||||||
SVT.SVT("feed"),
|
"ch-kunskapskanalen", "allprograms"
|
||||||
SVT.SVT("ch-svt1"),
|
]
|
||||||
SVT.SVT("ch-svt2"),
|
|
||||||
SVT.SVT("ch-svt24"),
|
for category in get_all_svt_categories():
|
||||||
SVT.SVT("ch-barnkanalen"),
|
ids.append(category['id'])
|
||||||
SVT.SVT("ch-kunskapskanalen"),
|
for id in ids:
|
||||||
SVT.SVT("allprograms"),
|
channels.append(SVT.SVT(id))
|
||||||
],
|
svt = ChannelProvider("SVT", channels=channels)
|
||||||
)
|
|
||||||
|
|
||||||
providers.append(svt)
|
providers.append(svt)
|
||||||
|
|
||||||
return providers
|
return providers
|
||||||
|
|
||||||
|
|
||||||
def show_channel_list(self, _, provider_index) -> None:
|
def show_channel_list(self, _, provider_index) -> None:
|
||||||
self.m_selected_provider_index = provider_index
|
self.m_selected_provider_index = provider_index
|
||||||
self.m_selected_provider = self.m_providers[provider_index]
|
self.m_selected_provider = self.m_providers[provider_index]
|
||||||
|
@ -209,7 +209,11 @@ class Cast(wx.Frame):
|
||||||
back_callback = lambda event: self.show_channel_list(
|
back_callback = lambda event: self.show_channel_list(
|
||||||
event, self.m_selected_provider_index)
|
event, self.m_selected_provider_index)
|
||||||
self.add_back_button(back_callback)
|
self.add_back_button(back_callback)
|
||||||
if self.m_selected_provider.get_name() == 'SVT' and self.m_selected_channel.get_id() == 'feed':
|
if self.m_selected_provider.get_name(
|
||||||
|
) == 'SVT' and self.m_selected_channel.get_id() not in [
|
||||||
|
"ch-svt1", "ch-svt2", "ch-svt24", "ch-barnkanalen",
|
||||||
|
"ch-kunskapskanalen"
|
||||||
|
]:
|
||||||
|
|
||||||
def refresh_callback(event):
|
def refresh_callback(event):
|
||||||
self.m_selected_channel.refresh()
|
self.m_selected_channel.refresh()
|
||||||
|
@ -224,9 +228,13 @@ class Cast(wx.Frame):
|
||||||
|
|
||||||
if self.m_selected_channel.wait():
|
if self.m_selected_channel.wait():
|
||||||
with wx.BusyInfo("Please wait, working..."):
|
with wx.BusyInfo("Please wait, working..."):
|
||||||
|
number_of_waits = 0
|
||||||
while self.m_selected_channel.wait():
|
while self.m_selected_channel.wait():
|
||||||
|
number_of_waits += 1
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
wx.GetApp().Yield()
|
wx.GetApp().Yield()
|
||||||
|
if number_of_waits > 10:
|
||||||
|
break
|
||||||
|
|
||||||
btnindex = 0
|
btnindex = 0
|
||||||
for item in self.m_selected_channel.get_items(): # type: ignore
|
for item in self.m_selected_channel.get_items(): # type: ignore
|
||||||
|
|
|
@ -9,7 +9,9 @@ import wx
|
||||||
|
|
||||||
from Channel import Channel
|
from Channel import Channel
|
||||||
from Items import Item
|
from Items import Item
|
||||||
from Utils import (add_video, get_all_svt_programs, get_svt_id, get_svt_thumbnail, hash_string, make_bitmap_from_url,
|
from Utils import (add_video, get_all_svt_categories, get_all_svt_programs,
|
||||||
|
get_svt_category, get_svt_id, get_svt_thumb_from_id_changed,
|
||||||
|
get_svt_thumbnail, hash_string, make_bitmap_from_url,
|
||||||
resolve_svt_channel, video_exists)
|
resolve_svt_channel, video_exists)
|
||||||
|
|
||||||
default_rss_url = 'http://www.svtplay.se/rss.xml'
|
default_rss_url = 'http://www.svtplay.se/rss.xml'
|
||||||
|
@ -31,6 +33,9 @@ class SVT(Channel):
|
||||||
thumbnail: wx.Bitmap = wx.Bitmap()
|
thumbnail: wx.Bitmap = wx.Bitmap()
|
||||||
published_parsed: datetime = datetime.now()
|
published_parsed: datetime = datetime.now()
|
||||||
video_id = str()
|
video_id = str()
|
||||||
|
categories: dict = dict()
|
||||||
|
for category in get_all_svt_categories():
|
||||||
|
categories[category['id']] = category
|
||||||
|
|
||||||
if self.m_id == 'feed':
|
if self.m_id == 'feed':
|
||||||
feed = feedparser.parse(self.get_feed())
|
feed = feedparser.parse(self.get_feed())
|
||||||
|
@ -80,17 +85,47 @@ class SVT(Channel):
|
||||||
swe_only = "no"
|
swe_only = "no"
|
||||||
if entry['item']['restrictions']['onlyAvailableInSweden']:
|
if entry['item']['restrictions']['onlyAvailableInSweden']:
|
||||||
swe_only = 'yes'
|
swe_only = 'yes'
|
||||||
description = "{}\nOnly available in Sweden:{}\nType of program:{}".format(title, swe_only, type)
|
description = "{}\nOnly available in Sweden:{}\nType of program:{}".format(
|
||||||
|
title, swe_only, type)
|
||||||
if not resolved_link:
|
if not resolved_link:
|
||||||
continue
|
continue
|
||||||
thumbnail = make_bitmap_from_url(
|
thumbnail = make_bitmap_from_url(
|
||||||
thumbnail_link, wx.Size(int(self.m_screen_width), 150))
|
thumbnail_link, wx.Size(int(self.m_screen_width), 150))
|
||||||
item = Item(description, resolved_link, self.m_provider_name,
|
item = Item(description,
|
||||||
published_parsed, thumbnail, title, sort_key = entry['selection_name'])
|
resolved_link,
|
||||||
|
self.m_provider_name,
|
||||||
|
published_parsed,
|
||||||
|
thumbnail,
|
||||||
|
title,
|
||||||
|
sort_key=entry['selection_name'])
|
||||||
self.m_items.append(item)
|
self.m_items.append(item)
|
||||||
add_video(video_id, self.m_id, self.m_provider_name,
|
add_video(video_id, self.m_id, self.m_provider_name,
|
||||||
description, resolved_link, published_parsed,
|
description, resolved_link, published_parsed,
|
||||||
thumbnail, title, 0)
|
thumbnail, title, 0)
|
||||||
|
elif self.m_id in categories.keys():
|
||||||
|
entries = get_svt_category(self.m_id)
|
||||||
|
for entry in entries:
|
||||||
|
elem = entry["item"]
|
||||||
|
svt_id = elem["videoSvtId"]
|
||||||
|
resolved_link = self.resolve_link(svt_id)
|
||||||
|
if not resolved_link:
|
||||||
|
continue
|
||||||
|
title = str(entry['heading'])
|
||||||
|
description = str(entry["description"])
|
||||||
|
published_parsed = datetime.now()
|
||||||
|
thumbnail_link = get_svt_thumb_from_id_changed(
|
||||||
|
elem['images']["wide"]["id"],
|
||||||
|
elem['images']["wide"]["changed"],
|
||||||
|
size=self.m_screen_width)
|
||||||
|
thumbnail = make_bitmap_from_url(
|
||||||
|
thumbnail_link, wx.Size(int(self.m_screen_width), 150))
|
||||||
|
item = Item(description, resolved_link, self.m_provider_name,
|
||||||
|
published_parsed, thumbnail, title)
|
||||||
|
self.m_items.append(item)
|
||||||
|
add_video(video_id, self.m_id, self.m_provider_name,
|
||||||
|
description, resolved_link, published_parsed,
|
||||||
|
thumbnail, title, 0)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
chan_dict = resolve_svt_channel(self.m_id)
|
chan_dict = resolve_svt_channel(self.m_id)
|
||||||
resolved_link = self.resolve_link(self.m_id)
|
resolved_link = self.resolve_link(self.m_id)
|
||||||
|
|
|
@ -68,22 +68,52 @@ 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_all_svt_categories() -> list:
|
||||||
|
categories: list = list()
|
||||||
|
url = "https://www.svtplay.se/kategori"
|
||||||
|
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()
|
||||||
|
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
|
||||||
|
return programs
|
||||||
|
|
||||||
|
def get_svt_data(url: str) -> 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"]
|
||||||
|
for key in data.keys():
|
||||||
|
result.append(json.loads(data[key]["data"]))
|
||||||
|
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)
|
||||||
res = requests.get(url)
|
|
||||||
soup = BeautifulSoup(res.text, features="lxml")
|
|
||||||
data = json.loads(
|
|
||||||
soup.find(id="__NEXT_DATA__").string)["props"]["urqlState"]
|
|
||||||
programs = list()
|
programs = list()
|
||||||
for key in data.keys():
|
for entry in data:
|
||||||
temp = json.loads(data[key]["data"])
|
if "programAtillO" in entry.keys():
|
||||||
if "programAtillO" in temp.keys():
|
for selection in entry["programAtillO"]["selections"]:
|
||||||
for selection in temp["programAtillO"]["selections"]:
|
|
||||||
for item in selection["items"]:
|
for item in selection["items"]:
|
||||||
item['selection_name'] = selection['name']
|
item['selection_name'] = selection['name']
|
||||||
programs.append(item)
|
programs.append(item)
|
||||||
|
break
|
||||||
|
|
||||||
return programs
|
return programs
|
||||||
|
|
||||||
|
@ -321,6 +351,9 @@ 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']))}
|
||||||
|
|
||||||
return channels[svt_id]
|
return channels[svt_id]
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue