-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathjerrydiscordpresence.py
executable file
·94 lines (77 loc) · 2.25 KB
/
jerrydiscordpresence.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/env python3
import subprocess
import sys
import re
import os
import httpx
from pypresence import Presence
CLIENT_ID = "1084791136981352558"
ENDPONT = "https://kitsu.io/api/"
rpc_client = Presence(CLIENT_ID)
rpc_client.connect()
http_client = httpx.Client(base_url=ENDPONT)
(
_,
mpv_executable,
anime_name,
release_year,
episode_count,
content_stream,
subtitle_stream,
*opts,
) = sys.argv
anime = http_client.get("edge/anime", params={"filter[text]": anime_name, "filter[year]": f"{release_year}..{release_year}"}).json()[
"data"
]
if not anime:
raise SystemExit()
media = anime[0]["attributes"]
media_title = "%s %s" % (media["canonicalTitle"], "- Episode "+episode_count)
if subtitle_stream != "":
args = [
mpv_executable,
content_stream,
f"--force-media-title={media_title}",
f"--sub-files={subtitle_stream}",
"--msg-level=ffmpeg/demuxer=error",
] + opts
else:
args = [
mpv_executable,
content_stream,
f"--force-media-title={media_title}",
"--msg-level=ffmpeg/demuxer=error",
] + opts
process = subprocess.Popen(
args
)
if sys.platform == 'win32':
file_path = os.path.join(os.environ['LocalAppData'], 'Temp', 'jerry_position')
else:
file_path = '/tmp/jerry_position'
while True:
with open(file_path, 'r') as file:
content = file.read()
pattern = r'(\(Paused\)\s)?AV:\s([0-9:]*) / ([0-9:]*) \(([0-9]*)%\)'
matches = re.findall(pattern, content)
small_image = "https://images-ext-1.discordapp.net/external/dUSRf56flwFeOMFjafsUhIMMS_1Xs-ptjeDHo6TWn6c/%3Fquality%3Dlossless%26size%3D48/https/cdn.discordapp.com/emojis/1138835294506975262.png"
if matches:
if matches[-1][0] == "(Paused) ":
elapsed = matches[-1][1]
else:
elapsed = matches[-1][1]
duration = matches[-1][2]
position = f"{elapsed} / {duration}"
else:
position = "00:00:00"
rpc_client.update(
details=media_title,
state=position,
large_image=media["posterImage"]["original"],
large_text=media_title,
small_image=small_image,
small_text=f"Episode {episode_count}"
)
if process.poll() is not None:
break
process.wait()