From 93a37a8cbd46b570fb77fbc100d581ed5580b3f5 Mon Sep 17 00:00:00 2001 From: Anatoly Date: Sun, 11 Apr 2021 02:37:39 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=8F=97=20Added=20Windows=20support?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 36 ++++++++++++++++++++++++++---------- print_logo.py | 3 +-- 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/main.py b/main.py index 24302b2..26a46f9 100644 --- a/main.py +++ b/main.py @@ -1,14 +1,19 @@ from rich.console import Console #from rich import inspect +import platform from pathlib import Path import os import json import argparse -from getch import getch import youtube_dl from get_channels import retrieve_youtube_subscriptions from print_logo import print_logo +if platform.system() == 'Windows': + import msvcrt +else: + from getch import getch + parser = argparse.ArgumentParser() parser.add_argument('-i', '--input', action='store', type=str, help='Path to json file generated by previously running this program.') @@ -25,7 +30,7 @@ download_all = args.all c = Console() ydl_opts = { - 'format': 'best' + 'format': 'best' } print_logo() @@ -45,15 +50,26 @@ else: curr_channel += 1 c.print(f'[dim][{curr_channel}/{len(all_channels)}]:[/dim] {ch["title"]} [cyan]\[y/n]') while True: - key = getch() - if key == "y": - ch['download'] = True - break - elif key == "n": - ch['download'] = False - break + if platform.system() == 'Windows': + key = str(msvcrt.getch()) + if key == "b'y'": + ch['download'] = True + break + elif key == "b'n'": + ch['download'] = False + break + else: + c.print('Press "y" or "n"', style='yellow') else: - c.print('Press "y" or "n"', style='orange') + key = getch() + if key == "y": + ch['download'] = True + break + elif key == "n": + ch['download'] = False + break + else: + c.print('Press "y" or "n"', style='yellow') c.print('All done! 🎉') c.print('Saving to download_list.json...', style='italic') diff --git a/print_logo.py b/print_logo.py index 18be784..a172ae0 100644 --- a/print_logo.py +++ b/print_logo.py @@ -8,5 +8,4 @@ __ ______ __ __________ ______ ______ __________ __ \ / / / / / / / / / / / / / __ / __/______/ / / / / / / / / /_/ / /_/ / / / / /_/ / /_/ / /__/_____/ /___/ /_/ / /___ /_/\____/\____/ /_/ \____/_____/_____/ \____/_____/_____/ - - """, style='magenta') \ No newline at end of file +""", style='magenta') \ No newline at end of file