]>
Raphaël G. Git Repositories - youtubedl/blob - test/test_write_info_json.py
a5b6f6972df48f6b7cdcfebc3ea32d11c6a27afa
4 # Allow direct execution
8 sys
.path
.insert(0, os
.path
.dirname(os
.path
.dirname(os
.path
.abspath(__file__
))))
10 from test
.helper
import get_params
, global_setup
17 import youtube_dl
.YoutubeDL
18 import youtube_dl
.extractor
21 class YoutubeDL(youtube_dl
.YoutubeDL
):
22 def __init__(self
, *args
, **kwargs
):
23 super(YoutubeDL
, self
).__init
__(*args
, **kwargs
)
24 self
.to_stderr
= self
.to_screen
27 'writeinfojson': True,
28 'skip_download': True,
29 'writedescription': True,
33 TEST_ID
= 'BaW_jenozKc'
34 INFO_JSON_FILE
= TEST_ID
+ '.mp4.info.json'
35 DESCRIPTION_FILE
= TEST_ID
+ '.mp4.description'
36 EXPECTED_DESCRIPTION
= u
'''test chars: "'/\ä↭𝕐
38 This is a test video for youtube-dl.
40 For more information, contact phihag@phihag.de .'''
43 class TestInfoJSON(unittest
.TestCase
):
48 def test_info_json(self
):
49 ie
= youtube_dl
.extractor
.YoutubeIE()
50 ydl
= YoutubeDL(params
)
51 ydl
.add_info_extractor(ie
)
52 ydl
.download([TEST_ID
])
53 self
.assertTrue(os
.path
.exists(INFO_JSON_FILE
))
54 with io
.open(INFO_JSON_FILE
, 'r', encoding
='utf-8') as jsonf
:
56 self
.assertEqual(jd
['upload_date'], u
'20121002')
57 self
.assertEqual(jd
['description'], EXPECTED_DESCRIPTION
)
58 self
.assertEqual(jd
['id'], TEST_ID
)
59 self
.assertEqual(jd
['extractor'], 'youtube')
60 self
.assertEqual(jd
['title'], u
'''youtube-dl test video "'/\ä↭𝕐''')
61 self
.assertEqual(jd
['uploader'], 'Philipp Hagemeister')
63 self
.assertTrue(os
.path
.exists(DESCRIPTION_FILE
))
64 with io
.open(DESCRIPTION_FILE
, 'r', encoding
='utf-8') as descf
:
66 self
.assertEqual(descr
, EXPECTED_DESCRIPTION
)
69 if os
.path
.exists(INFO_JSON_FILE
):
70 os
.remove(INFO_JSON_FILE
)
71 if os
.path
.exists(DESCRIPTION_FILE
):
72 os
.remove(DESCRIPTION_FILE
)
74 if __name__
== '__main__':