You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
81 lines
2.8 KiB
81 lines
2.8 KiB
#!/usr/bin/env python3
|
|
import io
|
|
|
|
import requests
|
|
import wx
|
|
from copy import copy
|
|
|
|
|
|
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]
|
|
|
|
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
|