37 lines
1.2 KiB
Python
37 lines
1.2 KiB
Python
from database import Database
|
|
import menu
|
|
import terminal_menu.Menu as terminal_menu
|
|
from time import sleep
|
|
import os, subprocess
|
|
|
|
def _play(url: str, database: Database):
|
|
start_pos = 0
|
|
viewing_data = database.get_viewing_data(url)
|
|
if (viewing_data != None):
|
|
response = menu.start_pos([f"go back to {str(viewing_data.get('last_pos'))}", "restart from 0: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()
|
|
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);
|
|
with open(os.devnull, 'wb') as devnull:
|
|
subprocess.check_call(['vlc', url], stdout=devnull, stderr=subprocess.STDOUT)
|
|
|