]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/ustream.py
68d03b99905cce848eb38fde8b6d8e643c548105
   1 from __future__ 
import unicode_literals
 
   5 from .common 
import InfoExtractor
 
  11 class UstreamIE(InfoExtractor
): 
  12     _VALID_URL 
= r
'https?://www\.ustream\.tv/(?P<type>recorded|embed|embed/recorded)/(?P<videoID>\d+)' 
  15         'url': 'http://www.ustream.tv/recorded/20274954', 
  16         'md5': '088f151799e8f572f84eb62f17d73e5c', 
  20             'uploader': 'Young Americans for Liberty', 
  21             'title': 'Young Americans for Liberty February 7, 2012 2:28 AM', 
  25     def _real_extract(self
, url
): 
  26         m 
= re
.match(self
._VALID
_URL
, url
) 
  27         video_id 
= m
.group('videoID') 
  29         # some sites use this embed format (see: http://github.com/rg3/youtube-dl/issues/2990) 
  30         if m
.group('type') == 'embed/recorded': 
  31             video_id 
= m
.group('videoID') 
  32             desktop_url 
= 'http://www.ustream.tv/recorded/' + video_id
 
  33             return self
.url_result(desktop_url
, 'Ustream') 
  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
( 
  38                 r
'ContentVideoIds=\["([^"]*?)"\]', webpage
, 'desktop_video_id') 
  39             desktop_url 
= 'http://www.ustream.tv/recorded/' + desktop_video_id
 
  40             return self
.url_result(desktop_url
, 'Ustream') 
  42         video_url 
= 'http://tcdn.ustream.tv/video/%s' % video_id
 
  43         webpage 
= self
._download
_webpage
(url
, video_id
) 
  45         self
.report_extraction(video_id
) 
  47         video_title 
= self
._html
_search
_regex
(r
'data-title="(?P<title>.+)"', 
  50         uploader 
= self
._html
_search
_regex
(r
'data-content-type="channel".*?>(?P<uploader>.*?)</a>', 
  51                                            webpage
, 'uploader', fatal
=False, flags
=re
.DOTALL
) 
  53         thumbnail 
= self
._html
_search
_regex
(r
'<link rel="image_src" href="(?P<thumb>.*?)"', 
  54                                             webpage
, 'thumbnail', fatal
=False) 
  62             'thumbnail': thumbnail
, 
  66 class UstreamChannelIE(InfoExtractor
): 
  67     _VALID_URL 
= r
'https?://www\.ustream\.tv/channel/(?P<slug>.+)' 
  68     IE_NAME 
= 'ustream:channel' 
  70         'url': 'http://www.ustream.tv/channel/channeljapan', 
  74         'playlist_mincount': 17, 
  77     def _real_extract(self
, url
): 
  78         m 
= re
.match(self
._VALID
_URL
, url
) 
  79         display_id 
= m
.group('slug') 
  80         webpage 
= self
._download
_webpage
(url
, display_id
) 
  81         channel_id 
= self
._html
_search
_meta
('ustream:channel_id', webpage
) 
  83         BASE 
= 'http://www.ustream.tv' 
  84         next_url 
= '/ajax/socialstream/videos/%s/1.json' % channel_id
 
  87             reply 
= self
._download
_json
( 
  88                 compat_urlparse
.urljoin(BASE
, next_url
), display_id
, 
  89                 note
='Downloading video information (next: %d)' % (len(video_ids
) + 1)) 
  90             video_ids
.extend(re
.findall(r
'data-content-id="(\d.*)"', reply
['data'])) 
  91             next_url 
= reply
['nextUrl'] 
  94             self
.url_result('http://www.ustream.tv/recorded/' + vid
, 'Ustream') 
  99             'display_id': display_id
,