diff --git a/main.py b/main.py index fda52ed..b4c04fa 100644 --- a/main.py +++ b/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 diff --git a/menu.py b/menu.py index d83c51e..4c4cb66 100644 --- a/menu.py +++ b/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]) diff --git a/player.py b/player.py index 8436c72..ca37ca2 100644 --- a/player.py +++ b/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) + diff --git a/scrapper.py b/scrapper.py index b666918..1977e3c 100644 --- a/scrapper.py +++ b/scrapper.py @@ -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)