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