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.

44 lines
1.5 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. if __name__ == '__main__':
  33. unittest.main()