]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/ustream.py
54605d863027968a4a15c5358b9f98539c69c4b3
1 from __future__
import unicode_literals
5 from .common
import InfoExtractor
16 class UstreamIE(InfoExtractor
):
17 _VALID_URL
= r
'https?://www\.ustream\.tv/(?P<type>recorded|embed|embed/recorded)/(?P<id>\d+)'
20 'url': 'http://www.ustream.tv/recorded/20274954',
21 'md5': '088f151799e8f572f84eb62f17d73e5c',
25 'title': 'Young Americans for Liberty February 7, 2012 2:28 AM',
26 'description': 'Young Americans for Liberty February 7, 2012 2:28 AM',
27 'timestamp': 1328577035,
28 'upload_date': '20120207',
29 'uploader': 'yaliberty',
30 'uploader_id': '6780869',
33 # From http://sportscanada.tv/canadagames/index.php/week2/figure-skating/444
34 # Title and uploader available only from params JSON
35 'url': 'http://www.ustream.tv/embed/recorded/59307601?ub=ff0000&lc=ff0000&oc=ffffff&uc=ffffff&v=3&wmode=direct',
36 'md5': '5a2abf40babeac9812ed20ae12d34e10',
40 'title': '-CG11- Canada Games Figure Skating',
41 'uploader': 'sportscanadatv',
43 'skip': 'This Pro Broadcaster has chosen to remove this video from the ustream.tv site.',
45 'url': 'http://www.ustream.tv/embed/10299409',
52 def _real_extract(self
, url
):
53 m
= re
.match(self
._VALID
_URL
, url
)
54 video_id
= m
.group('id')
56 # some sites use this embed format (see: https://github.com/rg3/youtube-dl/issues/2990)
57 if m
.group('type') == 'embed/recorded':
58 video_id
= m
.group('id')
59 desktop_url
= 'http://www.ustream.tv/recorded/' + video_id
60 return self
.url_result(desktop_url
, 'Ustream')
61 if m
.group('type') == 'embed':
62 video_id
= m
.group('id')
63 webpage
= self
._download
_webpage
(url
, video_id
)
64 content_video_ids
= self
._parse
_json
(self
._search
_regex
(
65 r
'ustream\.vars\.offAirContentVideoIds=([^;]+);', webpage
,
66 'content video IDs'), video_id
)
67 return self
.playlist_result(
68 map(lambda u
: self
.url_result('http://www.ustream.tv/recorded/' + u
, 'Ustream'), content_video_ids
),
71 params
= self
._download
_json
(
72 'https://api.ustream.tv/videos/%s.json' % video_id
, video_id
)
74 error
= params
.get('error')
77 '%s returned error: %s' % (self
.IE_NAME
, error
), expected
=True)
79 video
= params
['video']
81 title
= video
['title']
82 filesize
= float_or_none(video
.get('file_size'))
89 } for format_id
, video_url
in video
['media_urls'].items()]
90 self
._sort
_formats
(formats
)
92 description
= video
.get('description')
93 timestamp
= int_or_none(video
.get('created_at'))
94 duration
= float_or_none(video
.get('length'))
95 view_count
= int_or_none(video
.get('views'))
97 uploader
= video
.get('owner', {}).get('username')
98 uploader_id
= video
.get('owner', {}).get('id')
102 'url': thumbnail_url
,
103 } for thumbnail_id
, thumbnail_url
in video
.get('thumbnail', {}).items()]
108 'description': description
,
109 'thumbnails': thumbnails
,
110 'timestamp': timestamp
,
111 'duration': duration
,
112 'view_count': view_count
,
113 'uploader': uploader
,
114 'uploader_id': uploader_id
,
119 class UstreamChannelIE(InfoExtractor
):
120 _VALID_URL
= r
'https?://www\.ustream\.tv/channel/(?P<slug>.+)'
121 IE_NAME
= 'ustream:channel'
123 'url': 'http://www.ustream.tv/channel/channeljapan',
127 'playlist_mincount': 17,
130 def _real_extract(self
, url
):
131 m
= re
.match(self
._VALID
_URL
, url
)
132 display_id
= m
.group('slug')
133 webpage
= self
._download
_webpage
(url
, display_id
)
134 channel_id
= self
._html
_search
_meta
('ustream:channel_id', webpage
)
136 BASE
= 'http://www.ustream.tv'
137 next_url
= '/ajax/socialstream/videos/%s/1.json' % channel_id
140 reply
= self
._download
_json
(
141 compat_urlparse
.urljoin(BASE
, next_url
), display_id
,
142 note
='Downloading video information (next: %d)' % (len(video_ids
) + 1))
143 video_ids
.extend(re
.findall(r
'data-content-id="(\d.*)"', reply
['data']))
144 next_url
= reply
['nextUrl']
147 self
.url_result('http://www.ustream.tv/recorded/' + vid
, 'Ustream')
148 for vid
in video_ids
]
152 'display_id': display_id
,