-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.py
More file actions
106 lines (94 loc) · 3.81 KB
/
Copy pathapi.py
File metadata and controls
106 lines (94 loc) · 3.81 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
from flask import Flask, request, jsonify, render_template
import requests
from datetime import datetime
app = Flask(__name__)
@app.route("/")
def home():
return render_template("status.html")
@app.route("/dl", methods=["GET"])
def download_video():
thread_url = request.args.get("url")
if not thread_url:
return jsonify({
"success": False,
"error": "Missing 'url' parameter",
"api_owner": "@ISmartCoder",
"updates_channel": "@TheSmartDev",
"timestamp": datetime.now().isoformat(),
"message": "Please provide a valid Threads URL"
}), 400
api_url = "https://api.threadsphotodownloader.com/v2/media"
params = {"url": thread_url}
try:
response = requests.get(api_url, params=params, timeout=30)
if response.status_code == 200:
data = response.json()
videos = data.get("video_urls", [])
if videos:
return jsonify({
"success": True,
"video_url": videos[0]["download_url"],
"video_quality": videos[0].get("quality", "HD"),
"file_size": videos[0].get("file_size", "Unknown"),
"api_owner": "@ISmartCoder",
"updates_channel": "@TheSmartDev",
"timestamp": datetime.now().isoformat(),
"message": "Video downloaded successfully",
"total_videos_found": len(videos),
"server_response_time": f"{response.elapsed.total_seconds():.2f}s"
})
else:
return jsonify({
"success": False,
"error": "No video found in post",
"api_owner": "@ISmartCoder",
"updates_channel": "@TheSmartDev",
"timestamp": datetime.now().isoformat(),
"message": "The provided URL doesn't contain any downloadable videos"
}), 404
else:
return jsonify({
"success": False,
"error": "External API Error",
"status_code": response.status_code,
"api_owner": "@ISmartCoder",
"updates_channel": "@TheSmartDev",
"timestamp": datetime.now().isoformat(),
"message": "Failed to fetch video from external service"
}), 500
except requests.exceptions.Timeout:
return jsonify({
"success": False,
"error": "Request timeout",
"api_owner": "@ISmartCoder",
"updates_channel": "@TheSmartDev",
"timestamp": datetime.now().isoformat(),
"message": "The request took too long to process"
}), 408
except Exception as e:
return jsonify({
"success": False,
"error": str(e),
"api_owner": "@ISmartCoder",
"updates_channel": "@TheSmartDev",
"timestamp": datetime.now().isoformat(),
"message": "An unexpected error occurred"
}), 500
@app.route("/status", methods=["GET"])
def api_status():
return jsonify({
"api_status": "online",
"version": "v1.0",
"uptime": "99.9%",
"api_owner": "@ISmartCoder",
"updates_channel": "@TheSmartDev",
"timestamp": datetime.now().isoformat(),
"endpoints": {
"/": "Status page",
"/dl": "Download video",
"/status": "API status"
},
"message": "Threads Video Downloader API is running smoothly"
})
if __name__ == "__main__":
app.run(host="0.0.0.0", port=5000, debug=True)