You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.7 KiB

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