1 from __future__ import unicode_literals
6 from .common import InfoExtractor
8 compat_urllib_parse_urlparse,
16 class LivestreamIE(InfoExtractor):
17 IE_NAME = 'livestream'
18 _VALID_URL = r'http://new\.livestream\.com/.*?/(?P<event_name>.*?)(/videos/(?P<id>\d+))?/?$'
20 'url': 'http://new.livestream.com/CoheedandCambria/WebsterHall/videos/4719370',
21 'md5': '53274c76ba7754fb0e8d072716f2292b',
25 'title': 'Live from Webster Hall NYC',
26 'upload_date': '20121012',
30 def _extract_video_info(self, video_data):
32 video_data.get('progressive_url_hd') or
33 video_data.get('progressive_url')
36 'id': compat_str(video_data['id']),
38 'title': video_data['caption'],
39 'thumbnail': video_data['thumbnail_url'],
40 'upload_date': video_data['updated_at'].replace('-', '')[:8],
43 def _real_extract(self, url):
44 mobj = re.match(self._VALID_URL, url)
45 video_id = mobj.group('id')
46 event_name = mobj.group('event_name')
47 webpage = self._download_webpage(url, video_id or event_name)
50 # This is an event page:
51 config_json = self._search_regex(
52 r'window.config = ({.*?});', webpage, 'window config')
53 info = json.loads(config_json)['event']
54 videos = [self._extract_video_info(video_data['data'])
55 for video_data in info['feed']['data']
56 if video_data['type'] == 'video']
57 return self.playlist_result(videos, info['id'], info['full_name'])
59 og_video = self._og_search_video_url(webpage, 'player url')
60 query_str = compat_urllib_parse_urlparse(og_video).query
61 query = compat_urlparse.parse_qs(query_str)
62 api_url = query['play_url'][0].replace('.smil', '')
63 info = json.loads(self._download_webpage(
64 api_url, video_id, 'Downloading video info'))
65 return self._extract_video_info(info)
68 # The original version of Livestream uses a different system
69 class LivestreamOriginalIE(InfoExtractor):
70 IE_NAME = 'livestream:original'
71 _VALID_URL = r'''(?x)https?://www\.livestream\.com/
72 (?P<user>[^/]+)/(?P<type>video|folder)
73 (?:\?.*?Id=|/)(?P<id>.*?)(&|$)
76 'url': 'http://www.livestream.com/dealbook/video?clipId=pla_8aa4a3f1-ba15-46a4-893b-902210e138fb',
78 'id': 'pla_8aa4a3f1-ba15-46a4-893b-902210e138fb',
80 'title': 'Spark 1 (BitCoin) with Cameron Winklevoss & Tyler Winklevoss of Winklevoss Capital',
84 'skip_download': True,
88 def _extract_video(self, user, video_id):
89 api_url = 'http://x{0}x.api.channel.livestream.com/2.0/clipdetails?extendedInfo=true&id={1}'.format(user, video_id)
91 info = self._download_xml(api_url, video_id)
92 item = info.find('channel').find('item')
93 ns = {'media': 'http://search.yahoo.com/mrss'}
94 thumbnail_url = item.find(xpath_with_ns('media:thumbnail', ns)).attrib['url']
95 # Remove the extension and number from the path (like 1.jpg)
96 path = self._search_regex(r'(user-files/.+)_.*?\.jpg$', thumbnail_url, 'path')
100 'title': item.find('title').text,
101 'url': 'rtmp://extondemand.livestream.com/ondemand',
102 'play_path': 'mp4:trans/dv15/mogulus-{0}.mp4'.format(path),
104 'thumbnail': thumbnail_url,
107 def _extract_folder(self, url, folder_id):
108 webpage = self._download_webpage(url, folder_id)
109 urls = orderedSet(re.findall(r'<a href="(https?://livestre\.am/.*?)"', webpage))
117 } for video_url in urls],
120 def _real_extract(self, url):
121 mobj = re.match(self._VALID_URL, url)
122 id = mobj.group('id')
123 user = mobj.group('user')
124 url_type = mobj.group('type')
125 if url_type == 'folder':
126 return self._extract_folder(url, id)
128 return self._extract_video(user, id)
131 # The server doesn't support HEAD request, the generic extractor can't detect
133 class LivestreamShortenerIE(InfoExtractor):
134 IE_NAME = 'livestream:shortener'
135 IE_DESC = False # Do not list
136 _VALID_URL = r'https?://livestre\.am/(?P<id>.+)'
138 def _real_extract(self, url):
139 mobj = re.match(self._VALID_URL, url)
140 id = mobj.group('id')
141 webpage = self._download_webpage(url, id)
145 'url': self._og_search_url(webpage),