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 to video publish date #18384

Open
codl opened this issue Dec 3, 2018 · 3 comments
Open

set mtime to video publish date #18384

codl opened this issue Dec 3, 2018 · 3 comments

Comments

@codl
Copy link

@codl codl commented Dec 3, 2018

Make sure you are using the latest version: run youtube-dl --version and ensure your version is 2018.12.03. If it's not, read this FAQ entry and update. Issues with outdated version will be rejected.

  • I've verified and I assure that I'm running youtube-dl 2018.12.03

Before submitting an issue make sure you have:

  • At least skimmed through the README, most notably the FAQ and BUGS sections
  • Searched the bugtracker for similar issues including closed ones
  • Checked that provided video/audio/playlist URLs (if any) are alive and playable in a browser

What is the purpose of your issue?

  • Bug report (encountered problems with youtube-dl)
  • Site support request (request for adding support for a new site)
  • Feature request (request for a new functionality)
  • Question
  • Other

Description of your issue, suggested solution and other information

this is a followup to #18383 in which I found out that the mtime is only set according to the Last-Modified HTTP headers, and doesn't work for videos downloaded with DASH. I find this counter-intuitive: having downloaded videos and seen that the mtime was set to — as far as I could tell — the upload date, I expected this to happen all the time until it randomly didn't work for some videos.

I think that, whenever the upload time is available, it should be used for the final file's mtime in place of Last-Modified.

@dotysan
Copy link

@dotysan dotysan commented Apr 13, 2019

I just tested and it appears that all DASH segments indeed had the same/proper mtime when fetched via http.py. However when the segments are stitched together, the mtime is lost.

@dotysan
Copy link

@dotysan dotysan commented Apr 14, 2019

Not a pull request yet, because I'm new to the code in this project and haven't run the unit tests. But this seems to do the job!

diff --git a/youtube_dl/downloader/fragment.py b/youtube_dl/downloader/fragment.py
index 917f6dc01..37edcc900 100644
--- a/youtube_dl/downloader/fragment.py
+++ b/youtube_dl/downloader/fragment.py
@@ -116,6 +116,10 @@ class FragmentFD(FileDownloader):
         finally:
             if self.__do_ytdl_file(ctx):
                 self._write_ytdl_file(ctx)
+            try:
+                os.utime(ctx['tmpfilename'], (time.time(), os.stat(ctx['fragment_filename_sanitized']).st_mtime))
+            except Exception:
+                pass
             if not self.params.get('keep_fragments', False):
                 os.remove(encodeFilename(ctx['fragment_filename_sanitized']))
             del ctx['fragment_filename_sanitized']

In summary, it leverages the fact that every fragment/segment already has an mtime set from the last-modified header. So it just re-sets the mtime of the working/temp file from the fragment file. Which in turn, seems to be preserved in the finalized file of all fragments.

Feedback?

@reallyuniquename
Copy link

@reallyuniquename reallyuniquename commented Jul 15, 2020

Has this been addressed? I'm running latest version and it seems mtime has no effect on fragmented Twitch VODs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.