vvvvget.py 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. import os
  2. import json
  3. import requests
  4. import sqlite3
  5. def ds(h):
  6. g = "MNOPIJKL89+/4567UVWXQRSTEFGHABCDcdefYZabstuvopqr0123wxyzklmnghij"
  7. def f(m):
  8. l = []
  9. o = 0
  10. b = False
  11. m_len = len(m)
  12. while ((not b) and o < m_len):
  13. n = m[o] << 2
  14. o += 1
  15. k = -1
  16. j = -1
  17. if o < m_len:
  18. n += m[o] >> 4
  19. o += 1
  20. if o < m_len:
  21. k = (m[o - 1] << 4) & 255
  22. k += m[o] >> 2
  23. o += 1
  24. if o < m_len:
  25. j = (m[o - 1] << 6) & 255
  26. j += m[o]
  27. o += 1
  28. else:
  29. b = True
  30. else:
  31. b = True
  32. else:
  33. b = True
  34. l.append(n)
  35. if k != -1:
  36. l.append(k)
  37. if j != -1:
  38. l.append(j)
  39. return l
  40. c = []
  41. for e in h:
  42. c.append(g.index(e))
  43. c_len = len(c)
  44. for e in range(c_len * 2 - 1, -1, -1):
  45. a = c[e % c_len] ^ c[(e + 1) % c_len]
  46. c[e % c_len] = a
  47. c = f(c)
  48. d = ''
  49. for e in c:
  50. d += chr(e)
  51. return d
  52. def get_settings():
  53. settings = requests.get('https://www.vvvvid.it/vvvvid/settings')
  54. if settings.status_code != 200:
  55. return None
  56. return settings.json()['data']['defaultStreamingServer']
  57. def login():
  58. login = requests.get('https://www.vvvvid.it/user/login')
  59. return login.json()['data']['conn_id']
  60. def get_info(show_id, conn_id):
  61. info = requests.get('https://www.vvvvid.it/vvvvid/ondemand/' + str(show_id) + '/info/?conn_id=' + conn_id)
  62. info.encoding = 'utf-8'
  63. if info.json()['result'] == 'ok':
  64. return info.json()['data']
  65. else:
  66. return False
  67. def get_seasons(show_id, conn_id):
  68. seasons = requests.get('https://www.vvvvid.it/vvvvid/ondemand/' + str(show_id) + '/seasons/?conn_id=' + conn_id)
  69. if seasons.json()['result'] == 'ok' and seasons.json()['data'] and seasons.json()['data'][0]['episodes']:
  70. return seasons.json()['data']
  71. else:
  72. return False
  73. def get_episodes(season_id, show_id, conn_id):
  74. episodes = requests.get('https://www.vvvvid.it/vvvvid/ondemand/' + str(show_id) + '/season/' +str(season_id) + '?conn_id=' + conn_id)
  75. if episodes.json()['result'] == 'ok' and episodes.json()['data'] and episodes.json()['data'][0]['embed_info']:
  76. return episodes.json()['data']
  77. else:
  78. return False
  79. vvvvid_stream_url = get_settings()
  80. if vvvvid_stream_url is None:
  81. print("VVVVID is not available at the moment")
  82. exit(1)
  83. vvvvidb = "vvvvidb.sqlite3"
  84. last = 0
  85. if not os.path.isfile(vvvvidb):
  86. con = sqlite3.connect(vvvvidb)
  87. cur = con.cursor()
  88. cur.execute("CREATE TABLE series (id INTEGER, name TEXT NOT NULL, season_id INTEGER, type TEXT, PRIMARY KEY (id, season_id));")
  89. cur.execute("CREATE TABLE episodes (serie_id INTEGER, season_id INTEGER, cdn_url TEXT NOT NULL, type TEXT NOT NULL);")
  90. con.commit()
  91. con.close()
  92. #else:
  93. # con = sqlite3.connect(vvvvidb)
  94. # cur = con.cursor()
  95. # cur.execute("SELECT id FROM series ORDER BY id DESC LIMIT 1;")
  96. # rows = cur.fetchall()
  97. # if len(rows) > 0:
  98. # last = rows[0][0] + 1
  99. # con.commit()
  100. # con.close()
  101. #
  102. #print("Resuming from...{}".format(last))
  103. con = sqlite3.connect(vvvvidb)
  104. cur = con.cursor()
  105. stream_url = get_settings()
  106. conn_id = login()
  107. for i in range(last, min(last + 500, 1000)):
  108. print("Fetching...{}".format(i))
  109. info = get_info(i, conn_id)
  110. if info:
  111. seasons = get_seasons(i, conn_id)
  112. if seasons:
  113. for j in seasons:
  114. serie = (info['show_id'], info['title'], j['season_id'], j['name'])
  115. print("Found: {}".format(info['title']))
  116. try:
  117. cur.execute("INSERT INTO series (id, name, season_id, type) VALUES (?, ?, ?, ?);", serie)
  118. con.commit()
  119. except sqlite3.IntegrityError:
  120. # serie/stagione gia' presente, salta il fetch degli episodi
  121. continue
  122. eps = []
  123. episodes = get_episodes(j['season_id'], i, conn_id)
  124. if episodes:
  125. for k in episodes:
  126. if k['embed_info']:
  127. if k['video_type'] == 'video/rcs':
  128. embed_info = ds(k['embed_info'])
  129. embed_info = 'https' + embed_info[4:30] + 'i' + embed_info[31:-12] + 'master.m3u8'
  130. elif k['video_type'] == 'video/vvvvid':
  131. embed_info = 'https' + vvvvid_stream_url[4:] + ds(k['embed_info']) + '/playlist.m3u8'
  132. elif k['video_type'] == 'video/youtube':
  133. embed_info = ds(k['embed_info'])
  134. elif k['video_type'] == 'video/kenc':
  135. embed_info = ds(k['embed_info'])
  136. else:
  137. embed_info = ds(k['embed_info'])
  138. eps.append((info['show_id'], j['season_id'], k['video_type'], embed_info))
  139. print("Found {} episodes".format(len(eps)))
  140. try:
  141. cur.executemany("INSERT INTO episodes (serie_id, season_id, type, cdn_url) VALUES (?, ?, ?, ?);", eps)
  142. con.commit()
  143. except sqlite3.IntegrityError:
  144. # episodi gia' presenti
  145. pass
  146. con.close()