VLC_HTTP_LAUNCHER/main.py

111 lines
3.5 KiB
Python

from urllib.parse import unquote, quote
from scrapper import get_uri, get_files
from urllib.parse import quote, unquote
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 = '/'
database.set_last_site(site.get("id"))
while True:
pos = database.get_last_cursor_pos()
path = get_uri(get_url(site) + path)
database.set_last_path(path)
file = menu.files(site, path, database, pos)
if (file == None):
return
elif (file == "../" and path == "/"):
return
if (not file.endswith("/")):
player.play(get_url(site) + quote(path + file), database)
else:
path = path + file
def add_site(database: Database):
site = menu.add_site(database)
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(database: Database):
lst = []
for i in database.get_sites():
lst.append(f"{str(i.get('id'))}: {i.get('name')}")
choose = menu.site_deleter(lst, database)
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(database: Database):
lst = []
for i in database.get_sites():
lst.append(f"{str(i.get('id'))}: {i.get('name')}")
choose = menu.site_editor(lst, database)
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')}"]
choose = menu.param_editor(lst)
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(database: Database):
nb_site = database.get_sites_table_len()
if (nb_site == 0):
add_site(database)
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()
choose = menu.sites(database.get_sites())
if (choose == None):
return (1)
if (choose == nb_site + 1):
add_site(database);
elif (choose == nb_site + 2):
sites_editor(database)
elif (choose == nb_site + 3):
sites_deleter(database)
sites_navigator(database)
return
else:
files_navigator(database.get_sites()[choose])
database = Database()
if (database.get_cookies_table_len() == 0):
database.add_cookies({"last_path": "", "last_site": "", "last_cursor_pos": 0, "id": "0"})
sites_navigator(database);