]>
Raphaël G. Git Repositories - youtubedl/blob - test/test_write_info_json.py
de6d5180fc0a88a66b747548352fdf72775d7c00
9 # Allow direct execution
10 sys
.path
.append(os
.path
.dirname(os
.path
.dirname(os
.path
.abspath(__file__
))))
12 import youtube_dl
.YoutubeDL
13 import youtube_dl
.extractor
14 from youtube_dl
.utils
import *
16 PARAMETERS_FILE
= os
.path
.join(os
.path
.dirname(os
.path
.abspath(__file__
)), "parameters.json")
18 # General configuration (from __init__, not very elegant...)
19 jar
= compat_cookiejar
.CookieJar()
20 cookie_processor
= compat_urllib_request
.HTTPCookieProcessor(jar
)
21 proxy_handler
= compat_urllib_request
.ProxyHandler()
22 opener
= compat_urllib_request
.build_opener(proxy_handler
, cookie_processor
, YoutubeDLHandler())
23 compat_urllib_request
.install_opener(opener
)
25 class YoutubeDL(youtube_dl
.YoutubeDL
):
26 def __init__(self
, *args
, **kwargs
):
27 super(YoutubeDL
, self
).__init
__(*args
, **kwargs
)
28 self
.to_stderr
= self
.to_screen
30 with io
.open(PARAMETERS_FILE
, encoding
='utf-8') as pf
:
31 params
= json
.load(pf
)
32 params
['writeinfojson'] = True
33 params
['skip_download'] = True
34 params
['writedescription'] = True
36 TEST_ID
= 'BaW_jenozKc'
37 INFO_JSON_FILE
= TEST_ID
+ '.mp4.info.json'
38 DESCRIPTION_FILE
= TEST_ID
+ '.mp4.description'
39 EXPECTED_DESCRIPTION
= u
'''test chars: "'/\ä↭𝕐
41 This is a test video for youtube-dl.
43 For more information, contact phihag@phihag.de .'''
45 class TestInfoJSON(unittest
.TestCase
):
50 def test_info_json(self
):
51 ie
= youtube_dl
.extractor
.YoutubeIE()
52 ydl
= YoutubeDL(params
)
53 ydl
.add_info_extractor(ie
)
54 ydl
.download([TEST_ID
])
55 self
.assertTrue(os
.path
.exists(INFO_JSON_FILE
))
56 with io
.open(INFO_JSON_FILE
, 'r', encoding
='utf-8') as jsonf
:
58 self
.assertEqual(jd
['upload_date'], u
'20121002')
59 self
.assertEqual(jd
['description'], EXPECTED_DESCRIPTION
)
60 self
.assertEqual(jd
['id'], TEST_ID
)
61 self
.assertEqual(jd
['extractor'], 'youtube')
62 self
.assertEqual(jd
['title'], u
'''youtube-dl test video "'/\ä↭𝕐''')
63 self
.assertEqual(jd
['uploader'], 'Philipp Hagemeister')
65 self
.assertTrue(os
.path
.exists(DESCRIPTION_FILE
))
66 with io
.open(DESCRIPTION_FILE
, 'r', encoding
='utf-8') as descf
:
68 self
.assertEqual(descr
, EXPECTED_DESCRIPTION
)
71 if os
.path
.exists(INFO_JSON_FILE
):
72 os
.remove(INFO_JSON_FILE
)
73 if os
.path
.exists(DESCRIPTION_FILE
):
74 os
.remove(DESCRIPTION_FILE
)
76 if __name__
== '__main__':