1
0
mirror of https://github.com/yt-dlp/yt-dlp.git synced 2025-10-03 23:43:21 -04:00

[update] Self-restart after update

This commit is contained in:
pukkandan
2022-06-21 16:48:32 +05:30
parent 57e0f077a6
commit 8372be7469
2 changed files with 34 additions and 16 deletions

View File

@@ -26,7 +26,7 @@ from .postprocessor import (
MetadataFromFieldPP,
MetadataParserPP,
)
from .update import run_update
from .update import Updater
from .utils import (
NO_DEFAULT,
POSTPROCESS_WHEN,
@@ -879,17 +879,23 @@ def _real_main(argv=None):
return
with YoutubeDL(ydl_opts) as ydl:
pre_process = opts.update_self or opts.rm_cachedir
actual_use = all_urls or opts.load_info_filename
if opts.rm_cachedir:
ydl.cache.remove()
if opts.update_self and run_update(ydl) and actual_use:
# If updater returns True, exit. Required for windows
return 100, 'ERROR: The program must exit for the update to complete'
updater = Updater(ydl)
if opts.update_self and updater.update() and actual_use:
if updater.cmd:
return updater.restart()
# This code is reachable only for zip variant in py < 3.10
# It makes sense to exit here, but the old behavior is to continue
ydl.report_warning('Restart yt-dlp to use the updated version')
# return 100, 'ERROR: The program must exit for the update to complete'
if not actual_use:
if opts.update_self or opts.rm_cachedir:
if pre_process:
return ydl._download_retcode
ydl.warn_if_short_id(sys.argv[1:] if argv is None else argv)