]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/ustream.py
   1 from __future__ 
import unicode_literals
 
   6 from .common 
import InfoExtractor
 
  13 class UstreamIE(InfoExtractor
): 
  14     _VALID_URL 
= r
'https?://www\.ustream\.tv/(?P<type>recorded|embed|embed/recorded)/(?P<videoID>\d+)' 
  17         'url': 'http://www.ustream.tv/recorded/20274954', 
  18         'md5': '088f151799e8f572f84eb62f17d73e5c', 
  22             'uploader': 'Young Americans for Liberty', 
  23             'title': 'Young Americans for Liberty February 7, 2012 2:28 AM', 
  27     def _real_extract(self
, url
): 
  28         m 
= re
.match(self
._VALID
_URL
, url
) 
  29         video_id 
= m
.group('videoID') 
  31         # some sites use this embed format (see: http://github.com/rg3/youtube-dl/issues/2990) 
  32         if m
.group('type') == 'embed/recorded': 
  33             video_id 
= m
.group('videoID') 
  34             desktop_url 
= 'http://www.ustream.tv/recorded/' + video_id
 
  35             return self
.url_result(desktop_url
, 'Ustream') 
  36         if m
.group('type') == 'embed': 
  37             video_id 
= m
.group('videoID') 
  38             webpage 
= self
._download
_webpage
(url
, video_id
) 
  39             desktop_video_id 
= self
._html
_search
_regex
( 
  40                 r
'ContentVideoIds=\["([^"]*?)"\]', webpage
, 'desktop_video_id') 
  41             desktop_url 
= 'http://www.ustream.tv/recorded/' + desktop_video_id
 
  42             return self
.url_result(desktop_url
, 'Ustream') 
  44         video_url 
= 'http://tcdn.ustream.tv/video/%s' % video_id
 
  45         webpage 
= self
._download
_webpage
(url
, video_id
) 
  47         self
.report_extraction(video_id
) 
  49         video_title 
= self
._html
_search
_regex
(r
'data-title="(?P<title>.+)"', 
  52         uploader 
= self
._html
_search
_regex
(r
'data-content-type="channel".*?>(?P<uploader>.*?)</a>', 
  53             webpage
, 'uploader', fatal
=False, flags
=re
.DOTALL
) 
  55         thumbnail 
= self
._html
_search
_regex
(r
'<link rel="image_src" href="(?P<thumb>.*?)"', 
  56             webpage
, 'thumbnail', fatal
=False) 
  64             'thumbnail': thumbnail
, 
  68 class UstreamChannelIE(InfoExtractor
): 
  69     _VALID_URL 
= r
'https?://www\.ustream\.tv/channel/(?P<slug>.+)' 
  70     IE_NAME 
= 'ustream:channel' 
  72     def _real_extract(self
, url
): 
  73         m 
= re
.match(self
._VALID
_URL
, url
) 
  74         slug 
= m
.group('slug') 
  75         webpage 
= self
._download
_webpage
(url
, slug
) 
  76         channel_id 
= get_meta_content('ustream:channel_id', webpage
) 
  78         BASE 
= 'http://www.ustream.tv' 
  79         next_url 
= '/ajax/socialstream/videos/%s/1.json' % channel_id
 
  82             reply 
= json
.loads(self
._download
_webpage
(compat_urlparse
.urljoin(BASE
, next_url
), channel_id
)) 
  83             video_ids
.extend(re
.findall(r
'data-content-id="(\d.*)"', reply
['data'])) 
  84             next_url 
= reply
['nextUrl'] 
  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
] 
  88         return self
.playlist_result(url_entries
, channel_id
)