diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 81fa257..70eac23 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -59,7 +59,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-22.04, windows-2022] - python-version: ["3.9", "3.10", "3.11", "3.12", "3.13", "pypy3.9"] + python-version: ["3.9", "3.10", "3.11", "3.12", "3.13", "pypy3.10"] steps: - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 diff --git a/pyproject.toml b/pyproject.toml index e99605f..ce79934 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "hatchling.build" [project] name = "yt-dlp-fixupmtime" -version = "1.1.1" +version = "1.1.2" description = "A yt-dlp postprocessor plugin to set the mtime of all files to a given datetime value by key" requires-python = ">=3.9" license = { file = "LICENSE" } diff --git a/test/test_fixup_mtime.py b/test/test_fixup_mtime.py index ec04d48..7988094 100755 --- a/test/test_fixup_mtime.py +++ b/test/test_fixup_mtime.py @@ -16,19 +16,23 @@ class TestFixupMtimePP(unittest.TestCase): def setUp(self): self.pp = FixupMtimePP() + self.info = {"filepath": "test äةُ한汉漢なナอัй.mp4", "upload_date": "20120101"} # Create a temporary directory of files, set their initial mtime + file_path = Path(self.info["filepath"]) self.temp_dir = tempfile.mkdtemp() self.files = [ - Path(self.temp_dir, filename) for filename in ["test.mp4", "test.jpg", "test.info.json", "test2.mp4"] + file_path, + file_path.with_suffix(""), + file_path.with_suffix(".jpg"), + file_path.with_suffix(".info.json"), + Path("test2.mp4"), ] self.initial_mtime = 1234567890.0 for path in self.files: path.touch() os.utime(path, (self.initial_mtime, self.initial_mtime)) - self.info = {"filepath": self.files[0], "upload_date": "20120101"} - def tearDown(self): shutil.rmtree(self.temp_dir) @@ -70,7 +74,7 @@ def test__strptime_or_none_with_valid_string_and_valid_format_code(self): def test__get_related_files(self): filepath = self.info.get("filepath") - expected = [path for path in self.files if path.name in ["test.mp4", "test.jpg", "test.info.json"]] + expected = list(filter(lambda fpath: not fpath.name.startswith("test2"), self.files)) self.assertCountEqual(self.pp._get_related_files(filepath), expected) # noqa: PT009 def test__get_mtime_with_existing_mtime(self): @@ -102,9 +106,10 @@ def test_run(self): self.pp._mtime_format = "%Y%m%d" expected = datetime(year=2012, month=1, day=1, tzinfo=timezone.utc).timestamp() self.pp.run(self.info) - for path in self.files[:3]: - assert os.path.getmtime(path) == expected - assert os.path.getmtime(self.files[3]) != expected + for file in list(filter(lambda fpath: not fpath.name.startswith("test2"), self.files)): + assert file.stat().st_mtime == expected + for file in list(filter(lambda fpath: fpath.name.startswith("test2"), self.files)): + assert file.stat().st_mtime != expected if __name__ == "__main__": diff --git a/yt_dlp_plugins/postprocessor/fixup_mtime.py b/yt_dlp_plugins/postprocessor/fixup_mtime.py index 05f67aa..048c146 100644 --- a/yt_dlp_plugins/postprocessor/fixup_mtime.py +++ b/yt_dlp_plugins/postprocessor/fixup_mtime.py @@ -11,6 +11,7 @@ if TYPE_CHECKING: from collections.abc import Iterable + from yt_dlp.postprocessor.common import PostProcessor from yt_dlp.utils import date_formats @@ -34,7 +35,16 @@ def _strptime_or_none(self, timestamp: float | str | None, format_code: str) -> def _get_related_files(self, filepath: Path | str) -> list[Path]: if isinstance(filepath, str): filepath = Path(filepath) - return [Path(path) for path in filepath.parent.glob(f"{glob.escape(filepath.stem)}.*") if path.is_file()] + directory = filepath.parent + base_name = glob.escape(filepath.stem) + files_with_extension = directory.glob(f"{base_name}.*") + files = [fpath for fpath in files_with_extension if fpath.is_file()] + file_no_extension = directory / base_name + if file_no_extension.exists() and file_no_extension.is_file(): + files.append(file_no_extension) + if filepath not in files: + files.insert(0, filepath) + return files def _get_mtime(self, filepath: Path, info: dict, mtime_key: str) -> float | int | str | None: return os.path.getmtime(filepath) if mtime_key == "mtime" else info.get(mtime_key)