VLC_HTTP_LAUNCHER/main.py
2023-05-16 22:33:36 +02:00

112 lines
3.6 KiB
Python

from urllib.parse import unquote, quote
from scrapper import get_uri, get_files
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()
else:
path = '/'
while True:
database.set_last_path(path)
file = menu.files(get_url(site) + path)
if (file == None):
return
elif (file == "../" and path == "/"):
return
if (not file.endswith("/")):
player.play(get_url(site) + path + file, database)
else:
path = path + file
def add_site():
site = menu.add_site()
database.add_site(site)
def config_preview(site_name:str):
id = int(site_name.split(": ")[0])
site = database.get_site_by_id(id)
str = f"""
url: {site.get('url')}
user: {site.get('user')}
password: {site.get('password')}
"""
return (str)
def sites_deleter():
lst = []
for i in sites_table.all():
lst.append(f"{str(i.get('id'))}: {i.get('name')}")
terminal_menu = TerminalMenu(lst, show_search_hint=True, preview_title="delete", preview_command=config_preview)
choose = terminal_menu.show()
if (choose == None):
return (1)
site_name = lst[choose]
id = int(site_name.split(": ")[0])
sites_table.remove(query.id == id)
if (database.get_last_site() == id):
database.set_last_path("")
database.set_last_site("")
def sites_editor(site_id: int):
lst = []
for i in database.get_sites():
lst.append(f"{str(i.get('id'))}: {i.get('name')}")
terminal_menu = TerminalMenu(lst, show_search_hint=True, preview_title="delete", preview_command=config_preview)
choose = terminal_menu.show()
if (choose == None):
return (1)
site_name = lst[choose]
id = int(site_name.split(": ")[0])
site = database.get_site_by_id(id)
lst = [f"name: {site.get('name')}", f"url: {site.get('url')}", f"user: {site.get('user')}", f"password: {site.get('password')}"]
terminal_menu = TerminalMenu(lst)
choose = terminal_menu.show()
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)
def sites_navigator():
nb_site = database.get_sites_table_len()
if (nb_site == 0):
add_site()
nb_site = 1
last_site = database.get_last_site()
if (last_site != None):
files_navigator(last_site)
while True:
nb_site = database.get_sites_table_len()
terminal_menu = TerminalMenu(get(database.get_sites(), "name") + ["", "add", "edit", "delete"], skip_empty_entries=True, show_search_hint=True)
choose = terminal_menu.show()
if (choose == None):
return (1)
if (choose == nb_site + 1):
add_site();
elif (choose == nb_site + 2):
sites_editor()
elif (choose == nb_site + 3):
sites_deleter()
sites_navigator()
return
else:
set_url(database.get_sites()[choose])
files_navigator()
database = Database()
if (database.get_cookies_table_len() == 0):
database.add_cookies({"last_path": "", "last_site": "", "id": "0"})
sites_navigator();