This time a ChannelProvider has multiple Channels and the gui class deals with them instead of Channels directlymain
parent
54193eb8df
commit
a776e913a8
@ -0,0 +1,35 @@
|
||||
#/usr/bin/env python3
|
||||
import io
|
||||
|
||||
import requests
|
||||
import wx
|
||||
|
||||
from Channel import Channel
|
||||
from Utils import get_default_log_url, make_bitmap_from_url
|
||||
|
||||
|
||||
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
|
||||
|
||||
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'}
|
@ -0,0 +1,64 @@
|
||||
#!/usr/bin/env python3
|
||||
import io
|
||||
|
||||
import requests
|
||||
import wx
|
||||
|
||||
|
||||
def get_default_log_url(providerid: str = 'default') -> str:
|
||||
if providerid == 'SVT':
|
||||
return 'https://upload.wikimedia.org/wikipedia/commons/thumb/4/4b/Logotyp_SVT_Play.png/480px-Logotyp_SVT_Play.jpg'
|
||||
if providerid == 'YouTube':
|
||||
return 'https://upload.wikimedia.org/wikipedia/commons/thumb/a/af/Youtube.png/480px-Youtube.jpg'
|
||||
|
||||
else:
|
||||
return 'https://upload.wikimedia.org/wikipedia/commons/thumb/f/fd/Cartoon_Hand_Playing_Multiple_Online_Videos.svg/480px-Cartoon_Hand_Playing_Multiple_Online_Videos.svg.jpg'
|
||||
|
||||
|
||||
def make_bitmap_from_url(logo_url: str = get_default_log_url()) -> wx.Bitmap:
|
||||
res = requests.get(logo_url)
|
||||
content = res.content
|
||||
content_bytes = io.BytesIO(content)
|
||||
logo = wx.Image(content_bytes, type=wx.BITMAP_TYPE_ANY, index=-1)
|
||||
return wx.Bitmap(logo)
|
||||
|
||||
|
||||
def resolve_svt_channel(svt_id: str) -> dict:
|
||||
channels = {
|
||||
"ch-barnkanalen": {
|
||||
"name":
|
||||
"Barnkanalen",
|
||||
"thumbnail_url":
|
||||
"https://upload.wikimedia.org/wikipedia/commons/thumb/5/52/SVT_Barnkanalen_logo_2008%E2%80%932012.svg/480px-SVT_Barnkanalen_logo_2008%E2%80%932012.svg.jpg"
|
||||
},
|
||||
"ch-svt1": {
|
||||
"name":
|
||||
"SVT 1",
|
||||
"thumbnail_url":
|
||||
"https://upload.wikimedia.org/wikipedia/commons/thumb/c/c2/SVT1_logo_2012.svg/480px-SVT1_logo_2012.svg.jpg"
|
||||
},
|
||||
"ch-svt2": {
|
||||
"name":
|
||||
"SVT 2",
|
||||
"thumbnail_url":
|
||||
"https://upload.wikimedia.org/wikipedia/commons/thumb/a/a7/SVT2_logo_2012.svg/480px-SVT2_logo_2012.svg.jpg"
|
||||
},
|
||||
"ch-svt24": {
|
||||
"name":
|
||||
"SVT 24",
|
||||
"thumbnail_url":
|
||||
"https://upload.wikimedia.org/wikipedia/commons/thumb/8/8f/SVT24_logo.svg/480px-SVT24_logo.svg.jpg"
|
||||
},
|
||||
"kunskapskanalen": {
|
||||
"name":
|
||||
"Kunskapskanalen",
|
||||
"thumbnail_url":
|
||||
"https://upload.wikimedia.org/wikipedia/commons/thumb/b/b9/Kunskapskanalen_logo.png/480px-Kunskapskanalen_logo.jpg"
|
||||
},
|
||||
"feed": {
|
||||
"name": "Senaste program",
|
||||
"thumbnail_url": get_default_log_url('SVT')
|
||||
},
|
||||
}
|
||||
|
||||
return channels[svt_id]
|
Loading…
Reference in new issue