]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/livestream.py
Imported Upstream version 2013.08.02
[youtubedl] / youtube_dl / extractor / livestream.py
1 import re
2 import json
3
4 from .common import InfoExtractor
5 from ..utils import compat_urllib_parse_urlparse, compat_urlparse
6
7
8 class LivestreamIE(InfoExtractor):
9 _VALID_URL = r'http://new.livestream.com/.*?/(?P<event_name>.*?)(/videos/(?P<id>\d+))?/?$'
10 _TEST = {
11 u'url': u'http://new.livestream.com/CoheedandCambria/WebsterHall/videos/4719370',
12 u'file': u'4719370.mp4',
13 u'md5': u'0d2186e3187d185a04b3cdd02b828836',
14 u'info_dict': {
15 u'title': u'Live from Webster Hall NYC',
16 u'upload_date': u'20121012',
17 }
18 }
19
20 def _extract_video_info(self, video_data):
21 video_url = video_data.get('progressive_url_hd') or video_data.get('progressive_url')
22 return {'id': video_data['id'],
23 'url': video_url,
24 'ext': 'mp4',
25 'title': video_data['caption'],
26 'thumbnail': video_data['thumbnail_url'],
27 'upload_date': video_data['updated_at'].replace('-','')[:8],
28 }
29
30 def _real_extract(self, url):
31 mobj = re.match(self._VALID_URL, url)
32 video_id = mobj.group('id')
33 event_name = mobj.group('event_name')
34 webpage = self._download_webpage(url, video_id or event_name)
35
36 if video_id is None:
37 # This is an event page:
38 api_url = self._search_regex(r'event_design_eventId: \'(.+?)\'',
39 webpage, 'api url')
40 info = json.loads(self._download_webpage(api_url, event_name,
41 u'Downloading event info'))
42 videos = [self._extract_video_info(video_data['data'])
43 for video_data in info['feed']['data'] if video_data['type'] == u'video']
44 return self.playlist_result(videos, info['id'], info['full_name'])
45 else:
46 og_video = self._og_search_video_url(webpage, name=u'player url')
47 query_str = compat_urllib_parse_urlparse(og_video).query
48 query = compat_urlparse.parse_qs(query_str)
49 api_url = query['play_url'][0].replace('.smil', '')
50 info = json.loads(self._download_webpage(api_url, video_id,
51 u'Downloading video info'))
52 return self._extract_video_info(info)