|
|
|
@ -8,6 +8,7 @@ from datetime import datetime
|
|
|
|
|
from os import environ, makedirs, path
|
|
|
|
|
from typing import Callable, Union
|
|
|
|
|
from urllib.parse import urlparse
|
|
|
|
|
from youtubesearchpython import ChannelsSearch
|
|
|
|
|
|
|
|
|
|
import requests
|
|
|
|
|
import wx
|
|
|
|
@ -31,18 +32,26 @@ def add_subscription(channel_id: str,
|
|
|
|
|
basepath: str = BASEPATH,
|
|
|
|
|
filename: str = DB_FILE_NAME) -> None:
|
|
|
|
|
fullpath = path.join(basepath, filename)
|
|
|
|
|
if not path.isdir(basepath):
|
|
|
|
|
makedirs(basepath)
|
|
|
|
|
thumbpath = path.join(basepath, 'thumbnails')
|
|
|
|
|
thumbnail = path.join(thumbpath, channel_id)
|
|
|
|
|
fullpath = path.join(basepath, filename)
|
|
|
|
|
if not path.isdir(thumbpath):
|
|
|
|
|
makedirs(thumbpath)
|
|
|
|
|
if not path.isfile(thumbnail):
|
|
|
|
|
channels_search = ChannelsSearch(name, limit=1).result()['result'][0] #type: ignore
|
|
|
|
|
bitmap = make_bitmap_from_url('https:' + channels_search['thumbnails'][0]['url'])
|
|
|
|
|
bitmap.SaveFile(thumbnail, wx.BITMAP_TYPE_PNG)
|
|
|
|
|
con = sqlite3.connect(fullpath)
|
|
|
|
|
cur = con.cursor()
|
|
|
|
|
create_query: str = '''CREATE TABLE IF NOT EXISTS {}
|
|
|
|
|
(channel_id TEXT PRIMARY KEY, channel_name TEXT)'''.format(SUB_TABLE)
|
|
|
|
|
(channel_id TEXT PRIMARY KEY, channel_name TEXT, thumb_path TEXT)'''.format(
|
|
|
|
|
SUB_TABLE)
|
|
|
|
|
cur.execute(create_query)
|
|
|
|
|
con.commit()
|
|
|
|
|
upsert_query: str = '''INSERT INTO {} (channel_id, channel_name)
|
|
|
|
|
VALUES('{}',"{}") ON CONFLICT(channel_id) DO NOTHING'''.format(
|
|
|
|
|
SUB_TABLE, channel_id, name)
|
|
|
|
|
cur.execute(upsert_query)
|
|
|
|
|
upsert_query: str = '''INSERT INTO {} (channel_id, channel_name, thumb_path)
|
|
|
|
|
VALUES(?,?,?) ON CONFLICT(channel_id) DO NOTHING'''.format(
|
|
|
|
|
SUB_TABLE )
|
|
|
|
|
cur.execute(upsert_query, [channel_id, name, thumbnail])
|
|
|
|
|
con.commit()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -227,23 +236,23 @@ def make_sized_button(parent_pnl: wx.Panel, bitmap_or_str: Union[wx.Bitmap,
|
|
|
|
|
bitmap = wx.Bitmap(bitmap_or_str, wx.BITMAP_TYPE_ANY)
|
|
|
|
|
else:
|
|
|
|
|
bitmap = bitmap_or_str
|
|
|
|
|
btn_style = wx.BORDER_NONE | wx.BU_AUTODRAW | wx.BU_EXACTFIT | wx.BU_NOTEXT
|
|
|
|
|
btn_logo_style = wx.BU_AUTODRAW | wx.BU_EXACTFIT | wx.BU_NOTEXT | wx.BORDER_NONE#| wx.BOTTOM | wx.RIGHT | wx.TOP
|
|
|
|
|
btn_logo = wx.BitmapButton(parent_pnl,
|
|
|
|
|
wx.ID_ANY,
|
|
|
|
|
bitmap,
|
|
|
|
|
style=btn_style,
|
|
|
|
|
size=bitmap.GetSize())
|
|
|
|
|
style=btn_logo_style,
|
|
|
|
|
size=SIZE)
|
|
|
|
|
btn_logo.SetToolTip(text)
|
|
|
|
|
btn_sizer.Add(btn_logo, 0, wx.BOTTOM | wx.EXPAND | wx.LEFT | wx.TOP, 1)
|
|
|
|
|
btn_sizer.Add(btn_logo, 0, wx.EXPAND, 1)
|
|
|
|
|
|
|
|
|
|
btn_text = wx.Button(parent_pnl,
|
|
|
|
|
wx.ID_ANY,
|
|
|
|
|
text,
|
|
|
|
|
style=wx.BORDER_NONE | wx.BU_AUTODRAW,
|
|
|
|
|
style=wx.BU_AUTODRAW | wx.BOTTOM | wx.LEFT | wx.TOP | wx.BORDER_NONE,
|
|
|
|
|
size=wx.Size(SCREEN_WIDTH - SIZE.GetWidth(),
|
|
|
|
|
SIZE.GetHeight()))
|
|
|
|
|
btn_text.SetToolTip(text)
|
|
|
|
|
btn_sizer.Add(btn_text, 0, wx.BOTTOM | wx.RIGHT | wx.TOP | wx.EXPAND, 1)
|
|
|
|
|
btn_sizer.Add(btn_text, 0, wx.EXPAND, 1)
|
|
|
|
|
parent_pnl.Bind(wx.EVT_BUTTON, callback, btn_logo)
|
|
|
|
|
parent_pnl.Bind(wx.EVT_BUTTON, callback, btn_text)
|
|
|
|
|
|
|
|
|
@ -255,8 +264,8 @@ def make_bitmap_from_url(logo_url: str, size: wx.Size = SIZE) -> wx.Bitmap:
|
|
|
|
|
content = res.content
|
|
|
|
|
content_bytes = io.BytesIO(content)
|
|
|
|
|
image = wx.Image(content_bytes, type=wx.BITMAP_TYPE_ANY, index=-1)
|
|
|
|
|
scale_factor = image.GetWidth() / SCREEN_WIDTH
|
|
|
|
|
size.SetWidth(SCREEN_WIDTH)
|
|
|
|
|
scale_factor = image.GetWidth() / size.GetWidth()
|
|
|
|
|
size.SetWidth(image.GetWidth() / scale_factor)
|
|
|
|
|
height = image.GetHeight()
|
|
|
|
|
size.SetHeight(height / scale_factor)
|
|
|
|
|
image.Rescale(size.GetWidth(), size.GetHeight())
|
|
|
|
@ -265,11 +274,11 @@ def make_bitmap_from_url(logo_url: str, size: wx.Size = SIZE) -> wx.Bitmap:
|
|
|
|
|
|
|
|
|
|
def make_bitmap_from_file(path, size: wx.Size = SIZE) -> wx.Bitmap:
|
|
|
|
|
image = wx.Image(path, type=wx.BITMAP_TYPE_ANY, index=-1)
|
|
|
|
|
# scale_factor = image.GetWidth() / SCREEN_WIDTH
|
|
|
|
|
# size.SetWidth(SCREEN_WIDTH)
|
|
|
|
|
# height = image.GetHeight()
|
|
|
|
|
# size.SetHeight(height/scale_factor)
|
|
|
|
|
# image.Rescale(size.GetWidth(), size.GetHeight() )
|
|
|
|
|
scale_factor = image.GetWidth() / size.GetWidth()
|
|
|
|
|
size.SetWidth(image.GetWidth() / scale_factor)
|
|
|
|
|
height = image.GetHeight()
|
|
|
|
|
size.SetHeight(height / scale_factor)
|
|
|
|
|
image.Rescale(size.GetWidth(), size.GetHeight())
|
|
|
|
|
return wx.Bitmap(image)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|