-
Notifications
You must be signed in to change notification settings - Fork 1
/
SaveTheVideo.py
108 lines (90 loc) · 3.7 KB
/
SaveTheVideo.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import requests
import time
headers = {
'accept': 'application/json',
'accept-language': 'pl-PL,pl;q=0.6',
'content-type': 'application/json',
'origin': 'https://www.savethevideo.com',
'priority': 'u=1, i',
'referer': 'https://www.savethevideo.com/',
'sec-ch-ua': '"Chrome";v="129", "Not=A?Brand";v="8", "Chromium";v="129"',
'sec-ch-ua-mobile': '?0',
'sec-ch-ua-platform': '"Windows"',
'sec-fetch-dest': 'empty',
'sec-fetch-mode': 'cors',
'sec-fetch-site': 'same-site',
'sec-gpc': '1',
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36',
}
def send_request(url):
api_url = "https://api.v02.savethevideo.com/tasks"
payload = {"type": "info", "url": url}
response = requests.post(api_url, json=payload, headers=headers)
if response.status_code in [200, 202]:
data = response.json()
task_id = data.get('id')
task_href = data.get('href')
print(f"INFO: The task has been created successfully! ID: {task_id}")
state = data.get('state')
if state == 'completed':
print("SUCCESS: The task was already done. Viewing results....")
display_results(data)
else:
print("INFO: I am starting to monitore the task...")
monitor_task(task_href)
else:
print(f"ERROR: I don't recognize the response. Code: {response.status_code}")
print(response.text)
def monitor_task(task_href):
task_url = f"https://api.v02.savethevideo.com{task_href}"
while True:
response = requests.get(task_url, headers=headers)
if response.status_code == 200:
data = response.json()
state = data.get('state')
if state == 'completed':
print("SUCCESS: The task is done!")
display_results(data)
break
elif state == 'failed':
error_message = data.get('error', {}).get('message', 'Nieznany błąd')
print(f"ERROR: A error occured: {error_message}")
break
else:
print(f"INFO: State: {state} - Waiting....")
time.sleep(1)
else:
print(f"ERROR: There was an error while monitoring the task: {response.status_code}")
print(response.text)
break
def display_results(data):
result = data.get('result', [])
if not result:
print("ERROR: No results found for some reason.")
return
formats = result[0].get('formats', [])
video_with_audio_found = False
for fmt in formats:
if fmt.get('vcodec') != 'none' and fmt.get('acodec') != 'none' and fmt.get('ext') == 'mp4':
if not video_with_audio_found:
print("\nVideos with audio:\n")
video_with_audio_found = True
resolution = fmt.get('resolution', 'Unknown quality')
url = fmt['url']
print(f"{resolution}: {url}")
if not video_with_audio_found:
print("INFO: No videos with audio found. Searching for video without audio...\n")
for fmt in formats:
if fmt.get('vcodec') != 'none' and fmt.get('acodec') == 'none' and fmt.get('ext') == 'mp4':
resolution = fmt.get('resolution', 'Unknown quality')
url = fmt['url']
print(f"{resolution}: {url}")
def main():
url = input("URL: ")
print()
if url:
send_request(url)
else:
print("That is not a URL.")
if __name__ == "__main__":
main()