]> git.bitcoin.ninja Git - youtube-dl/blob - youtube_dl/extractor/pyvideo.py
Some pep8 style fixes
[youtube-dl] / youtube_dl / extractor / pyvideo.py
1 import re
2 import os
3
4 from .common import InfoExtractor
5
6
7 class PyvideoIE(InfoExtractor):
8     _VALID_URL = r'(?:http://)?(?:www\.)?pyvideo\.org/video/(?P<id>\d+)/(.*)'
9     _TESTS = [{
10         u'url': u'http://pyvideo.org/video/1737/become-a-logging-expert-in-30-minutes',
11         u'file': u'24_4WWkSmNo.mp4',
12         u'md5': u'de317418c8bc76b1fd8633e4f32acbc6',
13         u'info_dict': {
14             u"title": u"Become a logging expert in 30 minutes",
15             u"description": u"md5:9665350d466c67fb5b1598de379021f7",
16             u"upload_date": u"20130320",
17             u"uploader": u"NextDayVideo",
18             u"uploader_id": u"NextDayVideo",
19         },
20         u'add_ie': ['Youtube'],
21     },
22     {
23         u'url': u'http://pyvideo.org/video/2542/gloriajw-spotifywitherikbernhardsson182m4v',
24         u'md5': u'5fe1c7e0a8aa5570330784c847ff6d12',
25         u'info_dict': {
26             u'id': u'2542',
27             u'ext': u'm4v',
28             u'title': u'Gloriajw-SpotifyWithErikBernhardsson182',
29         },
30     },
31     ]
32
33     def _real_extract(self, url):
34         mobj = re.match(self._VALID_URL, url)
35         video_id = mobj.group('id')
36         webpage = self._download_webpage(url, video_id)
37         m_youtube = re.search(r'(https?://www\.youtube\.com/watch\?v=.*)', webpage)
38
39         if m_youtube is not None:
40             return self.url_result(m_youtube.group(1), 'Youtube')
41
42         title = self._html_search_regex(r'<div class="section">.*?<h3>([^>]+?)</h3>',
43             webpage, u'title', flags=re.DOTALL)
44         video_url = self._search_regex([r'<source src="(.*?)"',
45             r'<dt>Download</dt>.*?<a href="(.+?)"'],
46             webpage, u'video url', flags=re.DOTALL)
47         return {
48             'id': video_id,
49             'title': os.path.splitext(title)[0],
50             'url': video_url,
51         }