]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/bliptv.py
f2b02643de162ff1547bef47a62dca55f2a405a3
1 from __future__
import unicode_literals
5 from .common
import InfoExtractor
6 from .subtitles
import SubtitlesInfoExtractor
17 class BlipTVIE(SubtitlesInfoExtractor
):
18 _VALID_URL
= r
'https?://(?:\w+\.)?blip\.tv/(?:(?:.+-|rss/flash/)(?P<id>\d+)|((?:play/|api\.swf#)(?P<lookup_id>[\da-zA-Z+_]+)))'
22 'url': 'http://blip.tv/cbr/cbr-exclusive-gotham-city-imposters-bats-vs-jokerz-short-3-5796352',
23 'md5': 'c6934ad0b6acf2bd920720ec888eb812',
27 'title': 'CBR EXCLUSIVE: "Gotham City Imposters" Bats VS Jokerz Short 3',
28 'description': 'md5:9bc31f227219cde65e47eeec8d2dc596',
29 'timestamp': 1323138843,
30 'upload_date': '20111206',
32 'uploader_id': '679425',
37 # https://github.com/rg3/youtube-dl/pull/2274
38 'note': 'Video with subtitles',
39 'url': 'http://blip.tv/play/h6Uag5OEVgI.html',
40 'md5': '309f9d25b820b086ca163ffac8031806',
44 'title': 'Red vs. Blue Season 11 Episode 1',
45 'description': 'One-Zero-One',
46 'timestamp': 1371261608,
47 'upload_date': '20130615',
48 'uploader': 'redvsblue',
49 'uploader_id': '792887',
54 # https://bugzilla.redhat.com/show_bug.cgi?id=967465
55 'url': 'http://a.blip.tv/api.swf#h6Uag5KbVwI',
56 'md5': '314e87b1ebe7a48fcbfdd51b791ce5a6',
60 'upload_date': '20130520',
61 'description': 'Two hapless space marines argue over what to do when they realize they have an astronomically huge problem on their hands.',
62 'title': 'Red vs. Blue Season 11 Trailer',
63 'timestamp': 1369029609,
64 'uploader': 'redvsblue',
65 'uploader_id': '792887',
70 def _real_extract(self
, url
):
71 mobj
= re
.match(self
._VALID
_URL
, url
)
72 lookup_id
= mobj
.group('lookup_id')
74 # See https://github.com/rg3/youtube-dl/issues/857 and
75 # https://github.com/rg3/youtube-dl/issues/4197
77 info_page
= self
._download
_webpage
(
78 'http://blip.tv/play/%s.x?p=1' % lookup_id
, lookup_id
, 'Resolving lookup id')
79 video_id
= self
._search
_regex
(r
'config\.id\s*=\s*"([0-9]+)', info_page
, 'video_id')
81 video_id
= mobj
.group('id')
83 rss
= self
._download
_xml
('http://blip.tv/rss/flash/%s' % video_id
, video_id
, 'Downloading video RSS')
86 return '{http://blip.tv/dtd/blip/1.0}%s' % s
89 return '{http://search.yahoo.com/mrss/}%s' % s
92 return '{http://www.itunes.com/dtds/podcast-1.0.dtd}%s' % s
94 item
= rss
.find('channel/item')
96 video_id
= item
.find(blip('item_id')).text
97 title
= item
.find('./title').text
98 description
= clean_html(compat_str(item
.find(blip('puredescription')).text
))
99 timestamp
= parse_iso8601(item
.find(blip('datestamp')).text
)
100 uploader
= item
.find(blip('user')).text
101 uploader_id
= item
.find(blip('userid')).text
102 duration
= int(item
.find(blip('runtime')).text
)
103 media_thumbnail
= item
.find(media('thumbnail'))
104 thumbnail
= media_thumbnail
.get('url') if media_thumbnail
is not None else item
.find(itunes('image')).text
105 categories
= [category
.text
for category
in item
.findall('category')]
110 media_group
= item
.find(media('group'))
111 for media_content
in media_group
.findall(media('content')):
112 url
= media_content
.get('url')
113 role
= media_content
.get(blip('role'))
114 msg
= self
._download
_webpage
(
115 url
+ '?showplayer=20140425131715&referrer=http://blip.tv&mask=7&skin=flashvars&view=url',
116 video_id
, 'Resolving URL for %s' % role
)
117 real_url
= compat_urlparse
.parse_qs(msg
)['message'][0]
119 media_type
= media_content
.get('type')
120 if media_type
== 'text/srt' or url
.endswith('.srt'):
124 lang
= role
.rpartition('-')[-1].strip().lower()
125 langcode
= LANGS
.get(lang
, lang
)
126 subtitles
[langcode
] = url
127 elif media_type
.startswith('video/'):
131 'format_note': media_type
,
132 'vcodec': media_content
.get(blip('vcodec')),
133 'acodec': media_content
.get(blip('acodec')),
134 'filesize': media_content
.get('filesize'),
135 'width': int(media_content
.get('width')),
136 'height': int(media_content
.get('height')),
138 self
._sort
_formats
(formats
)
141 video_subtitles
= self
.extract_subtitles(video_id
, subtitles
)
142 if self
._downloader
.params
.get('listsubtitles', False):
143 self
._list
_available
_subtitles
(video_id
, subtitles
)
149 'description': description
,
150 'timestamp': timestamp
,
151 'uploader': uploader
,
152 'uploader_id': uploader_id
,
153 'duration': duration
,
154 'thumbnail': thumbnail
,
155 'categories': categories
,
157 'subtitles': video_subtitles
,
160 def _download_subtitle_url(self
, sub_lang
, url
):
161 # For some weird reason, blip.tv serves a video instead of subtitles
162 # when we request with a common UA
163 req
= compat_urllib_request
.Request(url
)
164 req
.add_header('Youtubedl-user-agent', 'youtube-dl')
165 return self
._download
_webpage
(req
, None, note
=False)
168 class BlipTVUserIE(InfoExtractor
):
169 _VALID_URL
= r
'(?:(?:https?://(?:\w+\.)?blip\.tv/)|bliptvuser:)(?!api\.swf)([^/]+)/*$'
171 IE_NAME
= 'blip.tv:user'
173 'url': 'http://blip.tv/actone',
176 'title': 'Act One: The Series',
181 def _real_extract(self
, url
):
182 mobj
= re
.match(self
._VALID
_URL
, url
)
183 username
= mobj
.group(1)
185 page_base
= 'http://m.blip.tv/pr/show_get_full_episode_list?users_id=%s&lite=0&esi=1'
187 page
= self
._download
_webpage
(url
, username
, 'Downloading user page')
188 mobj
= re
.search(r
'data-users-id="([^"]+)"', page
)
189 page_base
= page_base
% mobj
.group(1)
190 title
= self
._og
_search
_title
(page
)
192 # Download video ids using BlipTV Ajax calls. Result size per
193 # query is limited (currently to 12 videos) so we need to query
194 # page by page until there are no video ids - it means we got
201 url
= page_base
+ "&page=" + str(pagenum
)
202 page
= self
._download
_webpage
(
203 url
, username
, 'Downloading video ids from page %d' % pagenum
)
205 # Extract video identifiers
208 for mobj
in re
.finditer(r
'href="/([^"]+)"', page
):
209 if mobj
.group(1) not in ids_in_page
:
210 ids_in_page
.append(unescapeHTML(mobj
.group(1)))
212 video_ids
.extend(ids_in_page
)
214 # A little optimization - if current page is not
215 # "full", ie. does not contain PAGE_SIZE video ids then
216 # we can assume that this page is the last one - there
217 # are no more ids on further pages - no need to query
220 if len(ids_in_page
) < self
._PAGE
_SIZE
:
225 urls
= ['http://blip.tv/%s' % video_id
for video_id
in video_ids
]
226 url_entries
= [self
.url_result(vurl
, 'BlipTV') for vurl
in urls
]
227 return self
.playlist_result(
228 url_entries
, playlist_title
=title
, playlist_id
=username
)