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.

137 lines
5.2 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..compat import (
  5. compat_urllib_request,
  6. compat_urllib_parse,
  7. )
  8. from ..utils import (
  9. determine_ext,
  10. int_or_none,
  11. parse_iso8601,
  12. )
  13. class ViewsterIE(InfoExtractor):
  14. _VALID_URL = r'http://(?:www\.)?viewster\.com/(?:serie|movie)/(?P<id>\d+-\d+-\d+)'
  15. _TESTS = [{
  16. # movie, Type=Movie
  17. 'url': 'http://www.viewster.com/movie/1140-11855-000/the-listening-project/',
  18. 'md5': '14d3cfffe66d57b41ae2d9c873416f01',
  19. 'info_dict': {
  20. 'id': '1140-11855-000',
  21. 'ext': 'flv',
  22. 'title': 'The listening Project',
  23. 'description': 'md5:bac720244afd1a8ea279864e67baa071',
  24. 'timestamp': 1214870400,
  25. 'upload_date': '20080701',
  26. 'duration': 4680,
  27. },
  28. }, {
  29. # series episode, Type=Episode
  30. 'url': 'http://www.viewster.com/serie/1284-19427-001/the-world-and-a-wall/',
  31. 'md5': 'd5434c80fcfdb61651cc2199a88d6ba3',
  32. 'info_dict': {
  33. 'id': '1284-19427-001',
  34. 'ext': 'flv',
  35. 'title': 'The World and a Wall',
  36. 'description': 'md5:24814cf74d3453fdf5bfef9716d073e3',
  37. 'timestamp': 1428192000,
  38. 'upload_date': '20150405',
  39. 'duration': 1500,
  40. },
  41. }, {
  42. # serie, Type=Serie
  43. 'url': 'http://www.viewster.com/serie/1303-19426-000/',
  44. 'info_dict': {
  45. 'id': '1303-19426-000',
  46. 'title': 'Is It Wrong to Try to Pick up Girls in a Dungeon?',
  47. 'description': 'md5:eeda9bef25b0d524b3a29a97804c2f11',
  48. },
  49. 'playlist_count': 13,
  50. }, {
  51. # unfinished serie, no Type
  52. 'url': 'http://www.viewster.com/serie/1284-19427-000/baby-steps-season-2/',
  53. 'info_dict': {
  54. 'id': '1284-19427-000',
  55. 'title': 'Baby Steps—Season 2',
  56. 'description': 'md5:e7097a8fc97151e25f085c9eb7a1cdb1',
  57. },
  58. 'playlist_mincount': 16,
  59. }]
  60. _ACCEPT_HEADER = 'application/json, text/javascript, */*; q=0.01'
  61. _AUTH_TOKEN = '/YqhSYsx8EaU9Bsta3ojlA=='
  62. def _download_json(self, url, video_id, note='Downloading JSON metadata', fatal=True):
  63. request = compat_urllib_request.Request(url)
  64. request.add_header('Accept', self._ACCEPT_HEADER)
  65. request.add_header('Auth-token', self._AUTH_TOKEN)
  66. return super(ViewsterIE, self)._download_json(request, video_id, note, fatal=fatal)
  67. def _real_extract(self, url):
  68. video_id = self._match_id(url)
  69. info = self._download_json(
  70. 'https://public-api.viewster.com/search/%s' % video_id,
  71. video_id, 'Downloading entry JSON')
  72. entry_id = info.get('Id') or info['id']
  73. # unfinished serie has no Type
  74. if info.get('Type') in ['Serie', None]:
  75. episodes = self._download_json(
  76. 'https://public-api.viewster.com/series/%s/episodes' % entry_id,
  77. video_id, 'Downloading series JSON')
  78. entries = [
  79. self.url_result(
  80. 'http://www.viewster.com/movie/%s' % episode['OriginId'], 'Viewster')
  81. for episode in episodes]
  82. title = (info.get('Title') or info['Synopsis']['Title']).strip()
  83. description = info.get('Synopsis', {}).get('Detailed')
  84. return self.playlist_result(entries, video_id, title, description)
  85. formats = []
  86. for media_type in ('application/f4m+xml', 'application/x-mpegURL'):
  87. media = self._download_json(
  88. 'https://public-api.viewster.com/movies/%s/video?mediaType=%s'
  89. % (entry_id, compat_urllib_parse.quote(media_type)),
  90. video_id, 'Downloading %s JSON' % media_type, fatal=False)
  91. if not media:
  92. continue
  93. video_url = media.get('Uri')
  94. if not video_url:
  95. continue
  96. ext = determine_ext(video_url)
  97. if ext == 'f4m':
  98. video_url += '&' if '?' in video_url else '?'
  99. video_url += 'hdcore=3.2.0&plugin=flowplayer-3.2.0.1'
  100. formats.extend(self._extract_f4m_formats(
  101. video_url, video_id, f4m_id='hds'))
  102. elif ext == 'm3u8':
  103. formats.extend(self._extract_m3u8_formats(
  104. video_url, video_id, 'mp4', m3u8_id='hls',
  105. fatal=False # m3u8 sometimes fail
  106. ))
  107. else:
  108. formats.append({
  109. 'url': video_url,
  110. })
  111. self._sort_formats(formats)
  112. synopsis = info.get('Synopsis', {})
  113. # Prefer title outside synopsis since it's less messy
  114. title = (info.get('Title') or synopsis['Title']).strip()
  115. description = synopsis.get('Detailed') or info.get('Synopsis', {}).get('Short')
  116. duration = int_or_none(info.get('Duration'))
  117. timestamp = parse_iso8601(info.get('ReleaseDate'))
  118. return {
  119. 'id': video_id,
  120. 'title': title,
  121. 'description': description,
  122. 'timestamp': timestamp,
  123. 'duration': duration,
  124. 'formats': formats,
  125. }