]>
Commit | Line | Data |
---|---|---|
e028d0d1 JMF |
1 | #!/usr/bin/env python |
2 | ||
3 | import sys | |
4 | import unittest | |
5 | ||
6 | # Allow direct execution | |
7 | import os | |
8 | sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) | |
9 | ||
10 | from helper import FakeYDL, parameters | |
11 | ||
12 | class YDL(FakeYDL): | |
13 | def __init__(self): | |
14 | super(YDL, self).__init__() | |
15 | self.downloaded_info_dicts = [] | |
16 | def process_info(self, info_dict): | |
17 | self.downloaded_info_dicts.append(info_dict) | |
18 | ||
19 | class TestFormatSelection(unittest.TestCase): | |
20 | def test_prefer_free_formats(self): | |
21 | # Same resolution => download webm | |
22 | ydl = YDL() | |
23 | ydl.params['prefer_free_formats'] = True | |
24 | formats = [{u'ext': u'webm', u'height': 460},{u'ext': u'mp4', u'height': 460}] | |
25 | info_dict = {u'formats': formats, u'extractor': u'test'} | |
26 | ydl.process_ie_result(info_dict) | |
27 | downloaded = ydl.downloaded_info_dicts[0] | |
28 | self.assertEqual(downloaded[u'ext'], u'webm') | |
29 | ||
30 | # Different resolution => download best quality (mp4) | |
31 | ydl = YDL() | |
32 | ydl.params['prefer_free_formats'] = True | |
33 | formats = [{u'ext': u'webm', u'height': 720},{u'ext': u'mp4',u'height': 1080}] | |
34 | info_dict[u'formats'] = formats | |
35 | ydl.process_ie_result(info_dict) | |
36 | downloaded = ydl.downloaded_info_dicts[0] | |
37 | self.assertEqual(downloaded[u'ext'], u'mp4') | |
38 | ||
39 | # No prefer_free_formats => keep original formats order | |
40 | ydl = YDL() | |
41 | ydl.params['prefer_free_formats'] = False | |
42 | formats = [{u'ext': u'webm', u'height': 720},{u'ext': u'flv',u'height': 720}] | |
43 | info_dict[u'formats'] = formats | |
44 | ydl.process_ie_result(info_dict) | |
45 | downloaded = ydl.downloaded_info_dicts[0] | |
46 | self.assertEqual(downloaded[u'ext'], u'flv') | |
47 | ||
48 | if __name__ == '__main__': | |
49 | unittest.main() |