Create a custom channel for all providers with the latest video from all channels
This commit is contained in:
parent
aff74e63e9
commit
1ce7bc3da8
4 changed files with 48 additions and 5 deletions
|
@ -37,7 +37,7 @@ class YouTube(Channel):
|
|||
kwargs={})
|
||||
self.m_thr.start()
|
||||
|
||||
def set_avatar(self) -> str:
|
||||
def set_avatar(self) -> None:
|
||||
info = get_info(self.m_channel_id)
|
||||
bmap = self.get_logo_as_bitmap()
|
||||
title = info['title']
|
||||
|
@ -54,8 +54,6 @@ class YouTube(Channel):
|
|||
del dc
|
||||
self.m_logo = bmap
|
||||
|
||||
return ""
|
||||
|
||||
def wait(self) -> bool:
|
||||
return self.m_thr.is_alive()
|
||||
|
||||
|
|
|
@ -40,3 +40,12 @@ class Channel:
|
|||
|
||||
def wait(self) -> bool:
|
||||
return False
|
||||
|
||||
def get_latest_item(self) -> Item:
|
||||
return self.m_items[0]
|
||||
|
||||
def set_items(self, items: list[Item]) -> None:
|
||||
self.m_items = items
|
||||
|
||||
def set_logo(self, logo: wx.Bitmap) -> None:
|
||||
self.m_logo = logo
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
#/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
|
||||
from Utils import get_default_log_url, make_bitmap_from_url, write_on_bitmap
|
||||
|
||||
|
||||
class ChannelProvider:
|
||||
|
@ -14,6 +16,11 @@ class ChannelProvider:
|
|||
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)
|
||||
|
@ -29,7 +36,20 @@ class ChannelProvider:
|
|||
return self.m_logo
|
||||
|
||||
def get_name(self) -> str:
|
||||
return self.m_id_
|
||||
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)
|
||||
|
|
|
@ -3,6 +3,7 @@ import io
|
|||
|
||||
import requests
|
||||
import wx
|
||||
from copy import copy
|
||||
|
||||
|
||||
def get_default_log_url(providerid: str = 'default') -> str:
|
||||
|
@ -62,3 +63,18 @@ def resolve_svt_channel(svt_id: str) -> dict:
|
|||
}
|
||||
|
||||
return channels[svt_id]
|
||||
|
||||
def write_on_bitmap(text: str, bmap: wx.Bitmap) -> wx.Bitmap:
|
||||
bitmap = wx.Bitmap(bmap)
|
||||
dc = wx.MemoryDC(bitmap)
|
||||
cblack = wx.Colour(0, 0, 0)
|
||||
cwhite = wx.Colour(255, 255, 255)
|
||||
dc.SetTextForeground(cwhite)
|
||||
dc.SetTextBackground(cblack)
|
||||
dc.SetFont(wx.Font().Bold())
|
||||
dc.SetBackgroundMode(wx.BRUSHSTYLE_SOLID)
|
||||
w, h = dc.GetSize()
|
||||
tw, th = dc.GetTextExtent(text)
|
||||
dc.DrawText(text, (w - tw) / 2, (h - th) / 2) #display text in center
|
||||
del dc
|
||||
return bitmap
|
||||
|
|
Loading…
Add table
Reference in a new issue