From 913be0e412e103bb697097d1614ffaec1040694b Mon Sep 17 00:00:00 2001 From: thezero Date: Wed, 17 Oct 2018 23:43:44 +0200 Subject: [PATCH] improve seasons/episodes fetching --- api.py | 21 ++++++++++++--------- db.py | 9 ++++----- db_to_html.py | 10 +++++----- vvvvget.py | 32 ++++++++++++++++++++++++++------ 4 files changed, 47 insertions(+), 25 deletions(-) diff --git a/api.py b/api.py index ab7fec8..8e6e4df 100644 --- a/api.py +++ b/api.py @@ -67,27 +67,28 @@ class Api(): return self.stream_url def login(self): - login = requests.get('https://www.vvvvid.it/user/login', headers={'User-Agent': Api.ua}) - self.conn_id = login.json()['data']['conn_id'] + login = requests.get('https://www.vvvvid.it/user/login', headers={'User-Agent': Api.ua}).json() + self.conn_id = login['data']['conn_id'] def get_info(self, show_id): info = requests.get('https://www.vvvvid.it/vvvvid/ondemand/' + str(show_id) + '/info/?conn_id=' + self.conn_id, headers={'User-Agent': Api.ua}) info.encoding = 'utf-8' - if info.json()['result'] == 'ok': - return info.json()['data'] + info = info.json() + if info['result'] == 'ok': + return info['data'] else: return False def get_seasons(self, show_id): - seasons = requests.get('https://www.vvvvid.it/vvvvid/ondemand/' + str(show_id) + '/seasons/?conn_id=' + self.conn_id, headers={'User-Agent': Api.ua}) - if seasons.json()['result'] == 'ok' and seasons.json()['data'] and seasons.json()['data'][0]['episodes']: - return seasons.json()['data'] + seasons = requests.get('https://www.vvvvid.it/vvvvid/ondemand/' + str(show_id) + '/seasons/?conn_id=' + self.conn_id, headers={'User-Agent': Api.ua}).json() + if seasons['result'] == 'ok' and seasons['data']: # and seasons['data'][0]['episodes']: + return seasons['data'] else: return [] def get_episodes(self, season_id, show_id): 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() - if episodes['result'] == 'ok' and episodes['data'] and episodes['data'][0]['embed_info']: + if episodes['result'] == 'ok' and episodes['data']: # and episodes['data'][0]['embed_info']: return episodes['data'] else: return [] @@ -97,7 +98,7 @@ class Api(): count = 0 for k in episodes: count += 1 - if k['embed_info']: + if k.get('embed_info'): if k['video_type'] == 'video/rcs': embed_info = self.ds(k['embed_info']) embed_info = 'https' + embed_info[4:30] + 'i' + embed_info[31:-12] + 'master.m3u8' @@ -109,5 +110,7 @@ class Api(): embed_info = self.ds(k['embed_info']) else: embed_info = self.ds(k['embed_info']) + else: + embed_info = "" eps.append((count, show_id, season_id, k['video_type'], embed_info)) return eps diff --git a/db.py b/db.py index 48c6ae7..31cda5e 100644 --- a/db.py +++ b/db.py @@ -34,7 +34,7 @@ class VVVVIDatabase(): con.close() # getting series in a useful format for later series = {} - for i,s in rows: + for i, s in rows: if series.get(i) is None: series[i] = [] series[i].append(s) @@ -49,12 +49,11 @@ class VVVVIDatabase(): con.close() # getting series in a useful format for later series = {} - for i,s in rows: + for i, s in rows: if series.get(i) is None: series[i] = [] series[i].append(s) - return series - + return series def insert_serie(self, serie): con = sqlite3.connect(self.path) @@ -80,4 +79,4 @@ class VVVVIDatabase(): except sqlite3.IntegrityError: # episodi gia' presenti pass - return False \ No newline at end of file + return False diff --git a/db_to_html.py b/db_to_html.py index 76c3c64..86a834b 100644 --- a/db_to_html.py +++ b/db_to_html.py @@ -3,7 +3,7 @@ import sqlite3 vvvvidb = "vvvvidb.sqlite3" -if not os.path.isfile(vvvvidb): +if not os.path.isfile(vvvvidb): print("{} file not found. Scrape the DB first using vvvvget.py".format(vvvvidb)) exit(1) @@ -23,10 +23,10 @@ out.write(''' Source Database

''') -# select all the series +# Select all the series # cur.execute("SELECT * FROM series;") -# selecy only series with at least one episodes +# Selecy only series with at least one episodes cur.execute("SELECT s.* FROM series as s INNER JOIN episodes as e ON e.serie_id = s.id AND e.season_id = s.season_id GROUP BY s.id, s.season_id;") series = cur.fetchall() @@ -34,7 +34,7 @@ for s in series: serie = (str(s[0]), str(s[2])) out.write("\t

{}: {} - Id Serie: {} - Tipo: {}

\n\t