mirror of
https://github.com/anatolykopyl/youtube-cdl.git
synced 2026-03-26 12:55:11 +00:00
🎨 autopep8
This commit is contained in:
121
main.py
121
main.py
@@ -10,33 +10,35 @@ from get_channels import retrieve_youtube_subscriptions
|
||||
from print_logo import print_logo
|
||||
|
||||
if platform.system() == 'Windows':
|
||||
import msvcrt
|
||||
def uni_getch():
|
||||
char = str(msvcrt.getch())
|
||||
if char == "b'y'":
|
||||
return True
|
||||
elif char == "b'n'":
|
||||
return False
|
||||
else:
|
||||
return None
|
||||
import msvcrt
|
||||
|
||||
def uni_getch():
|
||||
char = str(msvcrt.getch())
|
||||
if char == "b'y'":
|
||||
return True
|
||||
elif char == "b'n'":
|
||||
return False
|
||||
else:
|
||||
return None
|
||||
else:
|
||||
from getch import getch
|
||||
def uni_getch():
|
||||
char = getch()
|
||||
if char == "y":
|
||||
return True
|
||||
elif char == "n":
|
||||
return False
|
||||
else:
|
||||
return None
|
||||
from getch import getch
|
||||
|
||||
def uni_getch():
|
||||
char = getch()
|
||||
if char == "y":
|
||||
return True
|
||||
elif char == "n":
|
||||
return False
|
||||
else:
|
||||
return None
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('-i', '--input', action='store', type=str,
|
||||
help='Path to json file generated by previously running this program.')
|
||||
parser.add_argument('-o', '--output', action='store', type=str,
|
||||
help='Output folder.')
|
||||
parser.add_argument('-a', '--all', action='store_true',
|
||||
help='Download all subscriptions.')
|
||||
parser.add_argument('-i', '--input', action='store', type=str,
|
||||
help='Path to json file generated by previously running this program.')
|
||||
parser.add_argument('-o', '--output', action='store', type=str,
|
||||
help='Output folder.')
|
||||
parser.add_argument('-a', '--all', action='store_true',
|
||||
help='Download all subscriptions.')
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
@@ -46,45 +48,50 @@ download_all = args.all
|
||||
|
||||
c = Console()
|
||||
ydl_opts = {
|
||||
'format': 'best'
|
||||
'format': 'best'
|
||||
}
|
||||
|
||||
print_logo()
|
||||
|
||||
if json_input:
|
||||
f = open(json_input, "r", encoding='utf-8')
|
||||
all_channels = json.loads(f.read())
|
||||
f.close()
|
||||
f = open(json_input, "r", encoding='utf-8')
|
||||
all_channels = json.loads(f.read())
|
||||
f.close()
|
||||
else:
|
||||
all_channels = retrieve_youtube_subscriptions()
|
||||
curr_channel = 0
|
||||
c.print(f'You will be prompted if you want to download a channel for each of your subscriptions. (total {len(all_channels)})', style='bold')
|
||||
for ch in all_channels:
|
||||
if download_all:
|
||||
ch['download'] = True
|
||||
else:
|
||||
curr_channel += 1
|
||||
c.print(f'[dim][{curr_channel}/{len(all_channels)}]:[/dim] {ch["title"]} [cyan]\[y/n]')
|
||||
while True:
|
||||
key = uni_getch()
|
||||
if key == True:
|
||||
ch['download'] = True
|
||||
break
|
||||
elif key == False:
|
||||
ch['download'] = False
|
||||
break
|
||||
else:
|
||||
c.print('Press "y" or "n"', style='yellow')
|
||||
all_channels = retrieve_youtube_subscriptions()
|
||||
curr_channel = 0
|
||||
c.print(
|
||||
f'You will be prompted if you want to download a channel for each of your subscriptions. (total {len(all_channels)})', style='bold')
|
||||
for ch in all_channels:
|
||||
if download_all:
|
||||
ch['download'] = True
|
||||
else:
|
||||
curr_channel += 1
|
||||
c.print(
|
||||
f'[dim][{curr_channel}/{len(all_channels)}]:[/dim] {ch["title"]} [cyan]\[y/n]')
|
||||
while True:
|
||||
key = uni_getch()
|
||||
if key == True:
|
||||
ch['download'] = True
|
||||
break
|
||||
elif key == False:
|
||||
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')
|
||||
f = open("download_list.json", "w", encoding='utf-8')
|
||||
f.write(json.dumps(all_channels))
|
||||
f.close()
|
||||
c.print('All done! 🎉')
|
||||
c.print('Saving to download_list.json...', style='italic')
|
||||
f = open("download_list.json", "w", encoding='utf-8')
|
||||
f.write(json.dumps(all_channels))
|
||||
f.close()
|
||||
|
||||
for ch in all_channels:
|
||||
if ch['download']:
|
||||
ydl_opts['outtmpl'] = '{}/{}/%(title)s.%(ext)s'.format(output_dir, ch['title'])
|
||||
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
|
||||
Path(os.path.join(output_dir, ch['title'])).mkdir(parents=True, exist_ok=True)
|
||||
ydl.download(['https://www.youtube.com/channel/{}'.format(ch["id"])])
|
||||
if ch['download']:
|
||||
ydl_opts['outtmpl'] = '{}/{}/%(title)s.%(ext)s'.format(
|
||||
output_dir, ch['title'])
|
||||
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
|
||||
Path(os.path.join(output_dir, ch['title'])).mkdir(
|
||||
parents=True, exist_ok=True)
|
||||
ydl.download(
|
||||
['https://www.youtube.com/channel/{}'.format(ch["id"])])
|
||||
|
||||
Reference in New Issue
Block a user