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.

62 lines
2.2 KiB

  1. #!/usr/bin/env python
  2. from __future__ import unicode_literals
  3. # Allow direct execution
  4. import os
  5. import sys
  6. import unittest
  7. sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
  8. from test.helper import FakeYDL
  9. from youtube_dl.extractor.common import InfoExtractor
  10. from youtube_dl.extractor import YoutubeIE, get_info_extractor
  11. class TestIE(InfoExtractor):
  12. pass
  13. class TestInfoExtractor(unittest.TestCase):
  14. def setUp(self):
  15. self.ie = TestIE(FakeYDL())
  16. def test_ie_key(self):
  17. self.assertEqual(get_info_extractor(YoutubeIE.ie_key()), YoutubeIE)
  18. def test_html_search_regex(self):
  19. html = '<p id="foo">Watch this <a href="http://www.youtube.com/watch?v=BaW_jenozKc">video</a></p>'
  20. search = lambda re, *args: self.ie._html_search_regex(re, html, *args)
  21. self.assertEqual(search(r'<p id="foo">(.+?)</p>', 'foo'), 'Watch this video')
  22. def test_opengraph(self):
  23. ie = self.ie
  24. html = '''
  25. <meta name="og:title" content='Foo'/>
  26. <meta content="Some video's description " name="og:description"/>
  27. <meta property='og:image' content='http://domain.com/pic.jpg?key1=val1&amp;key2=val2'/>
  28. '''
  29. self.assertEqual(ie._og_search_title(html), 'Foo')
  30. self.assertEqual(ie._og_search_description(html), 'Some video\'s description ')
  31. self.assertEqual(ie._og_search_thumbnail(html), 'http://domain.com/pic.jpg?key1=val1&key2=val2')
  32. def test_html_search_meta(self):
  33. ie = self.ie
  34. html = '''
  35. <meta name="a" content="1" />
  36. <meta name='b' content='2'>
  37. <meta name="c" content='3'>
  38. <meta name=d content='4'>
  39. <meta property="e" content='5' >
  40. <meta content="6" name="f">
  41. '''
  42. self.assertEqual(ie._html_search_meta('a', html), '1')
  43. self.assertEqual(ie._html_search_meta('b', html), '2')
  44. self.assertEqual(ie._html_search_meta('c', html), '3')
  45. self.assertEqual(ie._html_search_meta('d', html), '4')
  46. self.assertEqual(ie._html_search_meta('e', html), '5')
  47. self.assertEqual(ie._html_search_meta('f', html), '6')
  48. if __name__ == '__main__':
  49. unittest.main()