generated from yt-dlp/yt-dlp-sample-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 95f4504
Showing
6 changed files
with
104 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
__pycache__ | ||
*.egg-info/ | ||
*.pyc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
This is free and unencumbered software released into the public domain. | ||
|
||
Anyone is free to copy, modify, publish, use, compile, sell, or | ||
distribute this software, either in source code form or as a compiled | ||
binary, for any purpose, commercial or non-commercial, and by any | ||
means. | ||
|
||
In jurisdictions that recognize copyright laws, the author or authors | ||
of this software dedicate any and all copyright interest in the | ||
software to the public domain. We make this dedication for the benefit | ||
of the public at large and to the detriment of our heirs and | ||
successors. We intend this dedication to be an overt act of | ||
relinquishment in perpetuity of all present and future rights to this | ||
software under copyright law. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR | ||
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, | ||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | ||
OTHER DEALINGS IN THE SOFTWARE. | ||
|
||
For more information, please refer to <http://unlicense.org/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# yt-dlp-FixupMtime | ||
|
||
A [yt-dlp](https://github.com/yt-dlp/yt-dlp) postprocessor [plugin](https://github.com/yt-dlp/yt-dlp#plugins) which sets the mtime of all files to a given datetime value by key. | ||
|
||
NOTE: This postprocessor should not be run before files are downloaded. | ||
|
||
## Installation | ||
|
||
Requires yt-dlp `2023.01.02` or above. | ||
|
||
You can install this package with pip: | ||
|
||
```console | ||
python3 -m pip install -U https://github.com/bradenhilton/yt-dlp-FixupMtime/archive/master.zip | ||
``` | ||
|
||
See [installing yt-dlp plugins](https://github.com/yt-dlp/yt-dlp#installing-plugins) for the other methods this plugin package can be installed. | ||
|
||
## Usage | ||
|
||
Pass `--use-postprocessor FixupMtime:mtime_key=<key>`, replacing `<key>` with your chosen key to activate the postprocessor e.g. `--use-postprocessor FixupMtime:mtime_key=upload_date`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[build-system] | ||
requires = ["setuptools"] | ||
build-backend = "setuptools.build_meta" | ||
|
||
[tool.distutils.bdist_wheel] | ||
universal = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[metadata] | ||
name = yt-dlp-FixupMtime | ||
version = 1.0.0 | ||
|
||
[options] | ||
packages = find_namespace: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import datetime | ||
import os | ||
from yt_dlp.postprocessor.common import PostProcessor | ||
from yt_dlp.utils import traverse_obj, datetime_from_str, replace_extension | ||
|
||
|
||
class FixupMtimePP(PostProcessor): | ||
def __init__(self, downloader=None, mtime_key=None): | ||
super().__init__(downloader) | ||
self._mtime_key = mtime_key | ||
|
||
def run(self, info): | ||
filepath = info.get('filepath') | ||
|
||
if filepath: | ||
files = { | ||
filepath, | ||
info.get('__infojson_filename'), | ||
} | ||
|
||
if self.get_param('keepvideo', False): | ||
for format in traverse_obj(info, ('requested_formats', ...)) or []: | ||
format_id = format.get('format_id') | ||
format_ext = format.get('ext') | ||
|
||
if format_id and format_ext: | ||
files.add(replace_extension( | ||
filepath, f'f{format_id}.{format_ext}')) | ||
|
||
for path in info.get('__files_to_move'): | ||
files.add(path) | ||
|
||
if self.get_param('writedescription', False): | ||
files.add(replace_extension(filepath, 'description')) | ||
|
||
mtime = datetime.datetime.fromtimestamp(os.stat( | ||
filepath).st_mtime, datetime.timezone.utc) if self._mtime_key == 'mtime' else datetime_from_str(info.get(self._mtime_key)) | ||
|
||
if mtime: | ||
self.to_screen( | ||
f'Setting mtime of files to {mtime.isoformat()}') | ||
for file in files: | ||
self.try_utime(file, mtime.timestamp(), mtime.timestamp()) | ||
return [], info |