Commit 643e6f72f6

643e6f72f65aa989fef1a32752ffdb5acb380dc4

parent: 5d7f5e9617

Unsigned

Wraient <wraient.911@gmail.com> · 2024-08-25 20:57 UTC

another process mpv

Layout: unified · split

start_video.py +8 −39
@@ -1,45 +1,14 @@
11import os
22import json
33import socket
4import random
4import subprocess
55
6def start_video(link):
7 salt = random.randint(0,500)
8 os.system(f"mpv --input-ipc-server=/tmp/mpvsocket{salt} {link}")
6def 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()
910 # Path to the MPV socket
10 socket_path = f'/tmp/mpvsocket{salt}'
11
11 # socket_path = f'/tmp/mpvsocket{salt}'
1212 # Connect to the MPV IPC socket
13 client = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
14 client.connect(socket_path)
15
16
17def 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
23def 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
29def pause():
30 """Pause the playback."""
31 command = {"command": ["set_property", "pause", True]}
32 send_command(command)
33
34def play():
35 """Resume the playback."""
36 command = {"command": ["set_property", "pause", False]}
37 send_command(command)
38
39def 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)