2023-05-16 16:33:36 -04:00
|
|
|
from urllib.parse import unquote, quote
|
|
|
|
from scrapper import get_uri, get_files
|
2023-05-16 17:25:05 -04:00
|
|
|
from urllib.parse import quote, unquote
|
2023-05-16 16:33:36 -04:00
|
|
|
import player
|
|
|
|
from database import Database
|
|
|
|
from utils import get_url
|
|
|
|
import menu
|
|
|
|
|
|
|
|
def files_navigator(site: dict):
|
|
|
|
if site.get("id") == database.get_last_site_id():
|
|
|
|
path = database.get_last_path()
|
2023-05-15 12:30:33 -04:00
|
|
|
else:
|
2023-05-16 16:33:36 -04:00
|
|
|
path = '/'
|
2023-05-29 13:23:39 -04:00
|
|
|
database.set_last_site(site.get("id"))
|
2023-05-15 12:30:33 -04:00
|
|
|
while True:
|
2023-05-29 13:23:39 -04:00
|
|
|
pos = database.get_last_cursor_pos()
|
2023-05-16 17:25:05 -04:00
|
|
|
path = get_uri(get_url(site) + path)
|
2023-05-16 16:33:36 -04:00
|
|
|
database.set_last_path(path)
|
2023-05-29 13:23:39 -04:00
|
|
|
file = menu.files(site, path, database, pos)
|
2023-05-16 16:33:36 -04:00
|
|
|
if (file == None):
|
|
|
|
return
|
|
|
|
elif (file == "../" and path == "/"):
|
2023-05-15 12:30:33 -04:00
|
|
|
return
|
|
|
|
if (not file.endswith("/")):
|
2023-05-16 17:25:05 -04:00
|
|
|
player.play(get_url(site) + quote(path + file), database)
|
2023-05-15 12:30:33 -04:00
|
|
|
else:
|
2023-05-16 16:33:36 -04:00
|
|
|
path = path + file
|
2023-05-15 12:30:33 -04:00
|
|
|
|
2023-05-17 05:08:40 -04:00
|
|
|
def add_site(database: Database):
|
|
|
|
site = menu.add_site(database)
|
2023-05-16 16:33:36 -04:00
|
|
|
database.add_site(site)
|
2023-05-15 12:30:33 -04:00
|
|
|
|
2023-05-15 15:12:10 -04:00
|
|
|
def config_preview(site_name:str):
|
|
|
|
id = int(site_name.split(": ")[0])
|
2023-05-16 16:33:36 -04:00
|
|
|
site = database.get_site_by_id(id)
|
2023-05-15 15:12:10 -04:00
|
|
|
str = f"""
|
|
|
|
url: {site.get('url')}
|
|
|
|
user: {site.get('user')}
|
|
|
|
password: {site.get('password')}
|
|
|
|
"""
|
|
|
|
return (str)
|
|
|
|
|
2023-05-17 05:08:40 -04:00
|
|
|
def sites_deleter(database: Database):
|
2023-05-15 15:12:10 -04:00
|
|
|
lst = []
|
2023-05-17 05:08:40 -04:00
|
|
|
for i in database.get_sites():
|
2023-05-15 15:12:10 -04:00
|
|
|
lst.append(f"{str(i.get('id'))}: {i.get('name')}")
|
2023-05-17 05:08:40 -04:00
|
|
|
choose = menu.site_deleter(lst, database)
|
2023-05-15 15:12:10 -04:00
|
|
|
if (choose == None):
|
|
|
|
return (1)
|
|
|
|
site_name = lst[choose]
|
|
|
|
id = int(site_name.split(": ")[0])
|
|
|
|
sites_table.remove(query.id == id)
|
2023-05-16 16:33:36 -04:00
|
|
|
if (database.get_last_site() == id):
|
|
|
|
database.set_last_path("")
|
|
|
|
database.set_last_site("")
|
2023-05-15 15:35:32 -04:00
|
|
|
|
2023-05-17 05:08:40 -04:00
|
|
|
def sites_editor(database: Database):
|
2023-05-15 15:35:32 -04:00
|
|
|
lst = []
|
2023-05-16 16:33:36 -04:00
|
|
|
for i in database.get_sites():
|
2023-05-15 15:35:32 -04:00
|
|
|
lst.append(f"{str(i.get('id'))}: {i.get('name')}")
|
2023-05-17 05:08:40 -04:00
|
|
|
choose = menu.site_editor(lst, database)
|
2023-05-15 15:35:32 -04:00
|
|
|
if (choose == None):
|
|
|
|
return (1)
|
|
|
|
site_name = lst[choose]
|
|
|
|
id = int(site_name.split(": ")[0])
|
2023-05-16 16:33:36 -04:00
|
|
|
site = database.get_site_by_id(id)
|
2023-05-15 15:35:32 -04:00
|
|
|
lst = [f"name: {site.get('name')}", f"url: {site.get('url')}", f"user: {site.get('user')}", f"password: {site.get('password')}"]
|
2023-05-17 05:08:40 -04:00
|
|
|
choose = menu.param_editor(lst)
|
2023-05-15 15:35:32 -04:00
|
|
|
if (choose == None):
|
|
|
|
return (1);
|
|
|
|
for i in lst:
|
|
|
|
print(i);
|
|
|
|
if (choose == 0):
|
|
|
|
sites_table.update(set("name", input("name: ")), query.id == id)
|
|
|
|
elif (choose == 1):
|
|
|
|
sites_table.update(set("url", input("url: ")), query.id == id)
|
|
|
|
elif (choose == 2):
|
|
|
|
sites_table.update(set("user", input("user: ")), query.id == id)
|
|
|
|
elif (choose == 3):
|
|
|
|
sites_table.update(set("password", input("password: ")), query.id == id)
|
2023-05-15 15:12:10 -04:00
|
|
|
|
2023-05-17 05:08:40 -04:00
|
|
|
def sites_navigator(database: Database):
|
2023-05-16 16:33:36 -04:00
|
|
|
nb_site = database.get_sites_table_len()
|
|
|
|
if (nb_site == 0):
|
2023-05-17 05:14:23 -04:00
|
|
|
add_site(database)
|
2023-05-16 16:33:36 -04:00
|
|
|
nb_site = 1
|
|
|
|
last_site = database.get_last_site()
|
2023-05-15 14:26:00 -04:00
|
|
|
if (last_site != None):
|
2023-05-16 16:33:36 -04:00
|
|
|
files_navigator(last_site)
|
2023-05-15 12:30:33 -04:00
|
|
|
while True:
|
2023-05-16 16:33:36 -04:00
|
|
|
nb_site = database.get_sites_table_len()
|
2023-05-17 05:08:40 -04:00
|
|
|
choose = menu.sites(database.get_sites())
|
2023-05-15 15:12:10 -04:00
|
|
|
if (choose == None):
|
|
|
|
return (1)
|
2023-05-16 16:33:36 -04:00
|
|
|
if (choose == nb_site + 1):
|
2023-05-17 05:08:40 -04:00
|
|
|
add_site(database);
|
2023-05-16 16:33:36 -04:00
|
|
|
elif (choose == nb_site + 2):
|
2023-05-17 05:08:40 -04:00
|
|
|
sites_editor(database)
|
2023-05-16 16:33:36 -04:00
|
|
|
elif (choose == nb_site + 3):
|
2023-05-17 05:08:40 -04:00
|
|
|
sites_deleter(database)
|
|
|
|
sites_navigator(database)
|
2023-05-15 15:12:10 -04:00
|
|
|
return
|
2023-05-15 12:30:33 -04:00
|
|
|
else:
|
2023-05-17 05:08:40 -04:00
|
|
|
files_navigator(database.get_sites()[choose])
|
2023-05-15 12:30:33 -04:00
|
|
|
|
2023-05-16 16:33:36 -04:00
|
|
|
database = Database()
|
2023-05-15 12:30:33 -04:00
|
|
|
|
2023-05-16 16:33:36 -04:00
|
|
|
if (database.get_cookies_table_len() == 0):
|
2023-05-29 13:23:39 -04:00
|
|
|
database.add_cookies({"last_path": "", "last_site": "", "last_cursor_pos": 0, "id": "0"})
|
2023-05-17 05:08:40 -04:00
|
|
|
sites_navigator(database);
|