|
|
|
@ -22,6 +22,7 @@ BASEPATH = path.join(str(environ.get("HOME")), '.config/cast')
|
|
|
|
|
DB_FILE_NAME = 'cast.db'
|
|
|
|
|
SUB_TABLE = 'subscriptions'
|
|
|
|
|
VIDEO_TABLE = 'videos'
|
|
|
|
|
USE_CACHED_CATEGORIES = False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def add_video(video_id: str,
|
|
|
|
@ -76,7 +77,16 @@ def get_svt_thumb_from_id_changed(id: str,
|
|
|
|
|
size, id, changed)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_all_svt_categories() -> list:
|
|
|
|
|
def get_all_svt_categories(basepath=BASEPATH) -> list:
|
|
|
|
|
global USE_CACHED_CATEGORIES
|
|
|
|
|
categoryfile = path.join(basepath,"categories.json")
|
|
|
|
|
if USE_CACHED_CATEGORIES:
|
|
|
|
|
if path.isfile(categoryfile):
|
|
|
|
|
with open(categoryfile, 'r') as jfile:
|
|
|
|
|
return(json.loads(jfile.read()))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
categories: list = list()
|
|
|
|
|
url = "https://www.svtplay.se/kategori"
|
|
|
|
|
data = get_svt_data(url)
|
|
|
|
@ -84,6 +94,9 @@ def get_all_svt_categories() -> list:
|
|
|
|
|
if 'genres' in entry.keys():
|
|
|
|
|
categories = entry['genres']
|
|
|
|
|
break
|
|
|
|
|
with open(categoryfile, 'w') as jfile:
|
|
|
|
|
jfile.write(json.dumps(categories))
|
|
|
|
|
USE_CACHED_CATEGORIES = True
|
|
|
|
|
return categories
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -295,7 +308,14 @@ def make_sized_button(parent_pnl: wx.Panel, bitmap_or_str: Union[wx.Bitmap,
|
|
|
|
|
return btn_sizer
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def make_bitmap_from_url(logo_url: str, size: wx.Size = SIZE) -> wx.Bitmap:
|
|
|
|
|
def make_bitmap_from_url(logo_url: str, size: wx.Size = SIZE, video_id: str = "") -> wx.Bitmap:
|
|
|
|
|
if not video_id:
|
|
|
|
|
video_id = hash_string(logo_url)
|
|
|
|
|
thumbpath = path.join(BASEPATH, 'thumbnails')
|
|
|
|
|
thumbnail = path.join(thumbpath, video_id)
|
|
|
|
|
if path.isfile(thumbnail):
|
|
|
|
|
return make_bitmap_from_file(thumbnail, size)
|
|
|
|
|
|
|
|
|
|
res = requests.get(logo_url)
|
|
|
|
|
content = res.content
|
|
|
|
|
content_bytes = io.BytesIO(content)
|
|
|
|
@ -305,7 +325,12 @@ def make_bitmap_from_url(logo_url: str, size: wx.Size = SIZE) -> wx.Bitmap:
|
|
|
|
|
height = image.GetHeight()
|
|
|
|
|
size.SetHeight(int(height / scale_factor))
|
|
|
|
|
image.Rescale(size.GetWidth(), size.GetHeight())
|
|
|
|
|
return wx.Bitmap(image)
|
|
|
|
|
bitmap = wx.Bitmap(image)
|
|
|
|
|
if not path.isdir(thumbpath):
|
|
|
|
|
makedirs(thumbpath)
|
|
|
|
|
if not path.isfile(thumbnail):
|
|
|
|
|
bitmap.SaveFile(thumbnail, wx.BITMAP_TYPE_PNG)
|
|
|
|
|
return bitmap
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def make_bitmap_from_file(path, size: wx.Size = SIZE) -> wx.Bitmap:
|
|
|
|
|