|
|
@ -8,6 +8,7 @@ from datetime import datetime
|
|
|
|
from os import environ, makedirs, path
|
|
|
|
from os import environ, makedirs, path
|
|
|
|
from typing import Callable, Union
|
|
|
|
from typing import Callable, Union
|
|
|
|
from urllib.parse import urlparse
|
|
|
|
from urllib.parse import urlparse
|
|
|
|
|
|
|
|
from youtubesearchpython import ChannelsSearch
|
|
|
|
|
|
|
|
|
|
|
|
import requests
|
|
|
|
import requests
|
|
|
|
import wx
|
|
|
|
import wx
|
|
|
@ -31,18 +32,26 @@ def add_subscription(channel_id: str,
|
|
|
|
basepath: str = BASEPATH,
|
|
|
|
basepath: str = BASEPATH,
|
|
|
|
filename: str = DB_FILE_NAME) -> None:
|
|
|
|
filename: str = DB_FILE_NAME) -> None:
|
|
|
|
fullpath = path.join(basepath, filename)
|
|
|
|
fullpath = path.join(basepath, filename)
|
|
|
|
if not path.isdir(basepath):
|
|
|
|
thumbpath = path.join(basepath, 'thumbnails')
|
|
|
|
makedirs(basepath)
|
|
|
|
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)
|
|
|
|
con = sqlite3.connect(fullpath)
|
|
|
|
cur = con.cursor()
|
|
|
|
cur = con.cursor()
|
|
|
|
create_query: str = '''CREATE TABLE IF NOT EXISTS {}
|
|
|
|
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)
|
|
|
|
cur.execute(create_query)
|
|
|
|
con.commit()
|
|
|
|
con.commit()
|
|
|
|
upsert_query: str = '''INSERT INTO {} (channel_id, channel_name)
|
|
|
|
upsert_query: str = '''INSERT INTO {} (channel_id, channel_name, thumb_path)
|
|
|
|
VALUES('{}',"{}") ON CONFLICT(channel_id) DO NOTHING'''.format(
|
|
|
|
VALUES(?,?,?) ON CONFLICT(channel_id) DO NOTHING'''.format(
|
|
|
|
SUB_TABLE, channel_id, name)
|
|
|
|
SUB_TABLE )
|
|
|
|
cur.execute(upsert_query)
|
|
|
|
cur.execute(upsert_query, [channel_id, name, thumbnail])
|
|
|
|
con.commit()
|
|
|
|
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)
|
|
|
|
bitmap = wx.Bitmap(bitmap_or_str, wx.BITMAP_TYPE_ANY)
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
bitmap = bitmap_or_str
|
|
|
|
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,
|
|
|
|
btn_logo = wx.BitmapButton(parent_pnl,
|
|
|
|
wx.ID_ANY,
|
|
|
|
wx.ID_ANY,
|
|
|
|
bitmap,
|
|
|
|
bitmap,
|
|
|
|
style=btn_style,
|
|
|
|
style=btn_logo_style,
|
|
|
|
size=bitmap.GetSize())
|
|
|
|
size=SIZE)
|
|
|
|
btn_logo.SetToolTip(text)
|
|
|
|
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,
|
|
|
|
btn_text = wx.Button(parent_pnl,
|
|
|
|
wx.ID_ANY,
|
|
|
|
wx.ID_ANY,
|
|
|
|
text,
|
|
|
|
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=wx.Size(SCREEN_WIDTH - SIZE.GetWidth(),
|
|
|
|
SIZE.GetHeight()))
|
|
|
|
SIZE.GetHeight()))
|
|
|
|
btn_text.SetToolTip(text)
|
|
|
|
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_logo)
|
|
|
|
parent_pnl.Bind(wx.EVT_BUTTON, callback, btn_text)
|
|
|
|
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 = res.content
|
|
|
|
content_bytes = io.BytesIO(content)
|
|
|
|
content_bytes = io.BytesIO(content)
|
|
|
|
image = wx.Image(content_bytes, type=wx.BITMAP_TYPE_ANY, index=-1)
|
|
|
|
image = wx.Image(content_bytes, type=wx.BITMAP_TYPE_ANY, index=-1)
|
|
|
|
scale_factor = image.GetWidth() / SCREEN_WIDTH
|
|
|
|
scale_factor = image.GetWidth() / size.GetWidth()
|
|
|
|
size.SetWidth(SCREEN_WIDTH)
|
|
|
|
size.SetWidth(image.GetWidth() / scale_factor)
|
|
|
|
height = image.GetHeight()
|
|
|
|
height = image.GetHeight()
|
|
|
|
size.SetHeight(height / scale_factor)
|
|
|
|
size.SetHeight(height / scale_factor)
|
|
|
|
image.Rescale(size.GetWidth(), size.GetHeight())
|
|
|
|
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:
|
|
|
|
def make_bitmap_from_file(path, size: wx.Size = SIZE) -> wx.Bitmap:
|
|
|
|
image = wx.Image(path, type=wx.BITMAP_TYPE_ANY, index=-1)
|
|
|
|
image = wx.Image(path, type=wx.BITMAP_TYPE_ANY, index=-1)
|
|
|
|
# scale_factor = image.GetWidth() / SCREEN_WIDTH
|
|
|
|
scale_factor = image.GetWidth() / size.GetWidth()
|
|
|
|
# size.SetWidth(SCREEN_WIDTH)
|
|
|
|
size.SetWidth(image.GetWidth() / scale_factor)
|
|
|
|
# height = image.GetHeight()
|
|
|
|
height = image.GetHeight()
|
|
|
|
# size.SetHeight(height/scale_factor)
|
|
|
|
size.SetHeight(height / scale_factor)
|
|
|
|
# image.Rescale(size.GetWidth(), size.GetHeight() )
|
|
|
|
image.Rescale(size.GetWidth(), size.GetHeight())
|
|
|
|
return wx.Bitmap(image)
|
|
|
|
return wx.Bitmap(image)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|