You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

290 lines
11 KiB

11 years ago
Switch codebase to use sanitized_Request instead of compat_urllib_request.Request [downloader/dash] Use sanitized_Request [downloader/http] Use sanitized_Request [atresplayer] Use sanitized_Request [bambuser] Use sanitized_Request [bliptv] Use sanitized_Request [brightcove] Use sanitized_Request [cbs] Use sanitized_Request [ceskatelevize] Use sanitized_Request [collegerama] Use sanitized_Request [extractor/common] Use sanitized_Request [crunchyroll] Use sanitized_Request [dailymotion] Use sanitized_Request [dcn] Use sanitized_Request [dramafever] Use sanitized_Request [dumpert] Use sanitized_Request [eitb] Use sanitized_Request [escapist] Use sanitized_Request [everyonesmixtape] Use sanitized_Request [extremetube] Use sanitized_Request [facebook] Use sanitized_Request [fc2] Use sanitized_Request [flickr] Use sanitized_Request [4tube] Use sanitized_Request [gdcvault] Use sanitized_Request [extractor/generic] Use sanitized_Request [hearthisat] Use sanitized_Request [hotnewhiphop] Use sanitized_Request [hypem] Use sanitized_Request [iprima] Use sanitized_Request [ivi] Use sanitized_Request [keezmovies] Use sanitized_Request [letv] Use sanitized_Request [lynda] Use sanitized_Request [metacafe] Use sanitized_Request [minhateca] Use sanitized_Request [miomio] Use sanitized_Request [meovideo] Use sanitized_Request [mofosex] Use sanitized_Request [moniker] Use sanitized_Request [mooshare] Use sanitized_Request [movieclips] Use sanitized_Request [mtv] Use sanitized_Request [myvideo] Use sanitized_Request [neteasemusic] Use sanitized_Request [nfb] Use sanitized_Request [niconico] Use sanitized_Request [noco] Use sanitized_Request [nosvideo] Use sanitized_Request [novamov] Use sanitized_Request [nowness] Use sanitized_Request [nuvid] Use sanitized_Request [played] Use sanitized_Request [pluralsight] Use sanitized_Request [pornhub] Use sanitized_Request [pornotube] Use sanitized_Request [primesharetv] Use sanitized_Request [promptfile] Use sanitized_Request [qqmusic] Use sanitized_Request [rtve] Use sanitized_Request [safari] Use sanitized_Request [sandia] Use sanitized_Request [shared] Use sanitized_Request [sharesix] Use sanitized_Request [sina] Use sanitized_Request [smotri] Use sanitized_Request [sohu] Use sanitized_Request [spankwire] Use sanitized_Request [sportdeutschland] Use sanitized_Request [streamcloud] Use sanitized_Request [streamcz] Use sanitized_Request [tapely] Use sanitized_Request [tube8] Use sanitized_Request [tubitv] Use sanitized_Request [twitch] Use sanitized_Request [twitter] Use sanitized_Request [udemy] Use sanitized_Request [vbox7] Use sanitized_Request [veoh] Use sanitized_Request [vessel] Use sanitized_Request [vevo] Use sanitized_Request [viddler] Use sanitized_Request [videomega] Use sanitized_Request [viewvster] Use sanitized_Request [viki] Use sanitized_Request [vk] Use sanitized_Request [vodlocker] Use sanitized_Request [voicerepublic] Use sanitized_Request [wistia] Use sanitized_Request [xfileshare] Use sanitized_Request [xtube] Use sanitized_Request [xvideos] Use sanitized_Request [yandexmusic] Use sanitized_Request [youku] Use sanitized_Request [youporn] Use sanitized_Request [youtube] Use sanitized_Request [patreon] Use sanitized_Request [extractor/common] Remove unused import [nfb] PEP 8
9 years ago
Switch codebase to use sanitized_Request instead of compat_urllib_request.Request [downloader/dash] Use sanitized_Request [downloader/http] Use sanitized_Request [atresplayer] Use sanitized_Request [bambuser] Use sanitized_Request [bliptv] Use sanitized_Request [brightcove] Use sanitized_Request [cbs] Use sanitized_Request [ceskatelevize] Use sanitized_Request [collegerama] Use sanitized_Request [extractor/common] Use sanitized_Request [crunchyroll] Use sanitized_Request [dailymotion] Use sanitized_Request [dcn] Use sanitized_Request [dramafever] Use sanitized_Request [dumpert] Use sanitized_Request [eitb] Use sanitized_Request [escapist] Use sanitized_Request [everyonesmixtape] Use sanitized_Request [extremetube] Use sanitized_Request [facebook] Use sanitized_Request [fc2] Use sanitized_Request [flickr] Use sanitized_Request [4tube] Use sanitized_Request [gdcvault] Use sanitized_Request [extractor/generic] Use sanitized_Request [hearthisat] Use sanitized_Request [hotnewhiphop] Use sanitized_Request [hypem] Use sanitized_Request [iprima] Use sanitized_Request [ivi] Use sanitized_Request [keezmovies] Use sanitized_Request [letv] Use sanitized_Request [lynda] Use sanitized_Request [metacafe] Use sanitized_Request [minhateca] Use sanitized_Request [miomio] Use sanitized_Request [meovideo] Use sanitized_Request [mofosex] Use sanitized_Request [moniker] Use sanitized_Request [mooshare] Use sanitized_Request [movieclips] Use sanitized_Request [mtv] Use sanitized_Request [myvideo] Use sanitized_Request [neteasemusic] Use sanitized_Request [nfb] Use sanitized_Request [niconico] Use sanitized_Request [noco] Use sanitized_Request [nosvideo] Use sanitized_Request [novamov] Use sanitized_Request [nowness] Use sanitized_Request [nuvid] Use sanitized_Request [played] Use sanitized_Request [pluralsight] Use sanitized_Request [pornhub] Use sanitized_Request [pornotube] Use sanitized_Request [primesharetv] Use sanitized_Request [promptfile] Use sanitized_Request [qqmusic] Use sanitized_Request [rtve] Use sanitized_Request [safari] Use sanitized_Request [sandia] Use sanitized_Request [shared] Use sanitized_Request [sharesix] Use sanitized_Request [sina] Use sanitized_Request [smotri] Use sanitized_Request [sohu] Use sanitized_Request [spankwire] Use sanitized_Request [sportdeutschland] Use sanitized_Request [streamcloud] Use sanitized_Request [streamcz] Use sanitized_Request [tapely] Use sanitized_Request [tube8] Use sanitized_Request [tubitv] Use sanitized_Request [twitch] Use sanitized_Request [twitter] Use sanitized_Request [udemy] Use sanitized_Request [vbox7] Use sanitized_Request [veoh] Use sanitized_Request [vessel] Use sanitized_Request [vevo] Use sanitized_Request [viddler] Use sanitized_Request [videomega] Use sanitized_Request [viewvster] Use sanitized_Request [viki] Use sanitized_Request [vk] Use sanitized_Request [vodlocker] Use sanitized_Request [voicerepublic] Use sanitized_Request [wistia] Use sanitized_Request [xfileshare] Use sanitized_Request [xtube] Use sanitized_Request [xvideos] Use sanitized_Request [yandexmusic] Use sanitized_Request [youku] Use sanitized_Request [youporn] Use sanitized_Request [youtube] Use sanitized_Request [patreon] Use sanitized_Request [extractor/common] Remove unused import [nfb] PEP 8
9 years ago
Switch codebase to use sanitized_Request instead of compat_urllib_request.Request [downloader/dash] Use sanitized_Request [downloader/http] Use sanitized_Request [atresplayer] Use sanitized_Request [bambuser] Use sanitized_Request [bliptv] Use sanitized_Request [brightcove] Use sanitized_Request [cbs] Use sanitized_Request [ceskatelevize] Use sanitized_Request [collegerama] Use sanitized_Request [extractor/common] Use sanitized_Request [crunchyroll] Use sanitized_Request [dailymotion] Use sanitized_Request [dcn] Use sanitized_Request [dramafever] Use sanitized_Request [dumpert] Use sanitized_Request [eitb] Use sanitized_Request [escapist] Use sanitized_Request [everyonesmixtape] Use sanitized_Request [extremetube] Use sanitized_Request [facebook] Use sanitized_Request [fc2] Use sanitized_Request [flickr] Use sanitized_Request [4tube] Use sanitized_Request [gdcvault] Use sanitized_Request [extractor/generic] Use sanitized_Request [hearthisat] Use sanitized_Request [hotnewhiphop] Use sanitized_Request [hypem] Use sanitized_Request [iprima] Use sanitized_Request [ivi] Use sanitized_Request [keezmovies] Use sanitized_Request [letv] Use sanitized_Request [lynda] Use sanitized_Request [metacafe] Use sanitized_Request [minhateca] Use sanitized_Request [miomio] Use sanitized_Request [meovideo] Use sanitized_Request [mofosex] Use sanitized_Request [moniker] Use sanitized_Request [mooshare] Use sanitized_Request [movieclips] Use sanitized_Request [mtv] Use sanitized_Request [myvideo] Use sanitized_Request [neteasemusic] Use sanitized_Request [nfb] Use sanitized_Request [niconico] Use sanitized_Request [noco] Use sanitized_Request [nosvideo] Use sanitized_Request [novamov] Use sanitized_Request [nowness] Use sanitized_Request [nuvid] Use sanitized_Request [played] Use sanitized_Request [pluralsight] Use sanitized_Request [pornhub] Use sanitized_Request [pornotube] Use sanitized_Request [primesharetv] Use sanitized_Request [promptfile] Use sanitized_Request [qqmusic] Use sanitized_Request [rtve] Use sanitized_Request [safari] Use sanitized_Request [sandia] Use sanitized_Request [shared] Use sanitized_Request [sharesix] Use sanitized_Request [sina] Use sanitized_Request [smotri] Use sanitized_Request [sohu] Use sanitized_Request [spankwire] Use sanitized_Request [sportdeutschland] Use sanitized_Request [streamcloud] Use sanitized_Request [streamcz] Use sanitized_Request [tapely] Use sanitized_Request [tube8] Use sanitized_Request [tubitv] Use sanitized_Request [twitch] Use sanitized_Request [twitter] Use sanitized_Request [udemy] Use sanitized_Request [vbox7] Use sanitized_Request [veoh] Use sanitized_Request [vessel] Use sanitized_Request [vevo] Use sanitized_Request [viddler] Use sanitized_Request [videomega] Use sanitized_Request [viewvster] Use sanitized_Request [viki] Use sanitized_Request [vk] Use sanitized_Request [vodlocker] Use sanitized_Request [voicerepublic] Use sanitized_Request [wistia] Use sanitized_Request [xfileshare] Use sanitized_Request [xtube] Use sanitized_Request [xvideos] Use sanitized_Request [yandexmusic] Use sanitized_Request [youku] Use sanitized_Request [youporn] Use sanitized_Request [youtube] Use sanitized_Request [patreon] Use sanitized_Request [extractor/common] Remove unused import [nfb] PEP 8
9 years ago
11 years ago
11 years ago
11 years ago
  1. from __future__ import unicode_literals
  2. import re
  3. from .common import InfoExtractor
  4. from ..compat import compat_urlparse
  5. from ..utils import (
  6. clean_html,
  7. int_or_none,
  8. parse_iso8601,
  9. sanitized_Request,
  10. unescapeHTML,
  11. xpath_text,
  12. xpath_with_ns,
  13. )
  14. class BlipTVIE(InfoExtractor):
  15. _VALID_URL = r'https?://(?:\w+\.)?blip\.tv/(?:(?:.+-|rss/flash/)(?P<id>\d+)|((?:play/|api\.swf#)(?P<lookup_id>[\da-zA-Z+_]+)))'
  16. _TESTS = [
  17. {
  18. 'url': 'http://blip.tv/cbr/cbr-exclusive-gotham-city-imposters-bats-vs-jokerz-short-3-5796352',
  19. 'md5': '80baf1ec5c3d2019037c1c707d676b9f',
  20. 'info_dict': {
  21. 'id': '5779306',
  22. 'ext': 'm4v',
  23. 'title': 'CBR EXCLUSIVE: "Gotham City Imposters" Bats VS Jokerz Short 3',
  24. 'description': 'md5:9bc31f227219cde65e47eeec8d2dc596',
  25. 'timestamp': 1323138843,
  26. 'upload_date': '20111206',
  27. 'uploader': 'cbr',
  28. 'uploader_id': '679425',
  29. 'duration': 81,
  30. }
  31. },
  32. {
  33. # https://github.com/rg3/youtube-dl/pull/2274
  34. 'note': 'Video with subtitles',
  35. 'url': 'http://blip.tv/play/h6Uag5OEVgI.html',
  36. 'md5': '309f9d25b820b086ca163ffac8031806',
  37. 'info_dict': {
  38. 'id': '6586561',
  39. 'ext': 'mp4',
  40. 'title': 'Red vs. Blue Season 11 Episode 1',
  41. 'description': 'One-Zero-One',
  42. 'timestamp': 1371261608,
  43. 'upload_date': '20130615',
  44. 'uploader': 'redvsblue',
  45. 'uploader_id': '792887',
  46. 'duration': 279,
  47. }
  48. },
  49. {
  50. # https://bugzilla.redhat.com/show_bug.cgi?id=967465
  51. 'url': 'http://a.blip.tv/api.swf#h6Uag5KbVwI',
  52. 'md5': '314e87b1ebe7a48fcbfdd51b791ce5a6',
  53. 'info_dict': {
  54. 'id': '6573122',
  55. 'ext': 'mov',
  56. 'upload_date': '20130520',
  57. 'description': 'Two hapless space marines argue over what to do when they realize they have an astronomically huge problem on their hands.',
  58. 'title': 'Red vs. Blue Season 11 Trailer',
  59. 'timestamp': 1369029609,
  60. 'uploader': 'redvsblue',
  61. 'uploader_id': '792887',
  62. }
  63. },
  64. {
  65. 'url': 'http://blip.tv/play/gbk766dkj4Yn',
  66. 'md5': 'fe0a33f022d49399a241e84a8ea8b8e3',
  67. 'info_dict': {
  68. 'id': '1749452',
  69. 'ext': 'mp4',
  70. 'upload_date': '20090208',
  71. 'description': 'Witness the first appearance of the Nostalgia Critic character, as Doug reviews the movie Transformers.',
  72. 'title': 'Nostalgia Critic: Transformers',
  73. 'timestamp': 1234068723,
  74. 'uploader': 'NostalgiaCritic',
  75. 'uploader_id': '246467',
  76. }
  77. },
  78. {
  79. # https://github.com/rg3/youtube-dl/pull/4404
  80. 'note': 'Audio only',
  81. 'url': 'http://blip.tv/hilarios-productions/weekly-manga-recap-kingdom-7119982',
  82. 'md5': '76c0a56f24e769ceaab21fbb6416a351',
  83. 'info_dict': {
  84. 'id': '7103299',
  85. 'ext': 'flv',
  86. 'title': 'Weekly Manga Recap: Kingdom',
  87. 'description': 'And then Shin breaks the enemy line, and he&apos;s all like HWAH! And then he slices a guy and it&apos;s all like FWASHING! And... it&apos;s really hard to describe the best parts of this series without breaking down into sound effects, okay?',
  88. 'timestamp': 1417660321,
  89. 'upload_date': '20141204',
  90. 'uploader': 'The Rollo T',
  91. 'uploader_id': '407429',
  92. 'duration': 7251,
  93. 'vcodec': 'none',
  94. }
  95. },
  96. {
  97. # missing duration
  98. 'url': 'http://blip.tv/rss/flash/6700880',
  99. 'info_dict': {
  100. 'id': '6684191',
  101. 'ext': 'm4v',
  102. 'title': 'Cowboy Bebop: Gateway Shuffle Review',
  103. 'description': 'md5:3acc480c0f9ae157f5fe88547ecaf3f8',
  104. 'timestamp': 1386639757,
  105. 'upload_date': '20131210',
  106. 'uploader': 'sfdebris',
  107. 'uploader_id': '706520',
  108. }
  109. }
  110. ]
  111. @staticmethod
  112. def _extract_url(webpage):
  113. mobj = re.search(r'<meta\s[^>]*https?://api\.blip\.tv/\w+/redirect/\w+/(\d+)', webpage)
  114. if mobj:
  115. return 'http://blip.tv/a/a-' + mobj.group(1)
  116. mobj = re.search(r'<(?:iframe|embed|object)\s[^>]*(https?://(?:\w+\.)?blip\.tv/(?:play/|api\.swf#)[a-zA-Z0-9_]+)', webpage)
  117. if mobj:
  118. return mobj.group(1)
  119. def _real_extract(self, url):
  120. mobj = re.match(self._VALID_URL, url)
  121. lookup_id = mobj.group('lookup_id')
  122. # See https://github.com/rg3/youtube-dl/issues/857 and
  123. # https://github.com/rg3/youtube-dl/issues/4197
  124. if lookup_id:
  125. urlh = self._request_webpage(
  126. 'http://blip.tv/play/%s' % lookup_id, lookup_id, 'Resolving lookup id')
  127. url = compat_urlparse.urlparse(urlh.geturl())
  128. qs = compat_urlparse.parse_qs(url.query)
  129. mobj = re.match(self._VALID_URL, qs['file'][0])
  130. video_id = mobj.group('id')
  131. rss = self._download_xml('http://blip.tv/rss/flash/%s' % video_id, video_id, 'Downloading video RSS')
  132. def _x(p):
  133. return xpath_with_ns(p, {
  134. 'blip': 'http://blip.tv/dtd/blip/1.0',
  135. 'media': 'http://search.yahoo.com/mrss/',
  136. 'itunes': 'http://www.itunes.com/dtds/podcast-1.0.dtd',
  137. })
  138. item = rss.find('channel/item')
  139. video_id = xpath_text(item, _x('blip:item_id'), 'video id') or lookup_id
  140. title = xpath_text(item, 'title', 'title', fatal=True)
  141. description = clean_html(xpath_text(item, _x('blip:puredescription'), 'description'))
  142. timestamp = parse_iso8601(xpath_text(item, _x('blip:datestamp'), 'timestamp'))
  143. uploader = xpath_text(item, _x('blip:user'), 'uploader')
  144. uploader_id = xpath_text(item, _x('blip:userid'), 'uploader id')
  145. duration = int_or_none(xpath_text(item, _x('blip:runtime'), 'duration'))
  146. media_thumbnail = item.find(_x('media:thumbnail'))
  147. thumbnail = (media_thumbnail.get('url') if media_thumbnail is not None
  148. else xpath_text(item, 'image', 'thumbnail'))
  149. categories = [category.text for category in item.findall('category') if category is not None]
  150. formats = []
  151. subtitles_urls = {}
  152. media_group = item.find(_x('media:group'))
  153. for media_content in media_group.findall(_x('media:content')):
  154. url = media_content.get('url')
  155. role = media_content.get(_x('blip:role'))
  156. msg = self._download_webpage(
  157. url + '?showplayer=20140425131715&referrer=http://blip.tv&mask=7&skin=flashvars&view=url',
  158. video_id, 'Resolving URL for %s' % role)
  159. real_url = compat_urlparse.parse_qs(msg.strip())['message'][0]
  160. media_type = media_content.get('type')
  161. if media_type == 'text/srt' or url.endswith('.srt'):
  162. LANGS = {
  163. 'english': 'en',
  164. }
  165. lang = role.rpartition('-')[-1].strip().lower()
  166. langcode = LANGS.get(lang, lang)
  167. subtitles_urls[langcode] = url
  168. elif media_type.startswith('video/'):
  169. formats.append({
  170. 'url': real_url,
  171. 'format_id': role,
  172. 'format_note': media_type,
  173. 'vcodec': media_content.get(_x('blip:vcodec')) or 'none',
  174. 'acodec': media_content.get(_x('blip:acodec')),
  175. 'filesize': media_content.get('filesize'),
  176. 'width': int_or_none(media_content.get('width')),
  177. 'height': int_or_none(media_content.get('height')),
  178. })
  179. self._check_formats(formats, video_id)
  180. self._sort_formats(formats)
  181. subtitles = self.extract_subtitles(video_id, subtitles_urls)
  182. return {
  183. 'id': video_id,
  184. 'title': title,
  185. 'description': description,
  186. 'timestamp': timestamp,
  187. 'uploader': uploader,
  188. 'uploader_id': uploader_id,
  189. 'duration': duration,
  190. 'thumbnail': thumbnail,
  191. 'categories': categories,
  192. 'formats': formats,
  193. 'subtitles': subtitles,
  194. }
  195. def _get_subtitles(self, video_id, subtitles_urls):
  196. subtitles = {}
  197. for lang, url in subtitles_urls.items():
  198. # For some weird reason, blip.tv serves a video instead of subtitles
  199. # when we request with a common UA
  200. req = sanitized_Request(url)
  201. req.add_header('User-Agent', 'youtube-dl')
  202. subtitles[lang] = [{
  203. # The extension is 'srt' but it's actually an 'ass' file
  204. 'ext': 'ass',
  205. 'data': self._download_webpage(req, None, note=False),
  206. }]
  207. return subtitles
  208. class BlipTVUserIE(InfoExtractor):
  209. _VALID_URL = r'(?:(?:https?://(?:\w+\.)?blip\.tv/)|bliptvuser:)(?!api\.swf)([^/]+)/*$'
  210. _PAGE_SIZE = 12
  211. IE_NAME = 'blip.tv:user'
  212. _TEST = {
  213. 'url': 'http://blip.tv/actone',
  214. 'info_dict': {
  215. 'id': 'actone',
  216. 'title': 'Act One: The Series',
  217. },
  218. 'playlist_count': 5,
  219. }
  220. def _real_extract(self, url):
  221. mobj = re.match(self._VALID_URL, url)
  222. username = mobj.group(1)
  223. page_base = 'http://m.blip.tv/pr/show_get_full_episode_list?users_id=%s&lite=0&esi=1'
  224. page = self._download_webpage(url, username, 'Downloading user page')
  225. mobj = re.search(r'data-users-id="([^"]+)"', page)
  226. page_base = page_base % mobj.group(1)
  227. title = self._og_search_title(page)
  228. # Download video ids using BlipTV Ajax calls. Result size per
  229. # query is limited (currently to 12 videos) so we need to query
  230. # page by page until there are no video ids - it means we got
  231. # all of them.
  232. video_ids = []
  233. pagenum = 1
  234. while True:
  235. url = page_base + "&page=" + str(pagenum)
  236. page = self._download_webpage(
  237. url, username, 'Downloading video ids from page %d' % pagenum)
  238. # Extract video identifiers
  239. ids_in_page = []
  240. for mobj in re.finditer(r'href="/([^"]+)"', page):
  241. if mobj.group(1) not in ids_in_page:
  242. ids_in_page.append(unescapeHTML(mobj.group(1)))
  243. video_ids.extend(ids_in_page)
  244. # A little optimization - if current page is not
  245. # "full", ie. does not contain PAGE_SIZE video ids then
  246. # we can assume that this page is the last one - there
  247. # are no more ids on further pages - no need to query
  248. # again.
  249. if len(ids_in_page) < self._PAGE_SIZE:
  250. break
  251. pagenum += 1
  252. urls = ['http://blip.tv/%s' % video_id for video_id in video_ids]
  253. url_entries = [self.url_result(vurl, 'BlipTV') for vurl in urls]
  254. return self.playlist_result(
  255. url_entries, playlist_title=title, playlist_id=username)