]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/ustream.py
[ustream] Remove unnecessary webpage download
[yt-dlp.git] / youtube_dl / extractor / ustream.py
CommitLineData
0eb799ba
JMF
1from __future__ import unicode_literals
2
bfd5c93a 3import json
78af8eb1
PH
4import re
5
6from .common import InfoExtractor
74ac9bdd
JMF
7from ..utils import (
8 compat_urlparse,
a921f407 9 get_meta_content,
74ac9bdd 10)
78af8eb1
PH
11
12
13class UstreamIE(InfoExtractor):
b702eceb 14 _VALID_URL = r'https?://www\.ustream\.tv/(?P<type>recorded|embed|embed/recorded)/(?P<videoID>\d+)'
0eb799ba 15 IE_NAME = 'ustream'
ca6aada4 16 _TEST = {
0eb799ba
JMF
17 'url': 'http://www.ustream.tv/recorded/20274954',
18 'file': '20274954.flv',
19 'md5': '088f151799e8f572f84eb62f17d73e5c',
20 'info_dict': {
21 "uploader": "Young Americans for Liberty",
22 "title": "Young Americans for Liberty February 7, 2012 2:28 AM",
23 },
6f5ac90c 24 }
78af8eb1
PH
25
26 def _real_extract(self, url):
27 m = re.match(self._VALID_URL, url)
b702eceb 28 video_id = m.group('videoID')
29
30 if m.group('type') == 'embed/recorded': # some sites use this embed format (see: http://github.com/rg3/youtube-dl/issues/2990)
31 video_id = m.group('videoID')
b702eceb 32 desktop_url = 'http://www.ustream.tv/recorded/' + video_id
33 return self.url_result(desktop_url, 'Ustream')
5c386252 34 if m.group('type') == 'embed':
35 video_id = m.group('videoID')
36 webpage = self._download_webpage(url, video_id)
37 desktop_video_id = self._html_search_regex(r'ContentVideoIds=\["([^"]*?)"\]', webpage, 'desktop_video_id')
38 desktop_url = 'http://www.ustream.tv/recorded/' + desktop_video_id
39 return self.url_result(desktop_url, 'Ustream')
40
0eb799ba 41 video_url = 'http://tcdn.ustream.tv/video/%s' % video_id
78af8eb1
PH
42 webpage = self._download_webpage(url, video_id)
43
44 self.report_extraction(video_id)
45
46 video_title = self._html_search_regex(r'data-title="(?P<title>.+)"',
0eb799ba 47 webpage, 'title')
78af8eb1
PH
48
49 uploader = self._html_search_regex(r'data-content-type="channel".*?>(?P<uploader>.*?)</a>',
0eb799ba 50 webpage, 'uploader', fatal=False, flags=re.DOTALL)
78af8eb1
PH
51
52 thumbnail = self._html_search_regex(r'<link rel="image_src" href="(?P<thumb>.*?)"',
0eb799ba
JMF
53 webpage, 'thumbnail', fatal=False)
54
55 return {
56 'id': video_id,
57 'url': video_url,
58 'ext': 'flv',
59 'title': video_title,
60 'uploader': uploader,
61 'thumbnail': thumbnail,
62 }
63
bfd5c93a 64
bfd5c93a 65class UstreamChannelIE(InfoExtractor):
66 _VALID_URL = r'https?://www\.ustream\.tv/channel/(?P<slug>.+)'
0eb799ba 67 IE_NAME = 'ustream:channel'
bfd5c93a 68
69 def _real_extract(self, url):
70 m = re.match(self._VALID_URL, url)
71 slug = m.group('slug')
a921f407
JMF
72 webpage = self._download_webpage(url, slug)
73 channel_id = get_meta_content('ustream:channel_id', webpage)
bfd5c93a 74
bfd5c93a 75 BASE = 'http://www.ustream.tv'
76 next_url = '/ajax/socialstream/videos/%s/1.json' % channel_id
a921f407 77 video_ids = []
bfd5c93a 78 while next_url:
74ac9bdd 79 reply = json.loads(self._download_webpage(compat_urlparse.urljoin(BASE, next_url), channel_id))
a921f407 80 video_ids.extend(re.findall(r'data-content-id="(\d.*)"', reply['data']))
bfd5c93a 81 next_url = reply['nextUrl']
bfd5c93a 82
bfd5c93a 83 urls = ['http://www.ustream.tv/recorded/' + vid for vid in video_ids]
84 url_entries = [self.url_result(eurl, 'Ustream') for eurl in urls]
74ac9bdd 85 return self.playlist_result(url_entries, channel_id)