From dd99ddc10fdbc621d7397187c30cc6a0ff114a24 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Sun, 24 May 2020 21:07:14 -0700 Subject: [PATCH] Remove youtube_dl_function argument, but add configurable extension. In order to improve the configurability of the queuefile creation, which I can't really do when relegating that to a possibly third-party function with only the video id as argument, I've decided I want to go all in on the queuefile as the output of ycdl. Actually downloading the video is best left to another tool designed for the task. Any third-party downloading function would always introduce the possibility of network errors and crashes, ruining the call stack of ycdldb.download_video for no good reason. --- ycdl/constants.py | 1 + ycdl/ycdldb.py | 25 +++++++------------------ 2 files changed, 8 insertions(+), 18 deletions(-) diff --git a/ycdl/constants.py b/ycdl/constants.py index 6c7aa95..13613dd 100644 --- a/ycdl/constants.py +++ b/ycdl/constants.py @@ -54,4 +54,5 @@ VIDEO_STATES = ['ignored', 'pending', 'downloaded'] DEFAULT_CONFIGURATION = { 'download_directory': '.', + 'queuefile_extension': 'ytqueue', } diff --git a/ycdl/ycdldb.py b/ycdl/ycdldb.py index b5fd3ae..5a5036f 100644 --- a/ycdl/ycdldb.py +++ b/ycdl/ycdldb.py @@ -15,10 +15,6 @@ from voussoirkit import pathclass from voussoirkit import sqlhelpers -def YOUTUBE_DL_COMMAND(video_id): - path = f'{video_id}.ytqueue' - open(path, 'w') - logging.basicConfig() logging.getLogger('googleapiclient.discovery').setLevel(logging.WARNING) logging.getLogger('requests.packages.urllib3.connectionpool').setLevel(logging.WARNING) @@ -242,8 +238,8 @@ class YCDLDBVideoMixin: def download_video(self, video, commit=True, force=False): ''' - Execute the `YOUTUBE_DL_COMMAND`, within the channel's associated - directory if applicable. + Create the queuefile within the channel's associated directory, or + the default directory from the config file. ''' if isinstance(video, ytapi.Video): video_id = video.id @@ -262,12 +258,12 @@ class YCDLDBVideoMixin: except exceptions.NoSuchChannel: download_directory = self.config['download_directory'] - os.makedirs(download_directory, exist_ok=True) + download_directory = pathclass.Path(download_directory) + os.makedirs(download_directory.absolute_path, exist_ok=True) - current_directory = os.getcwd() - os.chdir(download_directory) - self.youtube_dl_function(video_id) - os.chdir(current_directory) + extension = self.config['queuefile_extension'] + queuefile = download_directory.with_child(video_id).replace_extension(extension) + open(queuefile.absolute_path, 'a').close() video.mark_state('downloaded', commit=False) @@ -371,7 +367,6 @@ class YCDLDB( self, youtube, data_directory=None, - youtube_dl_function=None, skip_version_check=False, ): super().__init__() @@ -399,12 +394,6 @@ class YCDLDB( else: self._first_time_setup() - # DOWNLOAD COMMAND - if youtube_dl_function: - self.youtube_dl_function = youtube_dl_function - else: - self.youtube_dl_function = YOUTUBE_DL_COMMAND - # CONFIG self.config_filepath = self.data_directory.with_child(constants.DEFAULT_CONFIGNAME) self.load_config()