-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlibrary.py
61 lines (50 loc) · 2.24 KB
/
library.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import json
import inquirer
import requests
from utils import clear_screen, print_header
BASE_URL = "https://kissasian.lu/"
LIBRARY_FILE = 'data/library.json'
def read_library():
try:
with open(LIBRARY_FILE, 'r') as file:
return json.load(file)
except FileNotFoundError:
return []
def write_library(library):
with open(LIBRARY_FILE, 'w') as file:
json.dump(library, file, indent=4)
def library_menu():
from player import episode_menu
from kissasian import get_series_details
session = requests.Session()
while True:
clear_screen()
print_header()
library = read_library()
if not library:
print("Your library is empty.")
input("Press Enter to go back...")
break
choices = [series['title'] for series in library] + ['Go Back to Main Menu']
questions = [inquirer.List('series', message="Select a series", choices=choices)]
series_selection = inquirer.prompt(questions)['series']
if series_selection == 'Go Back to Main Menu':
break
selected_series = next(item for item in library if item['title'] == series_selection)
clear_screen()
print_header()
# Assuming get_series_details returns the expected values
summary, date_aired, cast, no_eps, eps_list = get_series_details(selected_series['url'])
print(f"Title: {selected_series['title']}\n\n{date_aired}\n\nSummary: {summary}\n\nCast: {', '.join(cast)}\n\nNumber of Episodes: {no_eps}\n")
choices = ['Go Back to Library', 'Remove From Library', 'Episode List']
questions = [inquirer.List('action', message="Select an action", choices=choices)]
answer = inquirer.prompt(questions)['action']
if answer == 'Remove From Library':
library = [item for item in library if item['url'] != selected_series['url']]
write_library(library)
print("Series removed from library.")
input("Press Enter to continue...")
elif answer == 'Episode List':
series_id = selected_series['url'].split('/')[-1]
# Now passing BASE_URL and session as required
episode_menu(eps_list, series_id, BASE_URL, session)