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.

140 lines
4.9 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. ExtractorError,
  7. int_or_none,
  8. str_or_none,
  9. )
  10. class VVVVIDIE(InfoExtractor):
  11. _VALID_URL = r'https?://(?:www\.)?vvvvid\.it/#!(?:show|anime|film|series)/(?P<show_id>\d+)/[^/]+/(?P<season_id>\d+)/(?P<id>[0-9]+)'
  12. _TESTS = [{
  13. # video_type == 'video/vvvvid'
  14. 'url': 'https://www.vvvvid.it/#!show/434/perche-dovrei-guardarlo-di-dario-moccia/437/489048/ping-pong',
  15. 'md5': 'b8d3cecc2e981adc3835adf07f6df91b',
  16. 'info_dict': {
  17. 'id': '489048',
  18. 'ext': 'mp4',
  19. 'title': 'Ping Pong',
  20. },
  21. }, {
  22. # video_type == 'video/rcs'
  23. 'url': 'https://www.vvvvid.it/#!show/376/death-note-live-action/377/482493/episodio-01',
  24. 'md5': '33e0edfba720ad73a8782157fdebc648',
  25. 'info_dict': {
  26. 'id': '482493',
  27. 'ext': 'mp4',
  28. 'title': 'Episodio 01',
  29. },
  30. }]
  31. _conn_id = None
  32. def _real_initialize(self):
  33. self._conn_id = self._download_json(
  34. 'https://www.vvvvid.it/user/login',
  35. None, headers=self.geo_verification_headers())['data']['conn_id']
  36. def _real_extract(self, url):
  37. show_id, season_id, video_id = re.match(self._VALID_URL, url).groups()
  38. response = self._download_json(
  39. 'https://www.vvvvid.it/vvvvid/ondemand/%s/season/%s' % (show_id, season_id),
  40. video_id, headers=self.geo_verification_headers(), query={
  41. 'conn_id': self._conn_id,
  42. })
  43. if response['result'] == 'error':
  44. raise ExtractorError('%s said: %s' % (
  45. self.IE_NAME, response['message']), expected=True)
  46. vid = int(video_id)
  47. video_data = list(filter(
  48. lambda episode: episode.get('video_id') == vid, response['data']))[0]
  49. formats = []
  50. # vvvvid embed_info decryption algorithm is reverse engineered from function $ds(h) at vvvvid.js
  51. def ds(h):
  52. g = "MNOPIJKL89+/4567UVWXQRSTEFGHABCDcdefYZabstuvopqr0123wxyzklmnghij"
  53. def f(m):
  54. l = []
  55. o = 0
  56. b = False
  57. m_len = len(m)
  58. while ((not b) and o < m_len):
  59. n = m[o] << 2
  60. o += 1
  61. k = -1
  62. j = -1
  63. if o < m_len:
  64. n += m[o] >> 4
  65. o += 1
  66. if o < m_len:
  67. k = (m[o - 1] << 4) & 255
  68. k += m[o] >> 2
  69. o += 1
  70. if o < m_len:
  71. j = (m[o - 1] << 6) & 255
  72. j += m[o]
  73. o += 1
  74. else:
  75. b = True
  76. else:
  77. b = True
  78. else:
  79. b = True
  80. l.append(n)
  81. if k != -1:
  82. l.append(k)
  83. if j != -1:
  84. l.append(j)
  85. return l
  86. c = []
  87. for e in h:
  88. c.append(g.index(e))
  89. c_len = len(c)
  90. for e in range(c_len * 2 - 1, -1, -1):
  91. a = c[e % c_len] ^ c[(e + 1) % c_len]
  92. c[e % c_len] = a
  93. c = f(c)
  94. d = ''
  95. for e in c:
  96. d += chr(e)
  97. return d
  98. for quality in ('_sd', ''):
  99. embed_code = video_data.get('embed_info' + quality)
  100. if not embed_code:
  101. continue
  102. embed_code = ds(embed_code)
  103. video_type = video_data.get('video_type')
  104. if video_type in ('video/rcs', 'video/kenc'):
  105. formats.extend(self._extract_akamai_formats(
  106. embed_code, video_id))
  107. else:
  108. formats.extend(self._extract_wowza_formats(
  109. 'http://sb.top-ix.org/videomg/_definst_/mp4:%s/playlist.m3u8' % embed_code, video_id))
  110. self._sort_formats(formats)
  111. return {
  112. 'id': video_id,
  113. 'title': video_data['title'],
  114. 'formats': formats,
  115. 'thumbnail': video_data.get('thumbnail'),
  116. 'duration': int_or_none(video_data.get('length')),
  117. 'series': video_data.get('show_title'),
  118. 'season_id': season_id,
  119. 'season_number': video_data.get('season_number'),
  120. 'episode_id': str_or_none(video_data.get('id')),
  121. 'epidode_number': int_or_none(video_data.get('number')),
  122. 'episode_title': video_data['title'],
  123. 'view_count': int_or_none(video_data.get('views')),
  124. 'like_count': int_or_none(video_data.get('video_likes')),
  125. }