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

set mtime for fragmented videos (such as DASH) #27138

Closed
wants to merge 2 commits into from
Closed

set mtime for fragmented videos (such as DASH) #27138

wants to merge 2 commits into from

Conversation

dotysan
Copy link

@dotysan dotysan commented Nov 21, 2020

Before submitting a pull request make sure you have:

In order to be accepted and merged into youtube-dl each piece of code must be in public domain or released under Unlicense. Check one of the following options:

  • I am the original author of this code and I am willing to release it under Unlicense
  • I am not the original author of this code but it is in public domain or released under Unlicense (provide reliable evidence)

What is the purpose of your pull request?

  • Bug fix
  • Improvement
  • New extractor
  • New feature

Description of your pull request and other information

set mtime for fragmented videos (such as DASH)

  • it is set to the mtime of the last fragment uploaded

See issue #18384.

 - it is set to the mtime of the last fragment uploaded
@dstftw
Copy link
Collaborator

dstftw commented Nov 21, 2020

This will set mtime for the final file number-of-fragment times. This is completely useless. mtime must be set one single time.
Another point that appears immediately - why the last fragment's mtime and not the first's or 42th's?

@dotysan
Copy link
Author

dotysan commented Nov 21, 2020

This will set mtime for the final file number-of-fragment times.

Agreed. Although the mtime of the last fragment is what is effective after the download is complete.

This is completely useless. mtime must be set one single time.

Is the call to os.utime() for each fragment really that expensive? I agree it would be more efficient to do it only once.

Another point that appears immediately - why the last fragment's mtime and not the first's or 42th's?

Because that's the last time the file was modified. I.e. when the last fragment finally uploaded.

 - cleaner solution, only call os.utime() after last fragment
@dotysan
Copy link
Author

dotysan commented Nov 23, 2020

OK @dstftw take another look at this PR. Indeed FileDownloader already calls os.utime() on every fragment, so there's no point in doing it twice on every fragment. I've stuffed it into a variable on the FragmentFD class. And now the syscall is just done once in _finish_frag_download().

@dotysan
Copy link
Author

dotysan commented Nov 23, 2020

mtime must be set one single time.

@dstftw BTW, it already calls os.utime() on every fragment here:

os.utime(filename, (time.time(), filetime))

This is in FileDownloader.try_utime() called from HttpFD.download(). And in this case of fragmented files it's just as wasteful, since we only need the mtime of the last fragment.

If you are truly concerned with eliminating wasteful syscalls, we should fix this too.

@@ -116,6 +116,7 @@ def _append_fragment(self, ctx, frag_content):
finally:
if self.__do_ytdl_file(ctx):
self._write_ytdl_file(ctx)
self.mtime = os.stat(ctx['fragment_filename_sanitized']).st_mtime
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing conceptually changed: you still request st_mtime unnecessarily n-1 times.

@dstftw
Copy link
Collaborator

dstftw commented Nov 23, 2020

mtime must be set one single time.

@dstftw BTW, it already calls os.utime() on every fragment here:

os.utime(filename, (time.time(), filetime))

This is in FileDownloader.try_utime() called from HttpFD.download(). And in this case of fragmented files it's just as wasteful, since we only need the mtime of the last fragment.

If you are truly concerned with eliminating wasteful syscalls, we should fix this too.

Calling os.utime on each separate fragment is perfectly legal since fragments are not necessarily removed after the download.

@dstftw dstftw closed this in f4415fa Nov 23, 2020
ThirumalaiK pushed a commit to ThirumalaiK/youtube-dl that referenced this pull request Jan 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants