|
|
@ -7,6 +7,8 @@ import wx
|
|
|
|
import wx.lib.scrolledpanel as scrolled
|
|
|
|
import wx.lib.scrolledpanel as scrolled
|
|
|
|
import wx.media
|
|
|
|
import wx.media
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from typing import Callable
|
|
|
|
|
|
|
|
|
|
|
|
from Channel import SVT, YouTube
|
|
|
|
from Channel import SVT, YouTube
|
|
|
|
from ChannelProvider import ChannelProvider
|
|
|
|
from ChannelProvider import ChannelProvider
|
|
|
|
from Utils import make_sized_button
|
|
|
|
from Utils import make_sized_button
|
|
|
@ -16,6 +18,8 @@ HEIGHT = 1440
|
|
|
|
BTN_HEIGHT = 40
|
|
|
|
BTN_HEIGHT = 40
|
|
|
|
SPACER_HEIGHT = 10
|
|
|
|
SPACER_HEIGHT = 10
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BM_BTN_STYLE = wx.BOTTOM | wx.EXPAND | wx.LEFT | wx.TOP
|
|
|
|
|
|
|
|
|
|
|
|
class Cast(wx.Frame):
|
|
|
|
class Cast(wx.Frame):
|
|
|
|
def __init__(self, *args, **kw):
|
|
|
|
def __init__(self, *args, **kw):
|
|
|
|
"""__init__.
|
|
|
|
"""__init__.
|
|
|
@ -31,7 +35,7 @@ class Cast(wx.Frame):
|
|
|
|
)
|
|
|
|
)
|
|
|
|
self.m_chromecast_thr.start()
|
|
|
|
self.m_chromecast_thr.start()
|
|
|
|
self.m_sizer: wx.Sizer = wx.BoxSizer(wx.VERTICAL)
|
|
|
|
self.m_sizer: wx.Sizer = wx.BoxSizer(wx.VERTICAL)
|
|
|
|
self.m_panel: wx.lib.scrolledpanel.ScrolledPanel = scrolled.ScrolledPanel(
|
|
|
|
self.m_panel: wx.lib.scrolledpanel.ScrolledPanel = scrolled.ScrolledPanel( # type: ignore
|
|
|
|
self, -1, style=wx.VSCROLL
|
|
|
|
self, -1, style=wx.VSCROLL
|
|
|
|
)
|
|
|
|
)
|
|
|
|
self.m_control = None
|
|
|
|
self.m_control = None
|
|
|
@ -61,6 +65,13 @@ class Cast(wx.Frame):
|
|
|
|
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:
|
|
|
|
|
|
|
|
backbtn = wx.Button(self.m_panel, -1, label="Go back", size=(WIDTH, BTN_HEIGHT))
|
|
|
|
|
|
|
|
backbtn.Bind(
|
|
|
|
|
|
|
|
wx.EVT_BUTTON, callback
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
self.m_sizer.Add(backbtn)
|
|
|
|
|
|
|
|
|
|
|
|
def get_chromecasts(self) -> None:
|
|
|
|
def get_chromecasts(self) -> None:
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
[TODO:description]
|
|
|
|
[TODO:description]
|
|
|
@ -80,19 +91,18 @@ class Cast(wx.Frame):
|
|
|
|
self.m_sizer.Add(btn_sizer)
|
|
|
|
self.m_sizer.Add(btn_sizer)
|
|
|
|
provider_index += 1
|
|
|
|
provider_index += 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.m_panel.SetupScrolling()
|
|
|
|
self.m_panel.SetSizer(self.m_sizer)
|
|
|
|
self.m_panel.SetSizer(self.m_sizer)
|
|
|
|
self.m_sizer.Fit(self)
|
|
|
|
self.Fit()
|
|
|
|
self.m_panel.Layout()
|
|
|
|
self.Layout()
|
|
|
|
|
|
|
|
|
|
|
|
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]
|
|
|
|
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)
|
|
|
|
backbtn = wx.Button(self.m_panel, -1, label="Go back", size=(WIDTH, BTN_HEIGHT))
|
|
|
|
bck_callback = lambda event: self.show_provider_list(event)
|
|
|
|
backbtn.Bind(wx.EVT_BUTTON, lambda event: self.show_provider_list(event))
|
|
|
|
self.add_back_button(bck_callback)
|
|
|
|
self.m_sizer.Add(backbtn, wx.ALIGN_CENTER_VERTICAL)
|
|
|
|
|
|
|
|
self.m_sizer.AddSpacer(SPACER_HEIGHT)
|
|
|
|
|
|
|
|
channel_index = 0
|
|
|
|
channel_index = 0
|
|
|
|
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()
|
|
|
@ -101,21 +111,14 @@ class Cast(wx.Frame):
|
|
|
|
self.m_sizer.Add(btn_sizer)
|
|
|
|
self.m_sizer.Add(btn_sizer)
|
|
|
|
channel_index += 1
|
|
|
|
channel_index += 1
|
|
|
|
|
|
|
|
|
|
|
|
self.m_sizer.AddSpacer(SPACER_HEIGHT)
|
|
|
|
self.m_panel.SetupScrolling()
|
|
|
|
self.m_panel.SetSizer(self.m_sizer)
|
|
|
|
self.m_panel.SetSizer(self.m_sizer)
|
|
|
|
self.m_sizer.Fit(self)
|
|
|
|
self.Fit()
|
|
|
|
self.m_panel.Layout()
|
|
|
|
self.Layout()
|
|
|
|
|
|
|
|
|
|
|
|
def show_video_list(self, _, index=0) -> None:
|
|
|
|
def show_video_list(self, _, index=0) -> None:
|
|
|
|
"""
|
|
|
|
|
|
|
|
Shows a list of videos
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
:param _ [TODO:type]: [TODO:description]
|
|
|
|
|
|
|
|
:rtype None: [TODO:description]
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
|
|
|
|
channel = self.m_selected_provider.get_channel_by_index(index)
|
|
|
|
channel = self.m_selected_provider.get_channel_by_index(index)
|
|
|
|
if channel.wait():
|
|
|
|
if channel.wait():
|
|
|
|
with wx.BusyInfo("Please wait, working..."):
|
|
|
|
with wx.BusyInfo("Please wait, working..."):
|
|
|
@ -124,36 +127,35 @@ class Cast(wx.Frame):
|
|
|
|
time.sleep(1)
|
|
|
|
time.sleep(1)
|
|
|
|
wx.GetApp().Yield()
|
|
|
|
wx.GetApp().Yield()
|
|
|
|
|
|
|
|
|
|
|
|
backbtn = wx.Button(self.m_panel, -1, label="Go back", size=(WIDTH, BTN_HEIGHT))
|
|
|
|
callback = lambda event: self.show_channel_list(event, self.m_selected_provider_index)
|
|
|
|
backbtn.Bind(
|
|
|
|
self.add_back_button(callback)
|
|
|
|
wx.EVT_BUTTON,
|
|
|
|
|
|
|
|
lambda event: self.show_channel_list(event, self.m_selected_provider_index),
|
|
|
|
for item in channel.get_items(): # type: ignore
|
|
|
|
)
|
|
|
|
inner_sizer = wx.BoxSizer(wx.VERTICAL)
|
|
|
|
self.m_sizer.Add(backbtn, wx.ALIGN_CENTER_VERTICAL)
|
|
|
|
|
|
|
|
self.m_sizer.AddSpacer(SPACER_HEIGHT)
|
|
|
|
|
|
|
|
for item in channel.get_items():
|
|
|
|
|
|
|
|
title = wx.StaticText(self.m_panel, -1)
|
|
|
|
title = wx.StaticText(self.m_panel, -1)
|
|
|
|
title.SetLabelMarkup("<span weight='bold' >{}</span>".format(item["title"]))
|
|
|
|
title.SetLabelMarkup("<span weight='bold' >{}</span>".format(item["title"]))
|
|
|
|
description = wx.StaticText(self.m_panel, -1, item["description"])
|
|
|
|
description = wx.StaticText(self.m_panel, -1, item["description"])
|
|
|
|
|
|
|
|
|
|
|
|
description.Wrap(478)
|
|
|
|
description.Wrap(WIDTH -2)
|
|
|
|
bitmap = item["thumbnail"]
|
|
|
|
bitmap = item["thumbnail"]
|
|
|
|
btn = wx.BitmapButton(self.m_panel, id=self.m_index, bitmap=bitmap)
|
|
|
|
btn = wx.BitmapButton(self.m_panel, id=self.m_index, bitmap=bitmap, style= BM_BTN_STYLE)
|
|
|
|
btn.Bind(
|
|
|
|
btn.Bind(
|
|
|
|
wx.EVT_BUTTON,
|
|
|
|
wx.EVT_BUTTON,
|
|
|
|
lambda event, link=item["link"], provider_index=index: self.show_player(
|
|
|
|
lambda event, link=item["link"], provider_index=index: self.show_player(
|
|
|
|
event, link, provider_index
|
|
|
|
event, link, provider_index
|
|
|
|
),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
self.m_sizer.Add(title)
|
|
|
|
inner_sizer.Add(title)
|
|
|
|
self.m_sizer.Add(btn)
|
|
|
|
inner_sizer.Add(btn)
|
|
|
|
self.m_sizer.Add(description)
|
|
|
|
inner_sizer.Add(description)
|
|
|
|
|
|
|
|
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
|
|
|
|
self.m_index = self.m_index + 1
|
|
|
|
self.m_sizer.AddSpacer(SPACER_HEIGHT)
|
|
|
|
#self.m_sizer.AddStretchSpacer()
|
|
|
|
|
|
|
|
self.m_panel.SetupScrolling()
|
|
|
|
self.m_panel.SetSizer(self.m_sizer)
|
|
|
|
self.m_panel.SetSizer(self.m_sizer)
|
|
|
|
self.m_sizer.Fit(self)
|
|
|
|
self.Fit()
|
|
|
|
self.m_panel.Layout()
|
|
|
|
self.Layout()
|
|
|
|
|
|
|
|
|
|
|
|
def show_player(self, _, uri, provider_index: int):
|
|
|
|
def show_player(self, _, uri, provider_index: int):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
@ -166,7 +168,7 @@ class Cast(wx.Frame):
|
|
|
|
self.m_sizer = wx.GridBagSizer()
|
|
|
|
self.m_sizer = wx.GridBagSizer()
|
|
|
|
self.m_control = wx.media.MediaCtrl(
|
|
|
|
self.m_control = wx.media.MediaCtrl(
|
|
|
|
self.m_panel,
|
|
|
|
self.m_panel,
|
|
|
|
size=(WIDTH, HEIGHT),
|
|
|
|
size=(WIDTH, HEIGHT/2),
|
|
|
|
style=wx.SIMPLE_BORDER,
|
|
|
|
style=wx.SIMPLE_BORDER,
|
|
|
|
szBackend=wx.media.MEDIABACKEND_GSTREAMER,
|
|
|
|
szBackend=wx.media.MEDIABACKEND_GSTREAMER,
|
|
|
|
)
|
|
|
|
)
|
|
|
@ -209,17 +211,23 @@ class Cast(wx.Frame):
|
|
|
|
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, self.show_video_list)
|
|
|
|
self.m_sizer.AddSpacer(SPACER_HEIGHT)
|
|
|
|
|
|
|
|
self.load_uri(uri)
|
|
|
|
self.load_uri(uri)
|
|
|
|
|
|
|
|
self.m_panel.SetupScrolling()
|
|
|
|
self.m_panel.SetSizer(self.m_sizer)
|
|
|
|
self.m_panel.SetSizer(self.m_sizer)
|
|
|
|
self.m_sizer.Fit(self)
|
|
|
|
self.Fit()
|
|
|
|
self.m_panel.Layout()
|
|
|
|
self.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, provider_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)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cancel_btn = wx.Button(self.m_panel, -1, "Cancel")
|
|
|
|
|
|
|
|
cancel_btn.Bind(
|
|
|
|
|
|
|
|
wx.EVT_BUTTON,
|
|
|
|
|
|
|
|
lambda event, index=provider_index: self.show_video_list(event, index),
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
self.m_sizer.Add(cancel_btn, wx.ALIGN_CENTER_VERTICAL)
|
|
|
|
for cast in self.m_chromecasts:
|
|
|
|
for cast in self.m_chromecasts:
|
|
|
|
friendly_name = cast.cast_info.friendly_name
|
|
|
|
friendly_name = cast.cast_info.friendly_name
|
|
|
|
btn = wx.Button(self.m_panel, id=-1, label=friendly_name, size=(WIDTH, BTN_HEIGHT))
|
|
|
|
btn = wx.Button(self.m_panel, id=-1, label=friendly_name, size=(WIDTH, BTN_HEIGHT))
|
|
|
@ -230,16 +238,16 @@ class Cast(wx.Frame):
|
|
|
|
),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
self.m_sizer.Add(btn, wx.ALIGN_CENTER_VERTICAL)
|
|
|
|
self.m_sizer.Add(btn, wx.ALIGN_CENTER_VERTICAL)
|
|
|
|
self.m_sizer.AddSpacer(SPACER_HEIGHT)
|
|
|
|
self.m_panel.SetupScrolling()
|
|
|
|
self.m_panel.SetSizer(self.m_sizer)
|
|
|
|
self.m_panel.SetSizer(self.m_sizer)
|
|
|
|
self.m_sizer.Fit(self)
|
|
|
|
self.Fit()
|
|
|
|
self.m_panel.Layout()
|
|
|
|
self.Layout()
|
|
|
|
|
|
|
|
|
|
|
|
def set_chromecast(self, event, chromecast, uri, provider_index):
|
|
|
|
def set_chromecast(self, event, chromecast, uri, provider_index):
|
|
|
|
self.m_selected_chromecast = chromecast
|
|
|
|
self.m_selected_chromecast = chromecast
|
|
|
|
self.show_player(event, uri, provider_index)
|
|
|
|
self.show_player(event, uri, provider_index)
|
|
|
|
|
|
|
|
|
|
|
|
def cast(self, event, uri):
|
|
|
|
def cast(self, _, uri):
|
|
|
|
mimetype = "video/mp4"
|
|
|
|
mimetype = "video/mp4"
|
|
|
|
cast = self.m_selected_chromecast
|
|
|
|
cast = self.m_selected_chromecast
|
|
|
|
cast.wait()
|
|
|
|
cast.wait()
|
|
|
|