-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_ngrok_api.py
More file actions
executable file
Β·130 lines (112 loc) Β· 4.05 KB
/
test_ngrok_api.py
File metadata and controls
executable file
Β·130 lines (112 loc) Β· 4.05 KB
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/usr/bin/env python3
"""
Test ShortsCreator API via ngrok tunnel
"""
import requests
import json
import sys
def get_ngrok_url():
"""Get the current ngrok public URL"""
try:
response = requests.get('http://localhost:4040/api/tunnels')
data = response.json()
if data['tunnels']:
return data['tunnels'][0]['public_url']
else:
return None
except Exception:
return None
def test_health(base_url):
"""Test the health endpoint"""
print("π₯ Testing health endpoint...")
try:
response = requests.get(f"{base_url}/health")
if response.status_code == 200:
data = response.json()
print(f"β
Health check passed: {data['status']}")
return True
else:
print(f"β Health check failed: {response.status_code}")
return False
except Exception as e:
print(f"β Health check error: {str(e)}")
return False
def test_split_video(base_url):
"""Test the split video endpoint"""
print("\nβοΈ Testing split video endpoint...")
data = {
"url": "https://sample-videos.com/zip/10/mp4/SampleVideo_1280x720_1mb.mp4",
"start_time": 1.0,
"end_time": 5.0
}
try:
response = requests.post(f"{base_url}/split-video", json=data)
if response.status_code == 200:
result = response.json()
print(f"β
Split video job created: {result['job_id']}")
return result['job_id']
else:
print(f"β Split video failed: {response.status_code} - {response.text}")
return None
except Exception as e:
print(f"β Split video error: {str(e)}")
return None
def check_job_status(base_url, job_id):
"""Check job status"""
print(f"\nπ Checking job status: {job_id}")
try:
response = requests.get(f"{base_url}/job-status/{job_id}")
if response.status_code == 200:
result = response.json()
status = result['status']
print(f"π Job Status: {status}")
print(f"π Progress: {result.get('progress', 0)}%")
if status == 'completed':
print("β
Job completed successfully!")
if result.get('output_path'):
print(f"π Output file: {result['output_path']}")
return True
elif status == 'failed':
print(f"β Job failed: {result.get('error', 'Unknown error')}")
return False
else:
print(f"β³ Job still {status}...")
return None
else:
print(f"β Status check failed: {response.status_code}")
return False
except Exception as e:
print(f"β Status check error: {str(e)}")
return False
def main():
"""Main test function"""
print("π§ͺ ShortsCreator ngrok API Test")
print("=" * 40)
# Get ngrok URL
ngrok_url = get_ngrok_url()
if not ngrok_url:
print("β Could not get ngrok URL. Make sure ngrok is running:")
print(" ./setup_ngrok.sh")
sys.exit(1)
print(f"π Testing API at: {ngrok_url}")
# Test health
if not test_health(ngrok_url):
print("\nβ Health check failed. API may not be accessible.")
sys.exit(1)
# Test split video (fastest operation)
job_id = test_split_video(ngrok_url)
if not job_id:
print("\nβ Could not create test job.")
sys.exit(1)
# Check initial status
check_job_status(ngrok_url, job_id)
print(f"\nπ Basic ngrok API test completed!")
print(f"π Your API is accessible at: {ngrok_url}")
print(f"π Job ID for monitoring: {job_id}")
print(f"π Check status: {ngrok_url}/job-status/{job_id}")
print(f"β¬οΈ Download when done: {ngrok_url}/download/{job_id}")
print(f"\nπ Example API calls:")
print(f"curl {ngrok_url}/health")
print(f"curl {ngrok_url}/job-status/{job_id}")
if __name__ == "__main__":
main()