handle scientific timestamp string parsing
This commit is contained in:
parent
1e06c40a2c
commit
395de16974
|
|
@ -409,6 +409,13 @@ class PendingList(PendingIndex):
|
|||
if timestamp and isinstance(timestamp, float):
|
||||
return int(timestamp)
|
||||
|
||||
if timestamp and isinstance(timestamp, str):
|
||||
try:
|
||||
# scientific string
|
||||
return int(float(timestamp))
|
||||
except (TypeError, ValueError):
|
||||
pass
|
||||
|
||||
upload_date = video_data.get("upload_date")
|
||||
if upload_date:
|
||||
try:
|
||||
|
|
|
|||
|
|
@ -11,6 +11,12 @@ def test_returns_scientific_timestamp_if_present():
|
|||
assert result == 1513573200
|
||||
|
||||
|
||||
def test_returns_scientific_timestamp_string_if_present():
|
||||
video_data = {"timestamp": "1.5135732e9"}
|
||||
result = PendingList._extract_published(video_data)
|
||||
assert result == 1513573200
|
||||
|
||||
|
||||
def test_returns_timestamp_if_present():
|
||||
video_data = {"timestamp": 1508457600}
|
||||
result = PendingList._extract_published(video_data)
|
||||
|
|
|
|||
|
|
@ -225,6 +225,13 @@ class YoutubeVideo(YouTubeItem, YoutubeSubtitle):
|
|||
if timestamp and isinstance(timestamp, float):
|
||||
return int(timestamp)
|
||||
|
||||
if timestamp and isinstance(timestamp, str):
|
||||
try:
|
||||
# scientific string
|
||||
return int(float(timestamp))
|
||||
except (TypeError, ValueError):
|
||||
pass
|
||||
|
||||
upload_date = self.youtube_meta["upload_date"]
|
||||
if not upload_date:
|
||||
raise ValueError(
|
||||
|
|
|
|||
Loading…
Reference in New Issue