diff --git a/src/ChannelProvider/__init__.py b/src/ChannelProvider/__init__.py index 6eeebea..878b6b0 100644 --- a/src/ChannelProvider/__init__.py +++ b/src/ChannelProvider/__init__.py @@ -49,3 +49,6 @@ class ChannelProvider: def prepend_channel(self, channel: Channel) -> int: self.m_channels.insert(0, channel) return len(self.m_channels) + + def set_channels(self, channels: list[Channel]) -> None: + self.m_channels = channels diff --git a/src/main.py b/src/main.py index 13aa9a3..e022937 100644 --- a/src/main.py +++ b/src/main.py @@ -95,6 +95,25 @@ class Cast(wx.Frame): return providers + def show_importer(self, _) -> None: + + with wx.FileDialog(self, "Open Newpipe json file", wildcard="Json files (*.json)|*.json", + style=wx.FD_OPEN | wx.FD_FILE_MUST_EXIST) as file_dialog: + + if file_dialog.ShowModal() == wx.ID_CANCEL: + return # the user changed their mind + + # Proceed loading the file chosen by the user + subfile = file_dialog.GetPath() + channels = list() + if os.path.isfile(subfile): + import_from_newpipe(subfile) + subscriptions = get_subscriptions() + for channel in subscriptions: + channels.append(YouTube.YouTube(channel[0], channel[1])) + self.m_providers[1].set_channels(channels) + self.show_channel_list(None,self.m_selected_provider_index) + def show_provider_list(self, _) -> None: self.m_sizer.Clear(delete_windows=True) self.m_sizer = wx.BoxSizer(wx.VERTICAL) @@ -130,6 +149,12 @@ class Cast(wx.Frame): #self.m_sizer.AddSpacer(SPACER_HEIGHT * 4) bck_callback = lambda event: self.show_provider_list(event) self.add_back_button(bck_callback) + + if self.m_selected_provider.get_name() == "YouTube": + importbtn = wx.Button(self.m_panel, -1, label="Import from NewPipe",size=(WIDTH, BTN_HEIGHT)) + importbtn.Bind(wx.EVT_BUTTON, lambda event: self.show_importer(event)) + self.m_sizer.Add(importbtn) + channel_index = 0 for channel in self.m_selected_provider.get_channels():