api.py 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. login = requests.get('https://www.vvvvid.it/user/login', headers={'User-Agent': Api.ua})
  61. self.conn_id = login.json()['data']['conn_id']
  62. def get_info(self, show_id):
  63. info = requests.get('https://www.vvvvid.it/vvvvid/ondemand/' + str(show_id) + '/info/?conn_id=' + self.conn_id, headers={'User-Agent': Api.ua})
  64. info.encoding = 'utf-8'
  65. if info.json()['result'] == 'ok':
  66. return info.json()['data']
  67. else:
  68. return False
  69. def get_seasons(self, show_id):
  70. seasons = requests.get('https://www.vvvvid.it/vvvvid/ondemand/' + str(show_id) + '/seasons/?conn_id=' + self.conn_id, headers={'User-Agent': Api.ua})
  71. if seasons.json()['result'] == 'ok' and seasons.json()['data'] and seasons.json()['data'][0]['episodes']:
  72. return seasons.json()['data']
  73. else:
  74. return []
  75. def get_episodes(self, season_id, show_id):
  76. episodes = requests.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()
  77. if episodes['result'] == 'ok' and episodes['data'] and episodes['data'][0]['embed_info']:
  78. return episodes['data']
  79. else:
  80. return []
  81. def format_episodes(self, season_id, show_id, episodes):
  82. eps = []
  83. count = 0
  84. for k in episodes:
  85. count += 1
  86. if k['embed_info']:
  87. if k['video_type'] == 'video/rcs':
  88. embed_info = self.ds(k['embed_info'])
  89. embed_info = 'https' + embed_info[4:30] + 'i' + embed_info[31:-12] + 'master.m3u8'
  90. elif k['video_type'] == 'video/vvvvid':
  91. embed_info = 'https' + self.stream_url[4:] + self.ds(k['embed_info']) + '/playlist.m3u8'
  92. elif k['video_type'] == 'video/youtube':
  93. embed_info = self.ds(k['embed_info'])
  94. elif k['video_type'] == 'video/kenc':
  95. embed_info = self.ds(k['embed_info'])
  96. else:
  97. embed_info = self.ds(k['embed_info'])
  98. eps.append((count, show_id, season_id, k['video_type'], embed_info))
  99. return eps