]>
Raphaƫl G. Git Repositories - youtubedl/blob - test/test_InfoExtractor.py
938466a800122211ab0414d9aa9de831951e2903
3 from __future__
import unicode_literals
5 # Allow direct execution
9 sys
.path
.insert(0, os
.path
.dirname(os
.path
.dirname(os
.path
.abspath(__file__
))))
11 from test
.helper
import FakeYDL
12 from youtube_dl
.extractor
.common
import InfoExtractor
13 from youtube_dl
.extractor
import YoutubeIE
, get_info_extractor
16 class TestIE(InfoExtractor
):
20 class TestInfoExtractor(unittest
.TestCase
):
22 self
.ie
= TestIE(FakeYDL())
24 def test_ie_key(self
):
25 self
.assertEqual(get_info_extractor(YoutubeIE
.ie_key()), YoutubeIE
)
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')
32 def test_opengraph(self
):
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&key2=val2'/>
38 <meta content='application/x-shockwave-flash' property='og:video:type'>
39 <meta content='Foo' property=og:foobar>
40 <meta name="og:test1" content='foo > < bar'/>
41 <meta name="og:test2" content="foo >//< bar"/>
43 self
.assertEqual(ie
._og
_search
_title
(html
), 'Foo')
44 self
.assertEqual(ie
._og
_search
_description
(html
), 'Some video\'s description ')
45 self
.assertEqual(ie
._og
_search
_thumbnail
(html
), 'http://domain.com/pic.jpg?key1=val1&key2=val2')
46 self
.assertEqual(ie
._og
_search
_video
_url
(html
, default
=None), None)
47 self
.assertEqual(ie
._og
_search
_property
('foobar', html
), 'Foo')
48 self
.assertEqual(ie
._og
_search
_property
('test1', html
), 'foo > < bar')
49 self
.assertEqual(ie
._og
_search
_property
('test2', html
), 'foo >//< bar')
51 def test_html_search_meta(self
):
54 <meta name="a" content="1" />
55 <meta name='b' content='2'>
56 <meta name="c" content='3'>
57 <meta name=d content='4'>
58 <meta property="e" content='5' >
59 <meta content="6" name="f">
62 self
.assertEqual(ie
._html
_search
_meta
('a', html
), '1')
63 self
.assertEqual(ie
._html
_search
_meta
('b', html
), '2')
64 self
.assertEqual(ie
._html
_search
_meta
('c', html
), '3')
65 self
.assertEqual(ie
._html
_search
_meta
('d', html
), '4')
66 self
.assertEqual(ie
._html
_search
_meta
('e', html
), '5')
67 self
.assertEqual(ie
._html
_search
_meta
('f', html
), '6')
69 if __name__
== '__main__':