Commit 643e6f72f6
Unsigned
Layout: unified · split
start_video.py +8 −39
| @@ -1,45 +1,14 @@ | ||
| 1 | 1 | import os |
| 2 | 2 | import json |
| 3 | 3 | import socket |
| 4 | import random | |
| 4 | import subprocess | |
| 5 | 5 | |
| 6 | def start_video(link): | |
| 7 | salt = random.randint(0,500) | |
| 8 | os.system(f"mpv --input-ipc-server=/tmp/mpvsocket{salt} {link}") | |
| 6 | def start_video(link, salt): | |
| 7 | # print(f"SALT IS {salt}") | |
| 8 | subprocess.Popen(['alacritty', '-e', 'bash', '-c', f"mpv --input-ipc-server=/tmp/mpvsocket{salt} {link}"]) | |
| 9 | # os.system() | |
| 9 | 10 | # Path to the MPV socket |
| 10 | socket_path = f'/tmp/mpvsocket{salt}' | |
| 11 | ||
| 11 | # socket_path = f'/tmp/mpvsocket{salt}' | |
| 12 | 12 | # Connect to the MPV IPC socket |
| 13 | client = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) | |
| 14 | client.connect(socket_path) | |
| 15 | ||
| 16 | ||
| 17 | def send_command(command): | |
| 18 | """Send a command to MPV and return the response.""" | |
| 19 | client.send((json.dumps(command) + '\n').encode('utf-8')) | |
| 20 | response = client.recv(1024) | |
| 21 | return json.loads(response.decode('utf-8')) | |
| 22 | ||
| 23 | def get_time_pos(): | |
| 24 | """Get the current playback time position.""" | |
| 25 | command = {"command": ["get_property", "time-pos"]} | |
| 26 | response = send_command(command) | |
| 27 | return response.get('data', 0) | |
| 28 | ||
| 29 | def pause(): | |
| 30 | """Pause the playback.""" | |
| 31 | command = {"command": ["set_property", "pause", True]} | |
| 32 | send_command(command) | |
| 33 | ||
| 34 | def play(): | |
| 35 | """Resume the playback.""" | |
| 36 | command = {"command": ["set_property", "pause", False]} | |
| 37 | send_command(command) | |
| 38 | ||
| 39 | def stop(): | |
| 40 | """Stop the playback.""" | |
| 41 | command = {"command": ["quit"]} | |
| 42 | send_command(command) | |
| 43 | ||
| 44 | # def get_data(): | |
| 45 | ||
| 13 | # client = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) | |
| 14 | # client.connect(socket_path) | |