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