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
| import requests
url = "https://multi-format-ai-translator-the-most-complete.p.rapidapi.com/translator/translate/ass"
querystring = {
"source": "auto",
"target": "es"
}
payload = """[Script Info]
Title: Example Subtitles
ScriptType: v4.00+
[V4+ Styles]
Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding
Style: Default,Arial,20,&H00FFFFFF,&H000000FF,&H00000000,&H00000000,0,0,0,0,100,100,0,0,1,2,2,2,10,10,10,1
[Events]
Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text
Dialogue: 0,0:00:01.00,0:00:04.00,Default,,0,0,0,,Welcome to the world of subtitles.
Dialogue: 0,0:00:04.50,0:00:08.00,Default,,0,0,0,,This format supports advanced styling and effects.
Dialogue: 0,0:00:08.50,0:00:12.00,Default,,0,0,0,,Let's see how translation preserves everything."""
headers = {
"Content-Type": "text/plain",
"X-RapidAPI-Key": "YOUR_API_KEY",
"X-RapidAPI-Host": "multi-format-ai-translator-the-most-complete.p.rapidapi.com"
}
response = requests.post(url, headers=headers, params=querystring, data=payload)
data = response.json()
# Save the translated subtitles to a file
with open("subtitles_es.ass", "w", encoding="utf-8") as f:
f.write(data["data"]["translated_ass"])
print("ASS subtitles translated and saved.")
|