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 urllib.parse import unquote, quote
|
||||||
from scrapper import get_uri, get_files
|
from scrapper import get_uri, get_files
|
||||||
|
from urllib.parse import quote, unquote
|
||||||
import player
|
import player
|
||||||
from database import Database
|
from database import Database
|
||||||
from utils import get_url
|
from utils import get_url
|
||||||
@ -11,14 +12,15 @@ def files_navigator(site: dict):
|
|||||||
else:
|
else:
|
||||||
path = '/'
|
path = '/'
|
||||||
while True:
|
while True:
|
||||||
|
path = get_uri(get_url(site) + path)
|
||||||
database.set_last_path(path)
|
database.set_last_path(path)
|
||||||
file = menu.files(get_url(site) + path)
|
file = menu.files(site, path)
|
||||||
if (file == None):
|
if (file == None):
|
||||||
return
|
return
|
||||||
elif (file == "../" and path == "/"):
|
elif (file == "../" and path == "/"):
|
||||||
return
|
return
|
||||||
if (not file.endswith("/")):
|
if (not file.endswith("/")):
|
||||||
player.play(get_url(site) + path + file, database)
|
player.play(get_url(site) + quote(path + file), database)
|
||||||
else:
|
else:
|
||||||
path = path + file
|
path = path + file
|
||||||
|
|
||||||
|
18
menu.py
18
menu.py
@ -1,8 +1,10 @@
|
|||||||
from simple_term_menu import TerminalMenu
|
from simple_term_menu import TerminalMenu
|
||||||
from database import Database
|
from database import Database
|
||||||
from scrapper import get_files, get_uri
|
from scrapper import get_files, get_uri
|
||||||
|
from utils import get_url
|
||||||
|
|
||||||
url = ""
|
uri = ""
|
||||||
|
preview_site = {}
|
||||||
|
|
||||||
def add_site(database: Database) -> dict:
|
def add_site(database: Database) -> dict:
|
||||||
print("add a site:")
|
print("add a site:")
|
||||||
@ -20,19 +22,21 @@ def add_site(database: Database) -> dict:
|
|||||||
def files_preview(filename: str) -> str:
|
def files_preview(filename: str) -> str:
|
||||||
if (not filename.endswith("/")):
|
if (not filename.endswith("/")):
|
||||||
return (None)
|
return (None)
|
||||||
files = get_files(url + filename)
|
files = get_files(preview_site, uri + filename)
|
||||||
return ("\n".join(files))
|
return ("\n".join(files))
|
||||||
|
|
||||||
def files(base_url:str):
|
def files(site, path):
|
||||||
global url
|
global uri
|
||||||
|
global preview_site
|
||||||
|
|
||||||
url = base_url
|
uri = path
|
||||||
files = get_files(base_url)
|
preview_site = site
|
||||||
|
files = get_files(site, path)
|
||||||
terminal_menu = TerminalMenu(files,
|
terminal_menu = TerminalMenu(files,
|
||||||
preview_command=files_preview,
|
preview_command=files_preview,
|
||||||
preview_size=0.3,
|
preview_size=0.3,
|
||||||
show_search_hint=True,
|
show_search_hint=True,
|
||||||
title=f"Index of {get_uri(url)}")
|
title=f"Index of {path}")
|
||||||
choose = terminal_menu.show()
|
choose = terminal_menu.show()
|
||||||
return (files[choose])
|
return (files[choose])
|
||||||
|
|
||||||
|
17
player.py
17
player.py
@ -1,8 +1,9 @@
|
|||||||
from simple_term_menu import TerminalMenu
|
from simple_term_menu import TerminalMenu
|
||||||
import vlc
|
|
||||||
from database import Database
|
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
|
start_pos = 0
|
||||||
viewing_data = database.get_viewing_data(url)
|
viewing_data = database.get_viewing_data(url)
|
||||||
if (viewing_data != None):
|
if (viewing_data != None):
|
||||||
@ -17,3 +18,15 @@ def play(url: str, database: Database):
|
|||||||
media = vlc_instance.media_new(url)
|
media = vlc_instance.media_new(url)
|
||||||
player.set_media(media)
|
player.set_media(media)
|
||||||
player.play()
|
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 bs4 import BeautifulSoup
|
||||||
from urllib.parse import quote, unquote
|
from urllib.parse import quote, unquote
|
||||||
|
from utils import get_url
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
def get_files(url: str) -> []:
|
def get_files(site:dict, path:str) -> []:
|
||||||
|
url = get_url(site) + quote(path)
|
||||||
if (url in ["/../", "../"]):
|
if (url in ["/../", "../"]):
|
||||||
return ([])
|
return ([])
|
||||||
response = requests.get(url)
|
response = requests.get(url)
|
||||||
|
Loading…
Reference in New Issue
Block a user