api.py 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. import requests
  2. class Api():
  3. ua = "Mozilla/5.0 (Windows; U; Win98; en-US; rv:0.9.4.2) Gecko/20020502 CS 2000 7.0/7.0"
  4. def __init__(self):
  5. print("Staring VVVVID Api")
  6. def ds(self, h):
  7. g = "MNOPIJKL89+/4567UVWXQRSTEFGHABCDcdefYZabstuvopqr0123wxyzklmnghij"
  8. def f(m):
  9. l = []
  10. o = 0
  11. b = False
  12. m_len = len(m)
  13. while ((not b) and o < m_len):
  14. n = m[o] << 2
  15. o += 1
  16. k = -1
  17. j = -1
  18. if o < m_len:
  19. n += m[o] >> 4
  20. o += 1
  21. if o < m_len:
  22. k = (m[o - 1] << 4) & 255
  23. k += m[o] >> 2
  24. o += 1
  25. if o < m_len:
  26. j = (m[o - 1] << 6) & 255
  27. j += m[o]
  28. o += 1
  29. else:
  30. b = True
  31. else:
  32. b = True
  33. else:
  34. b = True
  35. l.append(n)
  36. if k != -1:
  37. l.append(k)
  38. if j != -1:
  39. l.append(j)
  40. return l
  41. c = []
  42. for e in h:
  43. c.append(g.index(e))
  44. c_len = len(c)
  45. for e in range(c_len * 2 - 1, -1, -1):
  46. a = c[e % c_len] ^ c[(e + 1) % c_len]
  47. c[e % c_len] = a
  48. c = f(c)
  49. d = ''
  50. for e in c:
  51. d += chr(e)
  52. return d
  53. def get_settings(self):
  54. settings = requests.get('https://www.vvvvid.it/vvvvid/settings', headers={'User-Agent': Api.ua})
  55. if settings.status_code != 200:
  56. return None
  57. self.stream_url = settings.json()['data']['defaultStreamingServer']
  58. return self.stream_url
  59. def login(self):
  60. s = requests.session()
  61. login = s.get('https://www.vvvvid.it/user/login', headers={'User-Agent': Api.ua})
  62. self.conn_id = login.json()['data']['conn_id']
  63. self.session = s
  64. def get_info(self, show_id):
  65. info = self.session.get('https://www.vvvvid.it/vvvvid/ondemand/' + str(show_id) + '/info/?conn_id=' + self.conn_id, headers={'User-Agent': Api.ua})
  66. info.encoding = 'utf-8'
  67. info = info.json()
  68. if info['result'] == 'ok':
  69. return info['data']
  70. else:
  71. return False
  72. def get_seasons(self, show_id):
  73. seasons = self.session.get('https://www.vvvvid.it/vvvvid/ondemand/' + str(show_id) + '/seasons/?conn_id=' + self.conn_id, headers={'User-Agent': Api.ua}).json()
  74. if seasons['result'] == 'ok' and seasons['data']: # and seasons['data'][0]['episodes']:
  75. return seasons['data']
  76. else:
  77. return []
  78. def get_episodes(self, season_id, show_id):
  79. episodes = self.session.get('https://www.vvvvid.it/vvvvid/ondemand/' + str(show_id) + '/season/' + str(season_id) + '?conn_id=' + self.conn_id, headers={'User-Agent': Api.ua}).json()
  80. if episodes['result'] == 'ok' and episodes['data']: # and episodes['data'][0]['embed_info']:
  81. return episodes['data']
  82. else:
  83. return []
  84. def format_episodes(self, season_id, show_id, episodes):
  85. eps = []
  86. count = 0
  87. for k in episodes:
  88. count += 1
  89. if k.get('embed_info'):
  90. if k['video_type'] == 'video/rcs':
  91. embed_info = self.ds(k['embed_info'])
  92. embed_info = 'https' + embed_info[4:30] + 'i' + embed_info[31:-12] + 'master.m3u8'
  93. elif k['video_type'] == 'video/vvvvid':
  94. embed_info = 'https' + self.stream_url[4:] + self.ds(k['embed_info']) + '/playlist.m3u8'
  95. elif k['video_type'] == 'video/youtube':
  96. embed_info = self.ds(k['embed_info'])
  97. elif k['video_type'] == 'video/kenc':
  98. embed_info = self.ds(k['embed_info'])
  99. else:
  100. embed_info = self.ds(k['embed_info'])
  101. else:
  102. embed_info = ""
  103. eps.append((count, show_id, season_id, k['video_type'], embed_info))
  104. return eps