vvvvget/vvvvget.py

66 lines
1.8 KiB
Python
Raw Normal View History

2018-10-15 20:27:51 +02:00
from db import VVVVIDatabase
from api import Api
2018-03-27 22:10:39 +02:00
2018-10-15 20:27:51 +02:00
api = Api()
stream_url = api.get_settings()
if stream_url is None:
2018-05-21 17:22:14 +02:00
print("VVVVID is not available at the moment")
exit(1)
2018-10-15 20:27:51 +02:00
vvvvidb = VVVVIDatabase("vvvvidb.sqlite3")
api.login()
2018-10-17 23:43:44 +02:00
last = 0
smax = 1000
2018-05-21 17:22:14 +02:00
2018-10-15 20:27:51 +02:00
if not vvvvidb.is_valid:
# Database file not present
# Create a new database
vvvvidb.create()
2018-08-27 14:53:04 +02:00
else:
2018-10-15 20:27:51 +02:00
# Database file is already present
# Since we have no information about series lenght prior to their pubblication
# We scan all the older id to see if there are new episodes, then we scan every id greater then the last one
ids = vvvvidb.series_id()
2018-05-21 17:22:14 +02:00
2018-10-17 23:43:44 +02:00
for i in ids.keys():
print("Fetching old...{}".format(i))
info = api.get_info(i)
if not info:
continue
seasons = api.get_seasons(i)
for j in seasons:
if j['season_id'] not in ids.get(i):
# We found a new season for an old show
if not vvvvidb.insert_serie((info['show_id'], info['title'], j['season_id'], j['name'])):
continue
# New episodes for a new or old season
episodes = api.get_episodes(j['season_id'], i)
eps = api.format_episodes(j['season_id'], info['show_id'], episodes)
print("Found {} episodes".format(len(eps)))
vvvvidb.insert_episodes(eps)
last = i + 1
smax = 200
print("Resuming from...{}".format(last))
2018-10-15 20:27:51 +02:00
# Scan all the episodes
2018-10-17 23:43:44 +02:00
for i in range(last, last + smax):
2018-05-21 17:22:14 +02:00
print("Fetching...{}".format(i))
2018-10-15 20:27:51 +02:00
info = api.get_info(i)
if not info:
continue
seasons = api.get_seasons(i)
for j in seasons:
print("Found: {}".format(info['title']))
if not vvvvidb.insert_serie((info['show_id'], info['title'], j['season_id'], j['name'])):
print("Serie already present")
continue
episodes = api.get_episodes(j['season_id'], i)
eps = api.format_episodes(j['season_id'], info['show_id'], episodes)
print("Found {} episodes".format(len(eps)))
vvvvidb.insert_episodes(eps)