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

fix: Fix error if timestamp is None #4

Merged
merged 1 commit into from
Aug 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = yt-dlp-FixupMtime
version = 1.1.0
version = 1.1.1

[options]
packages = find_namespace:
Expand Down
6 changes: 6 additions & 0 deletions test/test_fixup_mtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ def setUp(self):
def tearDown(self):
shutil.rmtree(self.temp_dir)

def test__striptime_or_none_with_none_timestamp(self):
timestamp = None
format_code = self.pp._mtime_format
expected = None
self.assertEqual(self.pp._strptime_or_none(timestamp, format_code), expected)

def test__strptime_or_none_with_invalid_timestamp(self):
timestamp = 'foobar'
format_code = self.pp._mtime_format
Expand Down
4 changes: 3 additions & 1 deletion yt_dlp_plugins/postprocessor/fixup_mtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ def __init__(self, downloader=None, mtime_key: str = 'mtime', mtime_format: str
self._mtime_key = mtime_key
self._mtime_format = re.sub(r'%%', '%', mtime_format)

def _strptime_or_none(self, timestamp: Union[float, int, str], format_code: str) -> Optional[datetime.datetime]:
def _strptime_or_none(self, timestamp: Union[float, int, str, None], format_code: str) -> Optional[datetime.datetime]:
if timestamp is None:
return None
if isinstance(timestamp, (float, int)):
return datetime.datetime.fromtimestamp(timestamp, datetime.timezone.utc)
for code in [format_code] + date_formats(day_first=True):
Expand Down