Let download_video take download_directory, queuefile overrides.

This commit is contained in:
voussoir 2021-11-10 22:19:41 -08:00
parent 074f33342d
commit 5929a7689c
No known key found for this signature in database
GPG key ID: 5F7554F8C26DACCB
2 changed files with 56 additions and 6 deletions

View file

@ -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>
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)

View file

@ -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)