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