Repository: yt-dlp
Issue: [Feature Request] Expand `--mtime` to allow additional sources
Labels: enhancement

<!--

######################################################################
  WARNING!
  IGNORING THE FOLLOWING TEMPLATE WILL RESULT IN ISSUE CLOSED AS INCOMPLETE
######################################################################

-->


## Checklist

<!--
Carefully read and work through this check list in order to prevent the most common mistakes and misuse of yt-dlp:
- First of, make sure you are using the latest version of yt-dlp. Run `yt-dlp --version` and ensure your version is 2021.09.02. If it's not, see https://github.com/yt-dlp/yt-dlp on how to update. Issues with outdated version will be REJECTED.
- Search the bugtracker for similar feature requests: https://github.com/yt-dlp/yt-dlp. DO NOT post duplicates.
- Finally, put x into all relevant boxes like this [x] (Dont forget to delete the empty space)
-->

- [x] I'm reporting a feature request
- [x] I've verified that I'm running yt-dlp version **2021.09.02**
- [x] I've searched the bugtracker for similar feature requests including closed ones


## Description

<!--
Provide an explanation of your issue in an arbitrary form. Please make sure the description is worded well enough to be understood, see https://github.com/ytdl-org/youtube-dl#is-the-description-of-the-issue-itself-sufficient. Provide any additional information, suggested solution and as much context and examples as possible.
-->

~Please see [my gist](https://gist.github.com/bradenhilton/7e0bbcb32acc1a6792c476adbac73581) for current workarounds.~

EDIT: I created a [plugin](https://github.com/bradenhilton/yt-dlp-FixupMtime) which I believe should handle most use cases.

---

The main issue behind this request is the lack of a built-in way to set the mtime of the file to its upload date (if available). For relatively new files, the Last Modified header and upload date are often identical or extremely similar, so this does not help much there. However, this doesn't bear out for files which are much older, where the difference can sometimes be in the years.

It's possible to achieve this currently by using output templates within an `exec` string, or by reading a file's `DATE` tag with `ffprobe`/`mediainfo` etc., and converting the value to a DateTime then applying it to the file modification time.

I am not sure how feasible it would be to implement something like this, but I figured I would put forward some (admittedly very similar) proposals anyway.

### Proposal 1
- Leave `--mtime` as it is currently
- Add a new option `--mtime-sources SOURCES`, which can either be used in addition to, or implicitly enable `--mtime`, and where `SOURCES` is one of:
    - A single date-like source (e.g. `header`, `upload_date`/`release_date`), where:
        - If the desired source is not available, do one of the following:
            - Fallback to the Last Modified header
            - Do not change the mtime of the file
    - A comma-separated list of date-like sources, in order of preference, where:
        - If a source is not available, try the next one
        - If the sources list has been exhausted and no sources were available, do one of the following:
            - Fallback to the Last Modified header
            - Do not change the mtime of the file

### Proposal 2
- Change `--mtime` to `--mtime SOURCES`, where `SOURCES` is optional and one of:
    - A single date-like source (e.g. `header`, `upload_date`/`release_date`), where:
        - If the desired source is not available, do one of the following:
            - Fallback to the Last Modified header
            - Do not change the mtime of the file
    - A comma-separated list of date-like sources, in order of preference, where:
        - If a source is not available, try the next one
        - If the sources list has been exhausted and no sources were available, do one of the following:
            - Fallback to the Last Modified header
            - Do not change the mtime of the file

I may come back to edit this if I notice any errors or improvements that could be made.