diff options
author | Jeff Crouse <jefftimesten@gmail.com> | 2013-01-05 15:03:54 -0500 |
---|---|---|
committer | Jeff Crouse <jefftimesten@gmail.com> | 2013-01-05 15:03:54 -0500 |
commit | 258d5850c91e0d37a36c6bae0a25314f8149b05a (patch) | |
tree | 7d87df8436a588a4338a460499d8614006b6254a /test/test_write_info_json.py | |
parent | 187da2c093ad1013ea714a464e615de9aa773482 (diff) | |
parent | 8e5f7618704805caf9fac093e604834237a7965c (diff) |
Merge branch 'master' of https://github.com/rg3/youtube-dl
Conflicts:
.gitignore
LATEST_VERSION
Makefile
youtube-dl
youtube-dl.exe
youtube_dl/InfoExtractors.py
youtube_dl/__init__.py
Diffstat (limited to 'test/test_write_info_json.py')
-rw-r--r-- | test/test_write_info_json.py | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/test/test_write_info_json.py b/test/test_write_info_json.py new file mode 100644 index 000000000..8134dda37 --- /dev/null +++ b/test/test_write_info_json.py @@ -0,0 +1,77 @@ +#!/usr/bin/env python +# coding: utf-8 + +import json +import os +import sys +import unittest + +# Allow direct execution +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) + +import youtube_dl.FileDownloader +import youtube_dl.InfoExtractors +from youtube_dl.utils import * + +PARAMETERS_FILE = os.path.join(os.path.dirname(os.path.abspath(__file__)), "parameters.json") + +# General configuration (from __init__, not very elegant...) +jar = compat_cookiejar.CookieJar() +cookie_processor = compat_urllib_request.HTTPCookieProcessor(jar) +proxy_handler = compat_urllib_request.ProxyHandler() +opener = compat_urllib_request.build_opener(proxy_handler, cookie_processor, YoutubeDLHandler()) +compat_urllib_request.install_opener(opener) + +class FileDownloader(youtube_dl.FileDownloader): + def __init__(self, *args, **kwargs): + youtube_dl.FileDownloader.__init__(self, *args, **kwargs) + self.to_stderr = self.to_screen + +with io.open(PARAMETERS_FILE, encoding='utf-8') as pf: + params = json.load(pf) +params['writeinfojson'] = True +params['skip_download'] = True +params['writedescription'] = True + +TEST_ID = 'BaW_jenozKc' +INFO_JSON_FILE = TEST_ID + '.mp4.info.json' +DESCRIPTION_FILE = TEST_ID + '.mp4.description' +EXPECTED_DESCRIPTION = u'''test chars: "'/\ä↭𝕐 + +This is a test video for youtube-dl. + +For more information, contact phihag@phihag.de .''' + +class TestInfoJSON(unittest.TestCase): + def setUp(self): + # Clear old files + self.tearDown() + + def test_info_json(self): + ie = youtube_dl.InfoExtractors.YoutubeIE() + fd = FileDownloader(params) + fd.add_info_extractor(ie) + fd.download([TEST_ID]) + self.assertTrue(os.path.exists(INFO_JSON_FILE)) + with io.open(INFO_JSON_FILE, 'r', encoding='utf-8') as jsonf: + jd = json.load(jsonf) + self.assertEqual(jd['upload_date'], u'20121002') + self.assertEqual(jd['description'], EXPECTED_DESCRIPTION) + self.assertEqual(jd['id'], TEST_ID) + self.assertEqual(jd['extractor'], 'youtube') + self.assertEqual(jd['title'], u'''youtube-dl test video "'/\ä↭𝕐''') + self.assertEqual(jd['uploader'], 'Philipp Hagemeister') + + self.assertTrue(os.path.exists(DESCRIPTION_FILE)) + with io.open(DESCRIPTION_FILE, 'r', encoding='utf-8') as descf: + descr = descf.read() + self.assertEqual(descr, EXPECTED_DESCRIPTION) + + def tearDown(self): + if os.path.exists(INFO_JSON_FILE): + os.remove(INFO_JSON_FILE) + if os.path.exists(DESCRIPTION_FILE): + os.remove(DESCRIPTION_FILE) + +if __name__ == '__main__': + unittest.main() |