Make default upload_/release_date a compat_str
authordf <fieldhouse@gmx.net>
Sun, 1 Aug 2021 08:42:57 +0000 (09:42 +0100)
committerdirkf <fieldhouse@gmx.net>
Sat, 26 Feb 2022 10:29:42 +0000 (10:29 +0000)
Ensures download tests pass in Python 2 as well as 3; also
add YoutubeDL tests for timestamp -> upload_date etc.

test/test_YoutubeDL.py
youtube_dl/YoutubeDL.py

index a35effe0e4adae4b76073f3a698b3f7866849994..f8c8e619cf9d5d4df5878ed99a7ce785ef1b4d33 100644 (file)
@@ -997,6 +997,25 @@ class TestYoutubeDL(unittest.TestCase):
         self.assertEqual(downloaded['extractor'], 'Video')
         self.assertEqual(downloaded['extractor_key'], 'Video')
 
+    def test_default_times(self):
+        """Test addition of missing upload/release/_date from /release_/timestamp"""
+        info = {
+            'id': '1234',
+            'url': TEST_URL,
+            'title': 'Title',
+            'ext': 'mp4',
+            'timestamp': 1631352900,
+            'release_timestamp': 1632995931,
+        }
+
+        params = {'simulate': True, }
+        ydl = FakeYDL(params)
+        out_info = ydl.process_ie_result(info)
+        self.assertTrue(isinstance(out_info['upload_date'], compat_str))
+        self.assertEqual(out_info['upload_date'], '20210911')
+        self.assertTrue(isinstance(out_info['release_date'], compat_str))
+        self.assertEqual(out_info['release_date'], '20210930')
+
 
 if __name__ == '__main__':
     unittest.main()
index fe30758ef9c9c846cded752107c54b8d3d765fb6..69736acffa6b32e3c4ac4a9d94c7688bc687ba3f 100755 (executable)
@@ -1529,7 +1529,7 @@ class YoutubeDL(object):
                 # see http://bugs.python.org/issue1646728)
                 try:
                     upload_date = datetime.datetime.utcfromtimestamp(info_dict[ts_key])
-                    info_dict[date_key] = upload_date.strftime('%Y%m%d')
+                    info_dict[date_key] = compat_str(upload_date.strftime('%Y%m%d'))
                 except (ValueError, OverflowError, OSError):
                     pass