From 80481868db40ae36b2e21a3516255ae4849b9d4c Mon Sep 17 00:00:00 2001 From: starnakin Date: Wed, 31 May 2023 15:28:47 +0200 Subject: [PATCH] add: file already view is now in light grey --- database.py | 6 ++++++ main.py | 6 +++--- menu.py | 27 ++++++++++++++++++++++++--- player.py | 5 +++++ scrapper.py | 8 ++++++-- utils.py | 2 +- 6 files changed, 45 insertions(+), 9 deletions(-) diff --git a/database.py b/database.py index d0f68af..998753b 100644 --- a/database.py +++ b/database.py @@ -11,6 +11,12 @@ class Database(): def get_viewing_data(self, url:str ): return (self.viewing_table.get(self.query.url == url)) + + def set_viewing_data(self, url:str, viewing_data: dict): + self.viewing_table.update(set(url, value), self.query.url == url) + + def add_viewing_data(self, viewing_data): + self.viewing_table.insert(viewing_data) def get_sites(self): return (self.sites_table.all()) diff --git a/main.py b/main.py index 368dcbf..121952f 100644 --- a/main.py +++ b/main.py @@ -3,7 +3,7 @@ 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 utils import menu def files_navigator(site: dict): @@ -14,7 +14,7 @@ def files_navigator(site: dict): database.set_last_site(site.get("id")) while True: pos = database.get_last_cursor_pos() - path = get_uri(get_url(site) + path) + path = get_uri(utils.get_base_url(site) + path) database.set_last_path(path) file = menu.files(site, path, database, pos) if (file == None): @@ -22,7 +22,7 @@ def files_navigator(site: dict): elif (file == "../" and path == "/"): return if (not file.endswith("/")): - player.play(get_url(site) + quote(path + file), database) + player.play(utils.get_base_url(site) + quote(path + file), database) else: path = path + file diff --git a/menu.py b/menu.py index 7a5e607..21fa774 100644 --- a/menu.py +++ b/menu.py @@ -1,7 +1,10 @@ from database import Database -from scrapper import get_files, get_uri -from utils import get_url, get +from scrapper import get_files, get_uri, get_url +import utils +from utils import get import platform +import urllib +import colorama from terminal_menu.Menu import Menu @@ -33,14 +36,32 @@ def files_preview(filename: str) -> str: files = get_files(preview_site, uri + filename) return ("\n".join(files)) +def get_files_formated_by_viewing_data(database: Database, files: list, site: dict, path: str): + out = [] + current_url = utils.get_base_url(site) + urllib.parse.quote(path); + for file in files: + if file == "..": + out.append(file); + continue + url = current_url + urllib.parse.quote(file) + print (url) + viewing_data = database.get_viewing_data(url); + if (viewing_data == None) or (viewing_data.get("finished") == False): + out.append(colorama.Style.BRIGHT + file + colorama.Style.RESET_ALL) + else: + out.append(colorama.Fore.LIGHTBLACK_EX + file + colorama.Style.RESET_ALL); + return (out); + def files(site:dict, path:str, database:Database, pos:int): global uri global preview_site uri = path preview_site = site + current_url = get_url(site, path); files = get_files(site, path) - choose = get_user_choice_by_menu(files, + files_displayed = get_files_formated_by_viewing_data(database, files, site, path) + choose = get_user_choice_by_menu(files_displayed, preview_command=files_preview, preview_size=0.3, show_search_hint=True, diff --git a/player.py b/player.py index 77f26bc..ee53471 100644 --- a/player.py +++ b/player.py @@ -1,5 +1,6 @@ from database import Database import menu +import terminal_menu.Menu as terminal_menu from time import sleep import os, subprocess @@ -26,6 +27,10 @@ def _play(url: str, database: Database): def play(url: str, database: Database): + viewing_data = database.get_viewing_data(url); + if (viewing_data == None): + viewing_data = {"url": url, "finished": True} + database.add_viewing_data(viewing_data); 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 1977e3c..04e1fe9 100644 --- a/scrapper.py +++ b/scrapper.py @@ -1,10 +1,14 @@ from bs4 import BeautifulSoup from urllib.parse import quote, unquote -from utils import get_url +import utils import requests +def get_url(site: dict, path: str): + url = utils.get_base_url(site) + quote(path) + return (url) + def get_files(site:dict, path:str) -> []: - url = get_url(site) + quote(path) + url = get_url(site, path) if (url in ["/../", "../"]): return ([]) response = requests.get(url) diff --git a/utils.py b/utils.py index 95fc8fe..95caeee 100644 --- a/utils.py +++ b/utils.py @@ -1,5 +1,5 @@ -def get_url(site: dict): +def get_base_url(site: dict): if (site.get("user") == "" and site.get("password") == ""): return (f"http://{site.get('url')}") else: