From 7c7a9b881bd97eb0eda9cbb0ac28f11757333800 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Mon, 12 Dec 2016 19:50:41 -0800 Subject: [PATCH] rename some helper scripts --- download_thumbnails.py | 24 +++++++++++++++++------- refresh_channels.py | 5 +++++ ycdl.py | 8 +++++--- ycdl_refresh.py | 2 -- ycdl_easy.py => ycdl_repl.py | 2 +- 5 files changed, 28 insertions(+), 13 deletions(-) create mode 100644 refresh_channels.py delete mode 100644 ycdl_refresh.py rename ycdl_easy.py => ycdl_repl.py (76%) diff --git a/download_thumbnails.py b/download_thumbnails.py index c19604b..eb1e52c 100644 --- a/download_thumbnails.py +++ b/download_thumbnails.py @@ -1,13 +1,23 @@ +import bot import os -import ycdl_easy +import traceback +import ycdl +import ytapi + from voussoirkit import downloady +youtube_core = ytapi.Youtube(bot.YOUTUBE_KEY) +youtube = ycdl.YCDL(youtube_core) + DIRECTORY = 'C:\\users\\owner\\youtube thumbnails' -videos = ycdl_easy.youtube.get_videos() +videos = ycdl_repl.youtube.get_videos() for video in videos: - thumbnail_path = os.path.join(DIRECTORY, video['id']) + '.jpg' - if os.path.exists(thumbnail_path): - continue - result = downloady.download_file(video['thumbnail'], thumbnail_path) - print(result) + try: + thumbnail_path = os.path.join(DIRECTORY, video['id']) + '.jpg' + if os.path.exists(thumbnail_path): + continue + result = downloady.download_file(video['thumbnail'], thumbnail_path) + print(result) + except Exception as e: + traceback.print_exc() diff --git a/refresh_channels.py b/refresh_channels.py new file mode 100644 index 0000000..29dc457 --- /dev/null +++ b/refresh_channels.py @@ -0,0 +1,5 @@ +''' +Just a shortcut script to refresh all channels. +''' +import ycdl_repl +ycdl_repl.youtube.refresh_all_channels() diff --git a/ycdl.py b/ycdl.py index e5bf286..9edec9f 100644 --- a/ycdl.py +++ b/ycdl.py @@ -177,13 +177,15 @@ class YCDL: print('That video does not need to be downloaded.') return - download_directory = self.channel_directory(channel_id) - download_directory = download_directory or os.getcwd() - current_directory = os.getcwd() + download_directory = self.channel_directory(channel_id) + download_directory = download_directory or current_directory + os.makedirs(download_directory, exist_ok=True) os.chdir(download_directory) + self.youtube_dl_function(video_id) + os.chdir(current_directory) self.cur.execute('UPDATE videos SET download = "downloaded" WHERE id == ?', [video_id]) diff --git a/ycdl_refresh.py b/ycdl_refresh.py deleted file mode 100644 index 7574774..0000000 --- a/ycdl_refresh.py +++ /dev/null @@ -1,2 +0,0 @@ -import ycdl_easy -ycdl_easy.youtube.refresh_all_channels() diff --git a/ycdl_easy.py b/ycdl_repl.py similarity index 76% rename from ycdl_easy.py rename to ycdl_repl.py index f610a47..660359c 100644 --- a/ycdl_easy.py +++ b/ycdl_repl.py @@ -1,5 +1,5 @@ ''' -Run `python -i ycdl_easy.py to get an interpreter +Run `python -i ycdl_repl.py to get an interpreter session with these variables preloaded. '''