VLC_HTTP_LAUNCHER/player.py

37 lines
1.2 KiB
Python
Raw Permalink Normal View History

2023-05-16 16:33:36 -04:00
from database import Database
2023-05-20 13:17:43 -04:00
import menu
import terminal_menu.Menu as terminal_menu
2023-05-16 17:25:05 -04:00
from time import sleep
import os, subprocess
2023-05-16 16:33:36 -04:00
2023-05-16 17:25:05 -04:00
def _play(url: str, database: Database):
2023-05-16 16:33:36 -04:00
start_pos = 0
viewing_data = database.get_viewing_data(url)
if (viewing_data != None):
2023-05-20 13:17:43 -04:00
response = menu.start_pos([f"go back to {str(viewing_data.get('last_pos'))}", "restart from 0:00"])
2023-05-16 16:33:36 -04:00
if (response == None):
return (1);
elif (response == 0):
start_pos = viewing_data.get("last_pos")
vlc_instance = vlc.Instance()
player = vlc_instance.media_player_new()
media = vlc_instance.media_new(url)
player.set_media(media)
player.play()
2023-05-16 17:25:05 -04:00
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):
viewing_data = database.get_viewing_data(url);
if (viewing_data == None):
viewing_data = {"url": url, "finished": True}
database.add_viewing_data(viewing_data);
2023-05-16 17:25:05 -04:00
with open(os.devnull, 'wb') as devnull:
subprocess.check_call(['vlc', url], stdout=devnull, stderr=subprocess.STDOUT)