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.

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