From f6fe4f143bbb6f32cabfbe6c5d67fbb636c64b17 Mon Sep 17 00:00:00 2001 From: Micke Nordin Date: Sat, 8 Jan 2022 23:16:26 +0100 Subject: [PATCH] Add refresh buttons --- src/Channel/__init__.py | 3 +++ src/main.py | 34 +++++++++++++++++++++++++++++----- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/src/Channel/__init__.py b/src/Channel/__init__.py index d257d88..0988394 100644 --- a/src/Channel/__init__.py +++ b/src/Channel/__init__.py @@ -51,3 +51,6 @@ class Channel: def set_logo(self, logo: wx.Bitmap) -> None: self.m_logo = logo + + def refresh(self) -> None: + pass diff --git a/src/main.py b/src/main.py index 624a089..56d14aa 100644 --- a/src/main.py +++ b/src/main.py @@ -110,7 +110,9 @@ class Cast(wx.Frame): import_from_newpipe(subfile) subscriptions = get_subscriptions() for channel in subscriptions: - channels.append(YouTube.YouTube(channel[0], channel[1])) + yt_chan = YouTube.YouTube(channel[0], channel[1]) + yt_chan.refresh() + channels.append(yt_chan) self.m_providers[1].set_channels(channels) self.m_providers[1].make_latest() self.show_channel_list(None,self.m_selected_provider_index) @@ -178,18 +180,40 @@ class Cast(wx.Frame): self.m_sizer = wx.BoxSizer(wx.VERTICAL) # self.m_sizer.AddSpacer(SPACER_HEIGHT * 4) channel = self.m_selected_provider.get_channel_by_index(index) + def refresh_callback(event): + if self.m_selected_provider_index == 1 and index == 0: + with wx.BusyInfo("Please wait, working..."): + for chan in self.m_selected_provider.get_channels(): + chan.refresh() + wait = 1 + while wait > 0: + wait = 0 + for chan in self.m_selected_provider.get_channels(): + if chan.wait(): + wait += 1 + time.sleep(1) + wx.GetApp().Yield() + else: + channel.refresh() + self.show_video_list(event,index ) + + refreshbtn = wx.Button(self.m_panel, + -1, + label="Refresh", + size=(WIDTH, BTN_HEIGHT)) + refreshbtn.Bind(wx.EVT_BUTTON, refresh_callback) + self.m_sizer.Add(refreshbtn) if channel.wait(): with wx.BusyInfo("Please wait, working..."): - index = 0 - while channel.wait(): time.sleep(1) wx.GetApp().Yield() - callback = lambda event: self.show_channel_list( + back_callback = lambda event: self.show_channel_list( event, self.m_selected_provider_index) - self.add_back_button(callback) + self.add_back_button(back_callback) + for item in channel.get_items(): # type: ignore inner_sizer = wx.BoxSizer(wx.VERTICAL)