From 5929a7689c0eb863b7c21b969253f0d8a323244a Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Wed, 10 Nov 2021 22:19:41 -0800 Subject: [PATCH] Let download_video take download_directory, queuefile overrides. --- frontends/ycdl_cli.py | 19 ++++++++++++++++++- ycdl/ycdldb.py | 43 ++++++++++++++++++++++++++++++++++++++----- 2 files changed, 56 insertions(+), 6 deletions(-) diff --git a/frontends/ycdl_cli.py b/frontends/ycdl_cli.py index 0435355..c03b2aa 100644 --- a/frontends/ycdl_cli.py +++ b/frontends/ycdl_cli.py @@ -68,7 +68,12 @@ def download_video_argparse(args): needs_commit = False for video_id in pipeable.input_many(args.video_ids): video = ycdldb.get_video(video_id) - queuefile = ycdldb.download_video(video, force=args.force) + queuefile = ycdldb.download_video( + video, + download_directory=args.download_directory, + force=args.force, + queuefile_extension=args.queuefile_extension, + ) if queuefile is not None: needs_commit = True @@ -237,11 +242,21 @@ download_video: > ycdl_cli.py download_video video_id [video_id video_id...] flags: + --download_directory X: + By default, the queuefile will be placed in the channel's + download_directory if it has one, or the download_directory in the + ycdl.json config file. You can pass this argument to override both + of those. + --force: By default, a video that is already marked as downloaded will not be downloaded again. You can add this to make the queuefiles for those videos anyway. + --queuefile_extension X: + By default, the queuefile extension is taken from the channel or the + config file. You can pass this argument to override both of those. + Examples: > ycdl_cli.py download_video thOifuHs6eY > ycdl_cli.py download_video yJ-oASr_djo vHuFizITMdA --force @@ -337,7 +352,9 @@ def main(argv): p_download_video = subparsers.add_parser('download_video', aliases=['download-video']) p_download_video.add_argument('video_ids', nargs='+') + p_download_video.add_argument('--download_directory', '--download-directory', default=None) p_download_video.add_argument('--force', action='store_true') + p_download_video.add_argument('--queuefile_extension', '--queuefile-extension', default=None) p_download_video.add_argument('--yes', dest='autoyes', action='store_true') p_download_video.set_defaults(func=download_video_argparse) diff --git a/ycdl/ycdldb.py b/ycdl/ycdldb.py index 7aa1772..abe0b57 100644 --- a/ycdl/ycdldb.py +++ b/ycdl/ycdldb.py @@ -171,10 +171,32 @@ class YCDLDBVideoMixin: super().__init__() @worms.transaction - def download_video(self, video, force=False): + def download_video( + self, + video, + *, + download_directory=None, + force=False, + queuefile_extension=None, + ): ''' Create the queuefile within the channel's associated directory, or the default directory from the config file. + + download_directory: + By default, the queuefile will be placed in the channel's + download_directory if it has one, or the download_directory in the + ycdl.json config file. You can pass this argument to override both + of those. + + force: + By default, a video that is already marked as downloaded will not be + downloaded again. You can add this to make the queuefiles for those + videos anyway. + + queuefile_extension: + By default, the queuefile extension is taken from the channel or the + config file. You can pass this argument to override both of those. ''' if isinstance(video, objects.Video): pass @@ -191,14 +213,25 @@ class YCDLDBVideoMixin: try: channel = self.get_channel(video.author_id) - download_directory = channel.download_directory or self.config['download_directory'] - extension = channel.queuefile_extension or self.config['queuefile_extension'] except exceptions.NoSuchChannel: + channel = None + + if download_directory is not None: + download_directory = pathclass.Path(download_directory) + elif channel is not None: + download_directory = channel.download_directory or self.config['download_directory'] + else: download_directory = self.config['download_directory'] - extension = self.config['queuefile_extension'] + + if queuefile_extension is not None: + pass + elif channel is not None: + queuefile_extension = channel.queuefile_extension or self.config['queuefile_extension'] + else: + queuefile_extension = self.config['queuefile_extension'] download_directory = pathclass.Path(download_directory) - queuefile = download_directory.with_child(video.id).replace_extension(extension) + queuefile = download_directory.with_child(video.id).replace_extension(queuefile_extension) def create_queuefile(): log.info('Creating %s.', queuefile.absolute_path)