]>
Raphaël G. Git Repositories - youtubedl/blob - test/test_write_info_json.py
0396ef26283f58c05ee261b0cf23773d462ad103
3 from __future__
import unicode_literals
5 # Allow direct execution
9 sys
.path
.insert(0, os
.path
.dirname(os
.path
.dirname(os
.path
.abspath(__file__
))))
11 from test
.helper
import get_params
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
+ '.info.json'
35 DESCRIPTION_FILE
= TEST_ID
+ '.mp4.description'
36 EXPECTED_DESCRIPTION
= '''test chars: "'/\ä↭𝕐
37 test URL: https://github.com/rg3/youtube-dl/issues/1892
39 This is a test video for youtube-dl.
41 For more information, contact phihag@phihag.de .'''
44 class TestInfoJSON(unittest
.TestCase
):
49 def test_info_json(self
):
50 ie
= youtube_dl
.extractor
.YoutubeIE()
51 ydl
= YoutubeDL(params
)
52 ydl
.add_info_extractor(ie
)
53 ydl
.download([TEST_ID
])
54 self
.assertTrue(os
.path
.exists(INFO_JSON_FILE
))
55 with io
.open(INFO_JSON_FILE
, 'r', encoding
='utf-8') as jsonf
:
57 self
.assertEqual(jd
['upload_date'], '20121002')
58 self
.assertEqual(jd
['description'], EXPECTED_DESCRIPTION
)
59 self
.assertEqual(jd
['id'], TEST_ID
)
60 self
.assertEqual(jd
['extractor'], 'youtube')
61 self
.assertEqual(jd
['title'], '''youtube-dl test video "'/\ä↭𝕐''')
62 self
.assertEqual(jd
['uploader'], 'Philipp Hagemeister')
64 self
.assertTrue(os
.path
.exists(DESCRIPTION_FILE
))
65 with io
.open(DESCRIPTION_FILE
, 'r', encoding
='utf-8') as descf
:
67 self
.assertEqual(descr
, EXPECTED_DESCRIPTION
)
70 if os
.path
.exists(INFO_JSON_FILE
):
71 os
.remove(INFO_JSON_FILE
)
72 if os
.path
.exists(DESCRIPTION_FILE
):
73 os
.remove(DESCRIPTION_FILE
)
75 if __name__
== '__main__':