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.

217 lines
8.8 KiB

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
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..compat import (
  6. compat_HTTPError,
  7. compat_urllib_parse_unquote,
  8. )
  9. from ..utils import (
  10. determine_ext,
  11. ExtractorError,
  12. int_or_none,
  13. parse_iso8601,
  14. sanitized_Request,
  15. HEADRequest,
  16. url_basename,
  17. )
  18. class ViewsterIE(InfoExtractor):
  19. _VALID_URL = r'https?://(?:www\.)?viewster\.com/(?:serie|movie)/(?P<id>\d+-\d+-\d+)'
  20. _TESTS = [{
  21. # movie, Type=Movie
  22. 'url': 'http://www.viewster.com/movie/1140-11855-000/the-listening-project/',
  23. 'md5': 'e642d1b27fcf3a4ffa79f194f5adde36',
  24. 'info_dict': {
  25. 'id': '1140-11855-000',
  26. 'ext': 'mp4',
  27. 'title': 'The listening Project',
  28. 'description': 'md5:bac720244afd1a8ea279864e67baa071',
  29. 'timestamp': 1214870400,
  30. 'upload_date': '20080701',
  31. 'duration': 4680,
  32. },
  33. }, {
  34. # series episode, Type=Episode
  35. 'url': 'http://www.viewster.com/serie/1284-19427-001/the-world-and-a-wall/',
  36. 'md5': '9243079a8531809efe1b089db102c069',
  37. 'info_dict': {
  38. 'id': '1284-19427-001',
  39. 'ext': 'mp4',
  40. 'title': 'The World and a Wall',
  41. 'description': 'md5:24814cf74d3453fdf5bfef9716d073e3',
  42. 'timestamp': 1428192000,
  43. 'upload_date': '20150405',
  44. 'duration': 1500,
  45. },
  46. }, {
  47. # serie, Type=Serie
  48. 'url': 'http://www.viewster.com/serie/1303-19426-000/',
  49. 'info_dict': {
  50. 'id': '1303-19426-000',
  51. 'title': 'Is It Wrong to Try to Pick up Girls in a Dungeon?',
  52. 'description': 'md5:eeda9bef25b0d524b3a29a97804c2f11',
  53. },
  54. 'playlist_count': 13,
  55. }, {
  56. # unfinished serie, no Type
  57. 'url': 'http://www.viewster.com/serie/1284-19427-000/baby-steps-season-2/',
  58. 'info_dict': {
  59. 'id': '1284-19427-000',
  60. 'title': 'Baby Steps—Season 2',
  61. 'description': 'md5:e7097a8fc97151e25f085c9eb7a1cdb1',
  62. },
  63. 'playlist_mincount': 16,
  64. }, {
  65. # geo restricted series
  66. 'url': 'https://www.viewster.com/serie/1280-18794-002/',
  67. 'only_matching': True,
  68. }, {
  69. # geo restricted video
  70. 'url': 'https://www.viewster.com/serie/1280-18794-002/what-is-extraterritoriality-lawo/',
  71. 'only_matching': True,
  72. }]
  73. _ACCEPT_HEADER = 'application/json, text/javascript, */*; q=0.01'
  74. def _download_json(self, url, video_id, note='Downloading JSON metadata', fatal=True, query={}):
  75. request = sanitized_Request(url)
  76. request.add_header('Accept', self._ACCEPT_HEADER)
  77. request.add_header('Auth-token', self._AUTH_TOKEN)
  78. return super(ViewsterIE, self)._download_json(request, video_id, note, fatal=fatal, query=query)
  79. def _real_extract(self, url):
  80. video_id = self._match_id(url)
  81. # Get 'api_token' cookie
  82. self._request_webpage(
  83. HEADRequest('http://www.viewster.com/'),
  84. video_id, headers=self.geo_verification_headers())
  85. cookies = self._get_cookies('http://www.viewster.com/')
  86. self._AUTH_TOKEN = compat_urllib_parse_unquote(cookies['api_token'].value)
  87. info = self._download_json(
  88. 'https://public-api.viewster.com/search/%s' % video_id,
  89. video_id, 'Downloading entry JSON')
  90. entry_id = info.get('Id') or info['id']
  91. # unfinished serie has no Type
  92. if info.get('Type') in ('Serie', None):
  93. try:
  94. episodes = self._download_json(
  95. 'https://public-api.viewster.com/series/%s/episodes' % entry_id,
  96. video_id, 'Downloading series JSON')
  97. except ExtractorError as e:
  98. if isinstance(e.cause, compat_HTTPError) and e.cause.code == 404:
  99. self.raise_geo_restricted()
  100. else:
  101. raise
  102. entries = [
  103. self.url_result(
  104. 'http://www.viewster.com/movie/%s' % episode['OriginId'], 'Viewster')
  105. for episode in episodes]
  106. title = (info.get('Title') or info['Synopsis']['Title']).strip()
  107. description = info.get('Synopsis', {}).get('Detailed')
  108. return self.playlist_result(entries, video_id, title, description)
  109. formats = []
  110. for language_set in info.get('LanguageSets', []):
  111. manifest_url = None
  112. m3u8_formats = []
  113. audio = language_set.get('Audio') or ''
  114. subtitle = language_set.get('Subtitle') or ''
  115. base_format_id = audio
  116. if subtitle:
  117. base_format_id += '-%s' % subtitle
  118. def concat(suffix, sep='-'):
  119. return (base_format_id + '%s%s' % (sep, suffix)) if base_format_id else suffix
  120. medias = self._download_json(
  121. 'https://public-api.viewster.com/movies/%s/videos' % entry_id,
  122. video_id, fatal=False, query={
  123. 'mediaTypes': ['application/f4m+xml', 'application/x-mpegURL', 'video/mp4'],
  124. 'language': audio,
  125. 'subtitle': subtitle,
  126. })
  127. if not medias:
  128. continue
  129. for media in medias:
  130. video_url = media.get('Uri')
  131. if not video_url:
  132. continue
  133. ext = determine_ext(video_url)
  134. if ext == 'f4m':
  135. manifest_url = video_url
  136. video_url += '&' if '?' in video_url else '?'
  137. video_url += 'hdcore=3.2.0&plugin=flowplayer-3.2.0.1'
  138. formats.extend(self._extract_f4m_formats(
  139. video_url, video_id, f4m_id=concat('hds')))
  140. elif ext == 'm3u8':
  141. manifest_url = video_url
  142. m3u8_formats = self._extract_m3u8_formats(
  143. video_url, video_id, 'mp4', m3u8_id=concat('hls'),
  144. fatal=False) # m3u8 sometimes fail
  145. if m3u8_formats:
  146. formats.extend(m3u8_formats)
  147. else:
  148. qualities_basename = self._search_regex(
  149. r'/([^/]+)\.csmil/',
  150. manifest_url, 'qualities basename', default=None)
  151. if not qualities_basename:
  152. continue
  153. QUALITIES_RE = r'((,\d+k)+,?)'
  154. qualities = self._search_regex(
  155. QUALITIES_RE, qualities_basename,
  156. 'qualities', default=None)
  157. if not qualities:
  158. continue
  159. qualities = list(map(lambda q: int(q[:-1]), qualities.strip(',').split(',')))
  160. qualities.sort()
  161. http_template = re.sub(QUALITIES_RE, r'%dk', qualities_basename)
  162. http_url_basename = url_basename(video_url)
  163. if m3u8_formats:
  164. self._sort_formats(m3u8_formats)
  165. m3u8_formats = list(filter(
  166. lambda f: f.get('vcodec') != 'none', m3u8_formats))
  167. if len(qualities) == len(m3u8_formats):
  168. for q, m3u8_format in zip(qualities, m3u8_formats):
  169. f = m3u8_format.copy()
  170. f.update({
  171. 'url': video_url.replace(http_url_basename, http_template % q),
  172. 'format_id': f['format_id'].replace('hls', 'http'),
  173. 'protocol': 'http',
  174. })
  175. formats.append(f)
  176. else:
  177. for q in qualities:
  178. formats.append({
  179. 'url': video_url.replace(http_url_basename, http_template % q),
  180. 'ext': 'mp4',
  181. 'format_id': 'http-%d' % q,
  182. 'tbr': q,
  183. })
  184. if not formats and not info.get('VODSettings'):
  185. self.raise_geo_restricted()
  186. self._sort_formats(formats)
  187. synopsis = info.get('Synopsis') or {}
  188. # Prefer title outside synopsis since it's less messy
  189. title = (info.get('Title') or synopsis['Title']).strip()
  190. description = synopsis.get('Detailed') or (info.get('Synopsis') or {}).get('Short')
  191. duration = int_or_none(info.get('Duration'))
  192. timestamp = parse_iso8601(info.get('ReleaseDate'))
  193. return {
  194. 'id': video_id,
  195. 'title': title,
  196. 'description': description,
  197. 'timestamp': timestamp,
  198. 'duration': duration,
  199. 'formats': formats,
  200. }