|
|
|
#/usr/bin/env python3
|
|
|
|
import io
|
|
|
|
import threading
|
|
|
|
import time
|
|
|
|
|
|
|
|
import requests
|
|
|
|
import wx
|
|
|
|
|
|
|
|
from Channel import Channel
|
|
|
|
from Utils import get_default_log_url, make_bitmap_from_url, write_on_bitmap
|
|
|
|
|
|
|
|
|
|
|
|
class ChannelProvider:
|
|
|
|
def __init__(self, providerid: str, channels=list()):
|
|
|
|
self.m_id = providerid
|
|
|
|
self.m_logo_url = get_default_log_url(providerid)
|
|
|
|
self.m_logo: wx.Bitmap = make_bitmap_from_url(self.m_logo_url)
|
|
|
|
self.m_channels: list[Channel] = channels
|
|
|
|
if len(self.m_channels) > 0:
|
|
|
|
self.m_thr = threading.Thread(target=self.make_latest,
|
|
|
|
args=(),
|
|
|
|
kwargs={})
|
|
|
|
self.m_thr.start()
|
|
|
|
|
|
|
|
def append_channel(self, channel: Channel) -> int:
|
|
|
|
self.m_channels.append(channel)
|
|
|
|
return len(self.m_channels)
|
|
|
|
|
|
|
|
def get_channels(self) -> list[Channel]:
|
|
|
|
return self.m_channels
|
|
|
|
|
|
|
|
def get_channel_by_index(self, channel_index: int) -> Channel:
|
|
|
|
return self.m_channels[channel_index]
|
|
|
|
|
|
|
|
def get_logo_as_bitmap(self) -> wx.Bitmap:
|
|
|
|
return self.m_logo
|
|
|
|
|
|
|
|
def get_name(self) -> str:
|
|
|
|
return self.m_id
|
|
|
|
|
|
|
|
def get_logo_url(self) -> str:
|
|
|
|
links: dict = {'ch-svt1'}
|
|
|
|
|
|
|
|
def make_latest(self) -> None:
|
|
|
|
items = list()
|
|
|
|
for chan in self.m_channels:
|
|
|
|
while chan.wait():
|
|
|
|
time.sleep(1)
|
|
|
|
items.append(chan.get_latest_item())
|
|
|
|
|
|
|
|
channel = Channel(self.get_name, None, self.m_logo_url)
|
|
|
|
channel.set_items(items)
|
|
|
|
temp = self.get_logo_as_bitmap()
|
|
|
|
channel.set_logo(write_on_bitmap("Latest videos from all channels",temp))
|
|
|
|
self.append_channel(channel)
|