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