vvvvget.py 1.2 KB

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