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