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.

66 lines
2.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. <meta content='application/x-shockwave-flash' property='og:video:type'>
  29. <meta content='Foo' property=og:foobar>
  30. '''
  31. self.assertEqual(ie._og_search_title(html), 'Foo')
  32. self.assertEqual(ie._og_search_description(html), 'Some video\'s description ')
  33. self.assertEqual(ie._og_search_thumbnail(html), 'http://domain.com/pic.jpg?key1=val1&key2=val2')
  34. self.assertEqual(ie._og_search_video_url(html, default=None), None)
  35. self.assertEqual(ie._og_search_property('foobar', html), 'Foo')
  36. def test_html_search_meta(self):
  37. ie = self.ie
  38. html = '''
  39. <meta name="a" content="1" />
  40. <meta name='b' content='2'>
  41. <meta name="c" content='3'>
  42. <meta name=d content='4'>
  43. <meta property="e" content='5' >
  44. <meta content="6" name="f">
  45. '''
  46. self.assertEqual(ie._html_search_meta('a', html), '1')
  47. self.assertEqual(ie._html_search_meta('b', html), '2')
  48. self.assertEqual(ie._html_search_meta('c', html), '3')
  49. self.assertEqual(ie._html_search_meta('d', html), '4')
  50. self.assertEqual(ie._html_search_meta('e', html), '5')
  51. self.assertEqual(ie._html_search_meta('f', html), '6')
  52. if __name__ == '__main__':
  53. unittest.main()