]>
jfr.im git - yt-dlp.git/blob - youtube_dl/extractor/ustream.py
1 from __future__
import unicode_literals
6 from .common
import InfoExtractor
17 class UstreamIE(InfoExtractor
):
18 _VALID_URL
= r
'https?://www\.ustream\.tv/(?P<type>recorded|embed|embed/recorded)/(?P<id>\d+)'
21 'url': 'http://www.ustream.tv/recorded/20274954',
22 'md5': '088f151799e8f572f84eb62f17d73e5c',
26 'uploader': 'Young Americans for Liberty',
27 'title': 'Young Americans for Liberty February 7, 2012 2:28 AM',
30 # From http://sportscanada.tv/canadagames/index.php/week2/figure-skating/444
31 # Title and uploader available only from params JSON
32 'url': 'http://www.ustream.tv/embed/recorded/59307601?ub=ff0000&lc=ff0000&oc=ffffff&uc=ffffff&v=3&wmode=direct',
33 'md5': '5a2abf40babeac9812ed20ae12d34e10',
37 'title': '-CG11- Canada Games Figure Skating',
38 'uploader': 'sportscanadatv',
42 def _real_extract(self
, url
):
43 m
= re
.match(self
._VALID
_URL
, url
)
44 video_id
= m
.group('id')
46 # some sites use this embed format (see: http://github.com/rg3/youtube-dl/issues/2990)
47 if m
.group('type') == 'embed/recorded':
48 video_id
= m
.group('id')
49 desktop_url
= 'http://www.ustream.tv/recorded/' + video_id
50 return self
.url_result(desktop_url
, 'Ustream')
51 if m
.group('type') == 'embed':
52 video_id
= m
.group('id')
53 webpage
= self
._download
_webpage
(url
, video_id
)
54 desktop_video_id
= self
._html
_search
_regex
(
55 r
'ContentVideoIds=\["([^"]*?)"\]', webpage
, 'desktop_video_id')
56 desktop_url
= 'http://www.ustream.tv/recorded/' + desktop_video_id
57 return self
.url_result(desktop_url
, 'Ustream')
59 params
= self
._download
_json
(
60 'https://api.ustream.tv/videos/%s.json' % video_id
, video_id
)
62 error
= params
.get('error')
65 '%s returned error: %s' % (self
.IE_NAME
, error
), expected
=True)
67 video
= params
['video']
73 } for format_id
, video_url
in video
['media_urls'].items()]
74 self
._sort
_formats
(formats
)
76 title
= video
['title']
77 description
= video
.get('description')
78 timestamp
= int_or_none(video
.get('created_at'))
79 duration
= float_or_none(video
.get('length'))
80 filesize
= float_or_none(video
.get('file_size'))
81 view_count
= int_or_none(video
.get('views'))
83 uploader
= video
.get('owner', {}).get('username')
84 uploader_id
= video
.get('owner', {}).get('id')
89 } for thumbnail_id
, thumbnail_url
in video
.get('thumbnail', {}).items()]
94 'description': description
,
95 'thumbnails': thumbnails
,
96 'timestamp': timestamp
,
99 'view_count': view_count
,
100 'uploader': uploader
,
101 'uploader_id': uploader_id
,
106 class UstreamChannelIE(InfoExtractor
):
107 _VALID_URL
= r
'https?://www\.ustream\.tv/channel/(?P<slug>.+)'
108 IE_NAME
= 'ustream:channel'
110 'url': 'http://www.ustream.tv/channel/channeljapan',
114 'playlist_mincount': 17,
117 def _real_extract(self
, url
):
118 m
= re
.match(self
._VALID
_URL
, url
)
119 display_id
= m
.group('slug')
120 webpage
= self
._download
_webpage
(url
, display_id
)
121 channel_id
= self
._html
_search
_meta
('ustream:channel_id', webpage
)
123 BASE
= 'http://www.ustream.tv'
124 next_url
= '/ajax/socialstream/videos/%s/1.json' % channel_id
127 reply
= self
._download
_json
(
128 compat_urlparse
.urljoin(BASE
, next_url
), display_id
,
129 note
='Downloading video information (next: %d)' % (len(video_ids
) + 1))
130 video_ids
.extend(re
.findall(r
'data-content-id="(\d.*)"', reply
['data']))
131 next_url
= reply
['nextUrl']
134 self
.url_result('http://www.ustream.tv/recorded/' + vid
, 'Ustream')
135 for vid
in video_ids
]
139 'display_id': display_id
,