vvvvget.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. from db import VVVVIDatabase
  2. from api import Api
  3. api = Api()
  4. stream_url = api.get_settings()
  5. if stream_url is None:
  6. print("VVVVID is not available at the moment")
  7. exit(1)
  8. vvvvidb = VVVVIDatabase("vvvvidb.sqlite3")
  9. api.login()
  10. last = 0
  11. smax = 1000
  12. if not vvvvidb.is_valid:
  13. # Database file not present
  14. # Create a new database
  15. vvvvidb.create()
  16. else:
  17. # Database file is already present
  18. # Since we have no information about series lenght prior to their pubblication
  19. # We scan all the older id to see if there are new episodes, then we scan every id greater then the last one
  20. ids = vvvvidb.series_id()
  21. for i in ids.keys():
  22. print("Fetching old...{}".format(i))
  23. info = api.get_info(i)
  24. if not info:
  25. continue
  26. seasons = api.get_seasons(i)
  27. for j in seasons:
  28. if j['season_id'] not in ids.get(i):
  29. # We found a new season for an old show
  30. if not vvvvidb.insert_serie((info['show_id'], info['title'], j['season_id'], j['name'])):
  31. continue
  32. # New episodes for a new or old season
  33. episodes = api.get_episodes(j['season_id'], i)
  34. eps = api.format_episodes(j['season_id'], info['show_id'], episodes)
  35. print("Found {} episodes".format(len(eps)))
  36. vvvvidb.insert_episodes(eps)
  37. last = i + 1
  38. smax = 200
  39. print("Resuming from...{}".format(last))
  40. # Scan all the episodes
  41. for i in range(last, last + smax):
  42. print("Fetching...{}".format(i))
  43. info = api.get_info(i)
  44. if not info:
  45. continue
  46. seasons = api.get_seasons(i)
  47. for j in seasons:
  48. print("Found: {}".format(info['title']))
  49. if not vvvvidb.insert_serie((info['show_id'], info['title'], j['season_id'], j.get('name'))):
  50. print("Serie already present")
  51. continue
  52. episodes = api.get_episodes(j['season_id'], i)
  53. eps = api.format_episodes(j['season_id'], info['show_id'], episodes)
  54. print("Found {} episodes".format(len(eps)))
  55. vvvvidb.insert_episodes(eps)