Skip to content

Commit

Permalink
feat: Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
bradenhilton committed Mar 2, 2023
0 parents commit 95f4504
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
__pycache__
*.egg-info/
*.pyc
24 changes: 24 additions & 0 deletions LICENSE
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/>
21 changes: 21 additions & 0 deletions README.md
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`.
6 changes: 6 additions & 0 deletions pyproject.toml
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
6 changes: 6 additions & 0 deletions setup.cfg
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:
44 changes: 44 additions & 0 deletions yt_dlp_plugins/postprocessor/fixup_mtime.py
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

0 comments on commit 95f4504

Please sign in to comment.