50 lines
1.5 KiB
Python
50 lines
1.5 KiB
Python
from tinydb import TinyDB, Query
|
|
from bs4 import BeautifulSoup
|
|
import requests
|
|
import os
|
|
from simple_term_menu import TerminalMenu
|
|
|
|
db = TinyDB("./database.json", indent=4)
|
|
query = Query()
|
|
|
|
sites = db.table("sites")
|
|
nb_sites = len(sites.all());
|
|
site_choose = 0;
|
|
if (nb_sites == 0):
|
|
print("add a site:")
|
|
site = {}
|
|
site.update({"url": input("url:")})
|
|
site.update({"user": input("user(leave blank):")})
|
|
site.update({"password": input("password(leave blank):")})
|
|
name = input("name[url] :")
|
|
if (name == ""):
|
|
name = site.get("url")
|
|
site.update({"name": name})
|
|
sites.insert(site)
|
|
elif (nb_sites != 1):
|
|
lst = []
|
|
for site in sites.all():
|
|
append(sites.get("name"))
|
|
terminal_menu = TerminalMenu(lst)
|
|
site_choose = terminal_menu.show()
|
|
site = sites.all()[site_choose]
|
|
if (site.get("user") and site.get("password")):
|
|
url = f"http://{site.get('user')}:{site.get('password')}@{site.get('url')}/"
|
|
else:
|
|
url = f"http://{site.get('url')}/";
|
|
while True:
|
|
response = requests.get(url)
|
|
print("connection:", response.reason)
|
|
if (response.status_code != 200):
|
|
exit
|
|
soup = BeautifulSoup(response.text, 'html.parser')
|
|
lst = []
|
|
for element in soup.findAll("a"):
|
|
lst.append(element.text)
|
|
terminal_menu = TerminalMenu(lst)
|
|
file = soup.findAll("a")[terminal_menu.show()]["href"]
|
|
url = url + file
|
|
if (not file.endswith("/")):
|
|
print(f"vlc '{url}'")
|
|
os.system(f"vlc '{url}'")
|