Skip to content

Commit

Permalink
fix: Fix error if timestamp is None
Browse files Browse the repository at this point in the history
  • Loading branch information
bradenhilton committed Aug 15, 2023
1 parent e2c781a commit 64bc89d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
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

0 comments on commit 64bc89d

Please sign in to comment.