]>
Raphaƫl G. Git Repositories - youtubedl/blob - test/test_YoutubeDL.py
f8cd1bdce9a64ac87ec83ab15130148f580a5291
3 # Allow direct execution
7 sys
.path
.insert(0, os
.path
.dirname(os
.path
.dirname(os
.path
.abspath(__file__
))))
9 from test
.helper
import FakeYDL
13 def __init__(self
, *args
, **kwargs
):
14 super(YDL
, self
).__init
__(*args
, **kwargs
)
15 self
.downloaded_info_dicts
= []
18 def process_info(self
, info_dict
):
19 self
.downloaded_info_dicts
.append(info_dict
)
21 def to_screen(self
, msg
):
25 class TestFormatSelection(unittest
.TestCase
):
26 def test_prefer_free_formats(self
):
27 # Same resolution => download webm
29 ydl
.params
['prefer_free_formats'] = True
31 {u
'ext': u
'webm', u
'height': 460},
32 {u
'ext': u
'mp4', u
'height': 460},
34 info_dict
= {u
'formats': formats
, u
'extractor': u
'test'}
35 ydl
.process_ie_result(info_dict
)
36 downloaded
= ydl
.downloaded_info_dicts
[0]
37 self
.assertEqual(downloaded
[u
'ext'], u
'webm')
39 # Different resolution => download best quality (mp4)
41 ydl
.params
['prefer_free_formats'] = True
43 {u
'ext': u
'webm', u
'height': 720},
44 {u
'ext': u
'mp4', u
'height': 1080},
46 info_dict
[u
'formats'] = formats
47 ydl
.process_ie_result(info_dict
)
48 downloaded
= ydl
.downloaded_info_dicts
[0]
49 self
.assertEqual(downloaded
[u
'ext'], u
'mp4')
51 # No prefer_free_formats => keep original formats order
53 ydl
.params
['prefer_free_formats'] = False
55 {u
'ext': u
'webm', u
'height': 720},
56 {u
'ext': u
'flv', u
'height': 720},
58 info_dict
[u
'formats'] = formats
59 ydl
.process_ie_result(info_dict
)
60 downloaded
= ydl
.downloaded_info_dicts
[0]
61 self
.assertEqual(downloaded
[u
'ext'], u
'flv')
63 def test_format_limit(self
):
65 {u
'format_id': u
'meh'},
66 {u
'format_id': u
'good'},
67 {u
'format_id': u
'great'},
68 {u
'format_id': u
'excellent'},
71 u
'formats': formats
, u
'extractor': u
'test', 'id': 'testvid'}
74 ydl
.process_ie_result(info_dict
)
75 downloaded
= ydl
.downloaded_info_dicts
[0]
76 self
.assertEqual(downloaded
[u
'format_id'], u
'excellent')
78 ydl
= YDL({'format_limit': 'good'})
79 assert ydl
.params
['format_limit'] == 'good'
80 ydl
.process_ie_result(info_dict
)
81 downloaded
= ydl
.downloaded_info_dicts
[0]
82 self
.assertEqual(downloaded
[u
'format_id'], u
'good')
84 ydl
= YDL({'format_limit': 'great', 'format': 'all'})
85 ydl
.process_ie_result(info_dict
)
86 self
.assertEqual(ydl
.downloaded_info_dicts
[0][u
'format_id'], u
'meh')
87 self
.assertEqual(ydl
.downloaded_info_dicts
[1][u
'format_id'], u
'good')
88 self
.assertEqual(ydl
.downloaded_info_dicts
[2][u
'format_id'], u
'great')
89 self
.assertTrue('3' in ydl
.msgs
[0])
92 ydl
.params
['format_limit'] = 'excellent'
93 ydl
.process_ie_result(info_dict
)
94 downloaded
= ydl
.downloaded_info_dicts
[0]
95 self
.assertEqual(downloaded
[u
'format_id'], u
'excellent')
97 def test_format_selection(self
):
99 {u
'format_id': u
'35', u
'ext': u
'mp4'},
100 {u
'format_id': u
'45', u
'ext': u
'webm'},
101 {u
'format_id': u
'47', u
'ext': u
'webm'},
102 {u
'format_id': u
'2', u
'ext': u
'flv'},
104 info_dict
= {u
'formats': formats
, u
'extractor': u
'test'}
106 ydl
= YDL({'format': u
'20/47'})
107 ydl
.process_ie_result(info_dict
)
108 downloaded
= ydl
.downloaded_info_dicts
[0]
109 self
.assertEqual(downloaded
['format_id'], u
'47')
111 ydl
= YDL({'format': u
'20/71/worst'})
112 ydl
.process_ie_result(info_dict
)
113 downloaded
= ydl
.downloaded_info_dicts
[0]
114 self
.assertEqual(downloaded
['format_id'], u
'35')
117 ydl
.process_ie_result(info_dict
)
118 downloaded
= ydl
.downloaded_info_dicts
[0]
119 self
.assertEqual(downloaded
['format_id'], u
'2')
121 ydl
= YDL({'format': u
'webm/mp4'})
122 ydl
.process_ie_result(info_dict
)
123 downloaded
= ydl
.downloaded_info_dicts
[0]
124 self
.assertEqual(downloaded
['format_id'], u
'47')
126 ydl
= YDL({'format': u
'3gp/40/mp4'})
127 ydl
.process_ie_result(info_dict
)
128 downloaded
= ydl
.downloaded_info_dicts
[0]
129 self
.assertEqual(downloaded
['format_id'], u
'35')
132 if __name__
== '__main__':