|
|
@ -34,7 +34,6 @@ class Cast(wx.Frame):
|
|
|
|
super().__init__(*args, **kw)
|
|
|
|
super().__init__(*args, **kw)
|
|
|
|
self.m_selected_chromecast = None
|
|
|
|
self.m_selected_chromecast = None
|
|
|
|
self.SetSizeHints(WIDTH, HEIGHT, maxW=WIDTH)
|
|
|
|
self.SetSizeHints(WIDTH, HEIGHT, maxW=WIDTH)
|
|
|
|
self.m_index = 0
|
|
|
|
|
|
|
|
self.m_chromecast_thr = threading.Thread(target=self.get_chromecasts,
|
|
|
|
self.m_chromecast_thr = threading.Thread(target=self.get_chromecasts,
|
|
|
|
args=(),
|
|
|
|
args=(),
|
|
|
|
kwargs={})
|
|
|
|
kwargs={})
|
|
|
@ -46,8 +45,8 @@ class Cast(wx.Frame):
|
|
|
|
self.m_panel.SetupScrolling(rate_y=SCROLL_RATE, scrollToTop=True)
|
|
|
|
self.m_panel.SetupScrolling(rate_y=SCROLL_RATE, scrollToTop=True)
|
|
|
|
self.m_panel.SetSizer(self.m_sizer)
|
|
|
|
self.m_panel.SetSizer(self.m_sizer)
|
|
|
|
self.m_providers: list[ChannelProvider] = self.get_providers()
|
|
|
|
self.m_providers: list[ChannelProvider] = self.get_providers()
|
|
|
|
self.m_selected_channel = None
|
|
|
|
# self.m_selected_channel = None
|
|
|
|
self.m_selected_provider_index = None
|
|
|
|
# self.m_selected_provider_index = None
|
|
|
|
self.show_provider_list(None)
|
|
|
|
self.show_provider_list(None)
|
|
|
|
|
|
|
|
|
|
|
|
def add_back_button(self, callback: Callable) -> None:
|
|
|
|
def add_back_button(self, callback: Callable) -> None:
|
|
|
@ -131,8 +130,8 @@ class Cast(wx.Frame):
|
|
|
|
|
|
|
|
|
|
|
|
for provider in self.m_providers:
|
|
|
|
for provider in self.m_providers:
|
|
|
|
bitmap = provider.get_logo_as_bitmap()
|
|
|
|
bitmap = provider.get_logo_as_bitmap()
|
|
|
|
callback = lambda event, index=provider_index: self.show_channel_list(
|
|
|
|
callback = lambda event, pindex=provider_index: self.show_channel_list(
|
|
|
|
event, index)
|
|
|
|
event, pindex)
|
|
|
|
btn_sizer: wx.BoxSizer = make_sized_button(self.m_panel, bitmap,
|
|
|
|
btn_sizer: wx.BoxSizer = make_sized_button(self.m_panel, bitmap,
|
|
|
|
provider.get_name(),
|
|
|
|
provider.get_name(),
|
|
|
|
callback)
|
|
|
|
callback)
|
|
|
@ -162,8 +161,8 @@ class Cast(wx.Frame):
|
|
|
|
|
|
|
|
|
|
|
|
for channel in self.m_selected_provider.get_channels():
|
|
|
|
for channel in self.m_selected_provider.get_channels():
|
|
|
|
bitmap = channel.get_logo_as_bitmap()
|
|
|
|
bitmap = channel.get_logo_as_bitmap()
|
|
|
|
callback = lambda event, index=channel_index: self.show_video_list(
|
|
|
|
callback = lambda event, cindex=channel_index: self.show_video_list(
|
|
|
|
event, index)
|
|
|
|
event, cindex)
|
|
|
|
btn_sizer: wx.BoxSizer = make_sized_button(self.m_panel, bitmap,
|
|
|
|
btn_sizer: wx.BoxSizer = make_sized_button(self.m_panel, bitmap,
|
|
|
|
channel.get_name(),
|
|
|
|
channel.get_name(),
|
|
|
|
callback)
|
|
|
|
callback)
|
|
|
@ -175,47 +174,48 @@ class Cast(wx.Frame):
|
|
|
|
self.m_sizer.Fit(self)
|
|
|
|
self.m_sizer.Fit(self)
|
|
|
|
self.m_sizer.Layout()
|
|
|
|
self.m_sizer.Layout()
|
|
|
|
|
|
|
|
|
|
|
|
def show_video_list(self, _, index=0) -> None:
|
|
|
|
def show_video_list(self, _,channel_index) -> None:
|
|
|
|
|
|
|
|
self.m_selected_channel = self.m_selected_provider.get_channel_by_index(channel_index)
|
|
|
|
self.m_sizer.Clear(delete_windows=True)
|
|
|
|
self.m_sizer.Clear(delete_windows=True)
|
|
|
|
self.m_sizer = wx.BoxSizer(wx.VERTICAL)
|
|
|
|
self.m_sizer = wx.BoxSizer(wx.VERTICAL)
|
|
|
|
# self.m_sizer.AddSpacer(SPACER_HEIGHT * 4)
|
|
|
|
# self.m_sizer.AddSpacer(SPACER_HEIGHT * 4)
|
|
|
|
channel = self.m_selected_provider.get_channel_by_index(index)
|
|
|
|
back_callback = lambda event: self.show_channel_list(
|
|
|
|
def refresh_callback(event):
|
|
|
|
event, self.m_selected_provider_index)
|
|
|
|
if self.m_selected_provider_index == 1 and index == 0:
|
|
|
|
self.add_back_button(back_callback)
|
|
|
|
with wx.BusyInfo("Please wait, working..."):
|
|
|
|
if self.m_selected_provider.get_name() == 'YouTube' or (self.m_selected_provider.get_name() == 'SVT' and self.m_selected_channel.get_id() == 'feed'):
|
|
|
|
for chan in self.m_selected_provider.get_channels():
|
|
|
|
def refresh_callback(event):
|
|
|
|
chan.refresh()
|
|
|
|
if self.m_selected_provider.get_name() == 'YouTube' and channel_index == 0:
|
|
|
|
wait = 1
|
|
|
|
with wx.BusyInfo("Please wait, working..."):
|
|
|
|
while wait > 0:
|
|
|
|
|
|
|
|
wait = 0
|
|
|
|
|
|
|
|
for chan in self.m_selected_provider.get_channels():
|
|
|
|
for chan in self.m_selected_provider.get_channels():
|
|
|
|
if chan.wait():
|
|
|
|
chan.refresh()
|
|
|
|
wait += 1
|
|
|
|
wait = 1
|
|
|
|
time.sleep(1)
|
|
|
|
while wait > 0:
|
|
|
|
wx.GetApp().Yield()
|
|
|
|
wait = 0
|
|
|
|
else:
|
|
|
|
for chan in self.m_selected_provider.get_channels():
|
|
|
|
channel.refresh()
|
|
|
|
if chan.wait():
|
|
|
|
self.show_video_list(event,index )
|
|
|
|
wait += 1
|
|
|
|
|
|
|
|
time.sleep(1)
|
|
|
|
refreshbtn = wx.Button(self.m_panel,
|
|
|
|
wx.GetApp().Yield()
|
|
|
|
-1,
|
|
|
|
else:
|
|
|
|
label="Refresh",
|
|
|
|
self.m_selected_channel.refresh()
|
|
|
|
size=(WIDTH, BTN_HEIGHT))
|
|
|
|
self.show_video_list(event,channel_index)
|
|
|
|
refreshbtn.Bind(wx.EVT_BUTTON, refresh_callback)
|
|
|
|
|
|
|
|
self.m_sizer.Add(refreshbtn)
|
|
|
|
refreshbtn = wx.Button(self.m_panel,
|
|
|
|
|
|
|
|
-1,
|
|
|
|
if channel.wait():
|
|
|
|
label="Refresh",
|
|
|
|
|
|
|
|
size=(WIDTH, BTN_HEIGHT))
|
|
|
|
|
|
|
|
refreshbtn.Bind(wx.EVT_BUTTON, refresh_callback)
|
|
|
|
|
|
|
|
self.m_sizer.Add(refreshbtn)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if self.m_selected_channel.wait():
|
|
|
|
with wx.BusyInfo("Please wait, working..."):
|
|
|
|
with wx.BusyInfo("Please wait, working..."):
|
|
|
|
while channel.wait():
|
|
|
|
while self.m_selected_channel.wait():
|
|
|
|
time.sleep(1)
|
|
|
|
time.sleep(1)
|
|
|
|
wx.GetApp().Yield()
|
|
|
|
wx.GetApp().Yield()
|
|
|
|
|
|
|
|
|
|
|
|
back_callback = lambda event: self.show_channel_list(
|
|
|
|
|
|
|
|
event, self.m_selected_provider_index)
|
|
|
|
|
|
|
|
self.add_back_button(back_callback)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for item in channel.get_items(): # type: ignore
|
|
|
|
btnindex = 0
|
|
|
|
|
|
|
|
for item in self.m_selected_channel.get_items(): # type: ignore
|
|
|
|
inner_sizer = wx.BoxSizer(wx.VERTICAL)
|
|
|
|
inner_sizer = wx.BoxSizer(wx.VERTICAL)
|
|
|
|
pane_sizer = wx.BoxSizer(wx.VERTICAL)
|
|
|
|
pane_sizer = wx.BoxSizer(wx.VERTICAL)
|
|
|
|
title = wx.StaticText(self.m_panel, -1)
|
|
|
|
title = wx.StaticText(self.m_panel, -1)
|
|
|
@ -224,13 +224,13 @@ class Cast(wx.Frame):
|
|
|
|
|
|
|
|
|
|
|
|
bitmap = item["thumbnail"]
|
|
|
|
bitmap = item["thumbnail"]
|
|
|
|
btn = wx.BitmapButton(self.m_panel,
|
|
|
|
btn = wx.BitmapButton(self.m_panel,
|
|
|
|
id=self.m_index,
|
|
|
|
id=btnindex,
|
|
|
|
bitmap=bitmap,
|
|
|
|
bitmap=bitmap,
|
|
|
|
style=BM_BTN_STYLE)
|
|
|
|
style=BM_BTN_STYLE)
|
|
|
|
btn.Bind(
|
|
|
|
btn.Bind(
|
|
|
|
wx.EVT_BUTTON,
|
|
|
|
wx.EVT_BUTTON,
|
|
|
|
lambda event, link=item["link"], provider_index=index: self.
|
|
|
|
lambda event, link=item["link"], cindex=channel_index: self.
|
|
|
|
show_player(event, link, provider_index),
|
|
|
|
show_player(event, link, cindex),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
inner_sizer.Add(title)
|
|
|
|
inner_sizer.Add(title)
|
|
|
|
inner_sizer.Add(btn)
|
|
|
|
inner_sizer.Add(btn)
|
|
|
@ -256,13 +256,13 @@ class Cast(wx.Frame):
|
|
|
|
#inner_sizer.Add(description)
|
|
|
|
#inner_sizer.Add(description)
|
|
|
|
self.m_sizer.Add(inner_sizer)
|
|
|
|
self.m_sizer.Add(inner_sizer)
|
|
|
|
self.m_sizer.AddSpacer(SPACER_HEIGHT)
|
|
|
|
self.m_sizer.AddSpacer(SPACER_HEIGHT)
|
|
|
|
self.m_index = self.m_index + 1
|
|
|
|
btnindex = btnindex + 1
|
|
|
|
self.m_panel.SetupScrolling(rate_y=SCROLL_RATE, scrollToTop=True)
|
|
|
|
self.m_panel.SetupScrolling(rate_y=SCROLL_RATE, scrollToTop=True)
|
|
|
|
self.m_panel.SetSizer(self.m_sizer)
|
|
|
|
self.m_panel.SetSizer(self.m_sizer)
|
|
|
|
self.m_sizer.Fit(self)
|
|
|
|
self.m_sizer.Fit(self)
|
|
|
|
self.m_sizer.Layout()
|
|
|
|
self.m_sizer.Layout()
|
|
|
|
|
|
|
|
|
|
|
|
def show_player(self, _, uri, provider_index: int):
|
|
|
|
def show_player(self, _, uri, channel_index: int):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
Show the video player
|
|
|
|
Show the video player
|
|
|
|
|
|
|
|
|
|
|
@ -286,8 +286,7 @@ class Cast(wx.Frame):
|
|
|
|
back_button = wx.Button(self.m_panel, -1, "Back")
|
|
|
|
back_button = wx.Button(self.m_panel, -1, "Back")
|
|
|
|
back_button.Bind(
|
|
|
|
back_button.Bind(
|
|
|
|
wx.EVT_BUTTON,
|
|
|
|
wx.EVT_BUTTON,
|
|
|
|
lambda event, index=provider_index: self.show_video_list(
|
|
|
|
lambda event, cindex=channel_index: self.show_video_list(event, cindex),
|
|
|
|
event, index),
|
|
|
|
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
inner_sizer.Add(self.m_control, (0, 0))
|
|
|
|
inner_sizer.Add(self.m_control, (0, 0))
|
|
|
@ -301,8 +300,7 @@ class Cast(wx.Frame):
|
|
|
|
chromecast_button = wx.Button(self.m_panel, -1, "Cast")
|
|
|
|
chromecast_button = wx.Button(self.m_panel, -1, "Cast")
|
|
|
|
chromecast_button.Bind(
|
|
|
|
chromecast_button.Bind(
|
|
|
|
wx.EVT_BUTTON,
|
|
|
|
wx.EVT_BUTTON,
|
|
|
|
lambda event, muri=uri, index=provider_index: self.
|
|
|
|
lambda event, muri=uri, cindex=channel_index: self.select_chromecast(event, muri, cindex),
|
|
|
|
select_chromecast(event, muri, index),
|
|
|
|
|
|
|
|
)
|
|
|
|
)
|
|
|
|
inner_sizer.Add(chromecast_button, (2, 2))
|
|
|
|
inner_sizer.Add(chromecast_button, (2, 2))
|
|
|
|
self.m_sizer.Add(inner_sizer)
|
|
|
|
self.m_sizer.Add(inner_sizer)
|
|
|
@ -319,7 +317,7 @@ class Cast(wx.Frame):
|
|
|
|
play_button.Bind(wx.EVT_BUTTON, self.play)
|
|
|
|
play_button.Bind(wx.EVT_BUTTON, self.play)
|
|
|
|
pause_button.Bind(wx.EVT_BUTTON, self.pause)
|
|
|
|
pause_button.Bind(wx.EVT_BUTTON, self.pause)
|
|
|
|
|
|
|
|
|
|
|
|
self.Bind(wx.media.EVT_MEDIA_FINISHED, self.show_video_list)
|
|
|
|
self.Bind(wx.media.EVT_MEDIA_FINISHED, lambda event: self.show_video_list(event,0))
|
|
|
|
self.load_uri(uri)
|
|
|
|
self.load_uri(uri)
|
|
|
|
self.m_panel.SetupScrolling(rate_y=SCROLL_RATE, scrollToTop=True)
|
|
|
|
self.m_panel.SetupScrolling(rate_y=SCROLL_RATE, scrollToTop=True)
|
|
|
|
self.m_panel.SetSizer(self.m_sizer)
|
|
|
|
self.m_panel.SetSizer(self.m_sizer)
|
|
|
@ -327,7 +325,7 @@ class Cast(wx.Frame):
|
|
|
|
self.m_sizer.Layout()
|
|
|
|
self.m_sizer.Layout()
|
|
|
|
self.m_panel.ScrollChildIntoView(self.m_control)
|
|
|
|
self.m_panel.ScrollChildIntoView(self.m_control)
|
|
|
|
|
|
|
|
|
|
|
|
def select_chromecast(self, _, uri, provider_index):
|
|
|
|
def select_chromecast(self, _, uri, channel_index):
|
|
|
|
self.m_sizer.Clear(delete_windows=True)
|
|
|
|
self.m_sizer.Clear(delete_windows=True)
|
|
|
|
self.m_sizer = wx.BoxSizer(wx.VERTICAL)
|
|
|
|
self.m_sizer = wx.BoxSizer(wx.VERTICAL)
|
|
|
|
# self.m_sizer.AddSpacer(SPACER_HEIGHT * 4)
|
|
|
|
# self.m_sizer.AddSpacer(SPACER_HEIGHT * 4)
|
|
|
@ -339,8 +337,8 @@ class Cast(wx.Frame):
|
|
|
|
style=wx.BU_EXACTFIT)
|
|
|
|
style=wx.BU_EXACTFIT)
|
|
|
|
cancel_btn.Bind(
|
|
|
|
cancel_btn.Bind(
|
|
|
|
wx.EVT_BUTTON,
|
|
|
|
wx.EVT_BUTTON,
|
|
|
|
lambda event, index=provider_index: self.show_video_list(
|
|
|
|
lambda event, cindex=channel_index: self.show_video_list(
|
|
|
|
event, index),
|
|
|
|
event, cindex),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
self.m_sizer.Add(cancel_btn) #, wx.ALIGN_CENTER_VERTICAL)
|
|
|
|
self.m_sizer.Add(cancel_btn) #, wx.ALIGN_CENTER_VERTICAL)
|
|
|
|
|
|
|
|
|
|
|
@ -352,8 +350,8 @@ class Cast(wx.Frame):
|
|
|
|
size=(WIDTH, BTN_HEIGHT))
|
|
|
|
size=(WIDTH, BTN_HEIGHT))
|
|
|
|
btn.Bind(
|
|
|
|
btn.Bind(
|
|
|
|
wx.EVT_BUTTON,
|
|
|
|
wx.EVT_BUTTON,
|
|
|
|
lambda event, chromecast=cast, muri=uri, index=provider_index:
|
|
|
|
lambda event, chromecast=cast, muri=uri, cindex=channel_index:
|
|
|
|
self.set_chromecast(event, chromecast, muri, index),
|
|
|
|
self.set_chromecast(event, chromecast, muri, cindex),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
self.m_sizer.Add(btn) #, wx.ALIGN_CENTER_VERTICAL)
|
|
|
|
self.m_sizer.Add(btn) #, wx.ALIGN_CENTER_VERTICAL)
|
|
|
|
self.m_panel.SetupScrolling(rate_y=SCROLL_RATE, scrollToTop=True)
|
|
|
|
self.m_panel.SetupScrolling(rate_y=SCROLL_RATE, scrollToTop=True)
|
|
|
@ -361,9 +359,9 @@ class Cast(wx.Frame):
|
|
|
|
self.m_sizer.Fit(self)
|
|
|
|
self.m_sizer.Fit(self)
|
|
|
|
self.m_sizer.Layout()
|
|
|
|
self.m_sizer.Layout()
|
|
|
|
|
|
|
|
|
|
|
|
def set_chromecast(self, event, chromecast, uri, provider_index):
|
|
|
|
def set_chromecast(self, event, chromecast, uri, channel_index):
|
|
|
|
self.m_selected_chromecast = chromecast
|
|
|
|
self.m_selected_chromecast = chromecast
|
|
|
|
self.show_player(event, uri, provider_index)
|
|
|
|
self.show_player(event, uri, channel_index)
|
|
|
|
|
|
|
|
|
|
|
|
def cast(self, _, uri):
|
|
|
|
def cast(self, _, uri):
|
|
|
|
mimetype = "video/mp4"
|
|
|
|
mimetype = "video/mp4"
|
|
|
@ -377,7 +375,7 @@ class Cast(wx.Frame):
|
|
|
|
while True:
|
|
|
|
while True:
|
|
|
|
if player_state != cast.media_controller.status.player_state:
|
|
|
|
if player_state != cast.media_controller.status.player_state:
|
|
|
|
player_state = cast.media_controller.status.player_state
|
|
|
|
player_state = cast.media_controller.status.player_state
|
|
|
|
print("Player state:", player_state)
|
|
|
|
# print("Player state:", player_state)
|
|
|
|
|
|
|
|
|
|
|
|
if player_state == "PLAYING":
|
|
|
|
if player_state == "PLAYING":
|
|
|
|
has_played = True
|
|
|
|
has_played = True
|
|
|
|