From 4adb9675ea0852d860f8157b4279221e299cb2bf Mon Sep 17 00:00:00 2001 From: shibaisdog Date: Sat, 21 Dec 2024 00:25:35 +0900 Subject: [PATCH] Increased basic size --- src/gui.py | 28 ++++++++++++++++++---------- src/utils/download.py | 18 ++++++++++++++++++ src/win/font.py | 11 +++++++++++ 3 files changed, 47 insertions(+), 10 deletions(-) create mode 100644 src/win/font.py diff --git a/src/gui.py b/src/gui.py index 9dd6904..acb109a 100644 --- a/src/gui.py +++ b/src/gui.py @@ -16,6 +16,7 @@ from src import size import src.win.screen import src.win.setting +import src.win.font import src.discord.client import src.with_play import src.socket.server @@ -33,7 +34,7 @@ class VideoState: fullscreen: bool = False display_width: int = 0 display_height: int = 0 - ascii_width: int = 80 + ascii_width: int = 120 msg_start_time: float = 0 msg_text: str = "" @@ -128,7 +129,7 @@ def handle_key_event(key: str) -> None: elif key == "f11": state.fullscreen = not state.fullscreen if not state.fullscreen: - src.win.screen.reset((src.win.screen.vid.current_size[0], src.win.screen.vid.current_size[1]+5)) + src.win.screen.reset((src.win.screen.vid.current_size[0]*1.5, src.win.screen.vid.current_size[1]*1.5+5)) else: src.win.screen.reset((state.display_width,state.display_height)) elif key == "a": @@ -152,7 +153,7 @@ def toggle_ascii_mode(): src.win.screen.win = pygame.display.set_mode((int(window_width), int(window_height))) state.font = pygame.font.SysFont("Courier", state.font_size) else: - src.win.screen.reset((src.win.screen.vid.current_size[0], src.win.screen.vid.current_size[1]+5), vid=True) + src.win.screen.reset((src.win.screen.vid.current_size[0]*1.5, src.win.screen.vid.current_size[1]*1.5+5), vid=True) os.environ['SDL_VIDEO_CENTERED'] = '1' def draw_overlay(current_time: float): @@ -209,12 +210,19 @@ def render_subtitles(subtitles): else: pass for content in current_subtitle: - #print(f"{content['position']} / {content['line']} / {content['text']}") + #if content['size'] == None: + # content['size'] = 25 + #if int(content['size']) > 25: + # content['size'] = int(int(content['size']) * 0.75) + #else: + # content['size'] = 25 + content['size'] = 25 + font = src.win.font.get(content['size']) if '\n' in content['text']: i = 0 for line in (content['text'].split('\n'))[::-1]: - text_surface = src.win.screen.font.render(line, True, (236,82,82)) - text_rect = text_surface.get_rect(center=(src.win.screen.win.get_width() * (int(content['position']) / 100), src.win.screen.win.get_height() * (int(content['line']) / 100) - i * 30)) + text_surface = font.render(line, True, (236,82,82)) + text_rect = text_surface.get_rect(center=(src.win.screen.win.get_width() * (int(content['position']) / 100), src.win.screen.win.get_height() * (int(content['line']) / 100) - (i * (content['size'] + 11)))) padding = 2 rect_width = text_rect.width + padding * 2 rect_height = text_rect.height + padding * 2 @@ -227,7 +235,7 @@ def render_subtitles(subtitles): src.win.screen.win.blit(text_surface, text_rect) i += 1 else: - text_surface = src.win.screen.font.render(content['text'], True, (236,82,82)) + text_surface = font.render(content['text'], True, (236,82,82)) text_rect = text_surface.get_rect(center=(src.win.screen.win.get_width() * (int(content['position']) / 100), src.win.screen.win.get_height() * (int(content['line']) / 100))) padding = 2 rect_width = text_rect.width + padding * 2 @@ -252,7 +260,7 @@ def run(url: str, seek = 0): sub = None vtt = None src.win.screen.vid = Video(fn) - src.win.screen.reset((src.win.screen.vid.current_size[0], src.win.screen.vid.current_size[1] + 5), vid=True) + src.win.screen.reset((src.win.screen.vid.current_size[0]*1.5, src.win.screen.vid.current_size[1]*1.5 + 5), vid=True) pygame.display.set_caption(src.win.screen.vid.name) src.win.screen.vid.set_volume(user_setting.volume / 100) src.win.screen.vid.seek(seek) @@ -344,7 +352,7 @@ def wait(once): elif src.win.screen.vid is None: src.win.screen.reset((state.search_width, state.search_height)) else: - src.win.screen.reset((src.win.screen.vid.current_size[0], src.win.screen.vid.current_size[1] + 5), vid=True) + src.win.screen.reset((src.win.screen.vid.current_size[0]*1.5, src.win.screen.vid.current_size[1]*1.5 + 5), vid=True) pygame.scrap.init() icon = pygame.image.load("./asset/sclatIcon.png") pygame.display.set_icon(icon) @@ -526,7 +534,7 @@ def wait(once): if src.win.screen.vid == None: src.win.screen.reset((state.search_width, state.search_height)) else: - src.win.screen.reset((src.win.screen.vid.current_size[0],src.win.screen.vid.current_size[1]+5), vid=True) + src.win.screen.reset((src.win.screen.vid.current_size[0]*1.5,src.win.screen.vid.current_size[1]*1.5+5), vid=True) if trys >= 10: print("fail") src.win.setting.video_list = [] diff --git a/src/utils/download.py b/src/utils/download.py index 64f47fb..5fec53c 100644 --- a/src/utils/download.py +++ b/src/utils/download.py @@ -23,6 +23,8 @@ def progress_function(stream, chunk, bytes_remaining): width = stream.width if stream.width else 800 height = stream.height if stream.height else 600 + width = width * 1.5 + height = height * 1.5 src.win.screen.reset((width, height+5)) pygame.display.set_caption(f"Downloading: {convert_size(bytes_downloaded)} of {convert_size(total_size)} ({percentage:.2f}%)") @@ -31,6 +33,19 @@ def progress_function(stream, chunk, bytes_remaining): src.win.screen.win.blit(text_surface, text_rect) pygame.display.update() +def progress_hook(d): + try: + width = src.win.screen.win.get_size()[0] + height = src.win.screen.win.get_size()[1] + src.win.screen.win.fill((0,0,0)) + pygame.display.set_caption(f"Downloading: {d['_percent_str']} of {d['_speed_str']} - ETA: {d['_eta_str']}") + text_surface = src.win.screen.font.render(f"Downloading: {d['_percent_str']} of {d['_speed_str']} - ETA: {d['_eta_str']}", True, (255,255,255)) + text_rect = text_surface.get_rect(center=(int(width/2), int(height/2))) + src.win.screen.win.blit(text_surface, text_rect) + pygame.display.update() + except Exception as e: + print(e) + def after(a,b): src.win.screen.load = 2 @@ -89,6 +104,9 @@ def install_srt(url: str, fns: str, title: str, lang = 'ko'): 'writeautomaticsub': True, 'outtmpl': f'{fns}/{title}.%(ext)s', 'skip_download': True, + 'progress_hooks': [progress_hook], + 'verbose': False, + 'logger': None, } try: with yt_dlp.YoutubeDL(ydl_opts) as ydl: diff --git a/src/win/font.py b/src/win/font.py new file mode 100644 index 0000000..85486a2 --- /dev/null +++ b/src/win/font.py @@ -0,0 +1,11 @@ +import pygame + +List = {} + +def get(size:int): + if not (str(size) in List): + try: + List[str(size)] = pygame.font.Font("./asset/NanumBarunpenB.ttf", size) + except FileNotFoundError: + List[str(size)] = pygame.font.Font(None, size) + return List[str(size)] \ No newline at end of file