Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Output Problem(EMBEDDING YOUTUBE-DL) #28488

Open
hbtalha opened this issue Mar 19, 2021 · 2 comments
Open

Update Output Problem(EMBEDDING YOUTUBE-DL) #28488

hbtalha opened this issue Mar 19, 2021 · 2 comments

Comments

@hbtalha
Copy link

hbtalha commented Mar 19, 2021

I can't parse the output that tells that the update has succeeded.(run from Qt QProcess)
When I run the update(-U), all the output I catch is this:

D:\Downloads>youtube-dl -U
Updating to version 2021.03.14 ...
Waiting for file handle to be closed ...

But with only that it can't be said for sure when the update has been completed since that info comes later:

D:\Downloads>youtube-dl -U
Updating to version 2021.03.14 ...
Waiting for file handle to be closed ...

D:\Downloads>Updated youtube-dl to version 2021.03.14.

There's no way to know how long after.

Is there a solution for this?

@pukkandan
Copy link
Contributor

pukkandan commented Mar 27, 2021

In windows, the exe cannot update itself directly. So youtube-dl opens a new process with a batch script which does the actual updating. The Waiting for file handle to be closed ... message is misleading since youtube-dl actually waits for 5sec before replacing the exe file irrespective of whether the file handle is actually closed or not.

The relevant code:

            bat = os.path.join(directory, 'youtube-dl-updater.bat')
            with io.open(bat, 'w') as batfile:
                batfile.write('''
@echo off
echo Waiting for file handle to be closed ...
ping 127.0.0.1 -n 5 -w 1000 > NUL
move /Y "%s.new" "%s" > NUL
echo Updated youtube-dl to version %s.
start /b "" cmd /c del "%%~f0"&exit /b"
                \n''' % (exe, exe, version_id))

            subprocess.Popen([bat])  # Continues to run in the background

You can either set a fixed sleep of ~10sec, or will need to watch if the subprocess has exited

@hbtalha
Copy link
Author

hbtalha commented Mar 28, 2021

You can either set a fixed sleep of ~10sec, or will need to watch if the subprocess has exited

That's what I did, thanks for the info though

pukkandan added a commit to yt-dlp/yt-dlp that referenced this issue May 25, 2021
Closes: #335, ytdl-org/youtube-dl#28488, ytdl-org/youtube-dl#5810, ytdl-org/youtube-dl#5994

In windows, a running executable cannot be replaced. So, the old updater worked by launching a batch script and then exiting, so that the batch script can replace the executable. However, this caused the above-mentioned issues.

The new method takes advantage of the fact that while the executable cannot be replaced or deleted, it can still be renamed. The current update process on windows is as follows:
1. Delete `yt-dlp.exe.old` if it exists
2. Download the new version as `yt-dlp.exe.new`
3. Rename the running exe to `yt-dlp.exe.old`
4. Rename `yt-dlp.exe.new` to `yt-dlp.exe`
5. Open a shell that deletes `yt-dlp.exe.old` and terminate

While we still use a subprocess, the actual update is already done before the app terminates and the batch script does not print anything to stdout/stderr. So this solves all the above issues
nixxo pushed a commit to nixxo/yt-dlp that referenced this issue Nov 22, 2021
Closes: yt-dlp#335, ytdl-org/youtube-dl#28488, ytdl-org/youtube-dl#5810, ytdl-org/youtube-dl#5994

In windows, a running executable cannot be replaced. So, the old updater worked by launching a batch script and then exiting, so that the batch script can replace the executable. However, this caused the above-mentioned issues.

The new method takes advantage of the fact that while the executable cannot be replaced or deleted, it can still be renamed. The current update process on windows is as follows:
1. Delete `yt-dlp.exe.old` if it exists
2. Download the new version as `yt-dlp.exe.new`
3. Rename the running exe to `yt-dlp.exe.old`
4. Rename `yt-dlp.exe.new` to `yt-dlp.exe`
5. Open a shell that deletes `yt-dlp.exe.old` and terminate

While we still use a subprocess, the actual update is already done before the app terminates and the batch script does not print anything to stdout/stderr. So this solves all the above issues
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants