fix: and clean
This commit is contained in:
parent
42c3f6b37d
commit
d39e9cfb62
6
main.py
6
main.py
@ -1,5 +1,6 @@
|
||||
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
|
||||
@ -11,14 +12,15 @@ def files_navigator(site: dict):
|
||||
else:
|
||||
path = '/'
|
||||
while True:
|
||||
path = get_uri(get_url(site) + path)
|
||||
database.set_last_path(path)
|
||||
file = menu.files(get_url(site) + path)
|
||||
file = menu.files(site, path)
|
||||
if (file == None):
|
||||
return
|
||||
elif (file == "../" and path == "/"):
|
||||
return
|
||||
if (not file.endswith("/")):
|
||||
player.play(get_url(site) + path + file, database)
|
||||
player.play(get_url(site) + quote(path + file), database)
|
||||
else:
|
||||
path = path + file
|
||||
|
||||
|
18
menu.py
18
menu.py
@ -1,8 +1,10 @@
|
||||
from simple_term_menu import TerminalMenu
|
||||
from database import Database
|
||||
from scrapper import get_files, get_uri
|
||||
from utils import get_url
|
||||
|
||||
url = ""
|
||||
uri = ""
|
||||
preview_site = {}
|
||||
|
||||
def add_site(database: Database) -> dict:
|
||||
print("add a site:")
|
||||
@ -20,19 +22,21 @@ def add_site(database: Database) -> dict:
|
||||
def files_preview(filename: str) -> str:
|
||||
if (not filename.endswith("/")):
|
||||
return (None)
|
||||
files = get_files(url + filename)
|
||||
files = get_files(preview_site, uri + filename)
|
||||
return ("\n".join(files))
|
||||
|
||||
def files(base_url:str):
|
||||
global url
|
||||
def files(site, path):
|
||||
global uri
|
||||
global preview_site
|
||||
|
||||
url = base_url
|
||||
files = get_files(base_url)
|
||||
uri = path
|
||||
preview_site = site
|
||||
files = get_files(site, path)
|
||||
terminal_menu = TerminalMenu(files,
|
||||
preview_command=files_preview,
|
||||
preview_size=0.3,
|
||||
show_search_hint=True,
|
||||
title=f"Index of {get_uri(url)}")
|
||||
title=f"Index of {path}")
|
||||
choose = terminal_menu.show()
|
||||
return (files[choose])
|
||||
|
||||
|
17
player.py
17
player.py
@ -1,8 +1,9 @@
|
||||
from simple_term_menu import TerminalMenu
|
||||
import vlc
|
||||
from database import Database
|
||||
from time import sleep
|
||||
import os, subprocess
|
||||
|
||||
def play(url: str, database: Database):
|
||||
def _play(url: str, database: Database):
|
||||
start_pos = 0
|
||||
viewing_data = database.get_viewing_data(url)
|
||||
if (viewing_data != None):
|
||||
@ -17,3 +18,15 @@ def play(url: str, database: Database):
|
||||
media = vlc_instance.media_new(url)
|
||||
player.set_media(media)
|
||||
player.play()
|
||||
sleep(1)
|
||||
player.video_set_mouse_input(True)
|
||||
player.set_position(start_pos / player.get_length())
|
||||
player.set_fullscreen(True)
|
||||
while True:
|
||||
print("duration:", player.get_time(),":",player.get_length())
|
||||
|
||||
|
||||
def play(url: str, database: Database):
|
||||
with open(os.devnull, 'wb') as devnull:
|
||||
subprocess.check_call(['vlc', url], stdout=devnull, stderr=subprocess.STDOUT)
|
||||
|
||||
|
@ -1,8 +1,10 @@
|
||||
from bs4 import BeautifulSoup
|
||||
from urllib.parse import quote, unquote
|
||||
from utils import get_url
|
||||
import requests
|
||||
|
||||
def get_files(url: str) -> []:
|
||||
def get_files(site:dict, path:str) -> []:
|
||||
url = get_url(site) + quote(path)
|
||||
if (url in ["/../", "../"]):
|
||||
return ([])
|
||||
response = requests.get(url)
|
||||
|
Loading…
Reference in New Issue
Block a user