coollsd commited on
Commit
1fd4e83
·
verified ·
1 Parent(s): 0d5e387

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -9
app.py CHANGED
@@ -105,11 +105,15 @@ class MediaDownloader:
105
 
106
  return None
107
 
 
 
 
 
108
  @app.route('/')
109
  def home():
110
  return """
111
- <h1>downloader</h1>
112
- <p>Use: /download?url=url</p>
113
  """
114
 
115
  @app.route('/download')
@@ -117,7 +121,7 @@ def download():
117
  try:
118
  url = request.args.get('url')
119
  if not url:
120
- return "No URL", 400
121
 
122
  downloader = MediaDownloader()
123
 
@@ -126,14 +130,12 @@ def download():
126
 
127
  if files and len(files) > 0:
128
  if len(files) == 1:
129
- # Single file download
130
  response = make_response(send_file(files[0], as_attachment=True))
131
  @response.call_on_close
132
  def cleanup():
133
  downloader.cleanup()
134
  return response
135
  else:
136
- # Multiple files download
137
  def generate():
138
  for file_path in files:
139
  with open(file_path, 'rb') as f:
@@ -155,14 +157,15 @@ def download():
155
  return response
156
  else:
157
  downloader.cleanup()
158
- return "Failed", 400
159
 
160
  except Exception as e:
161
  downloader.cleanup()
162
- return f"Error: {str(e)}", 500
163
 
164
  except Exception as e:
165
- return f"Error: {str(e)}", 500
166
 
167
  if __name__ == '__main__':
168
- app.run(host='0.0.0.0', port=8080, debug=True)
 
 
105
 
106
  return None
107
 
108
+ @app.route('/health')
109
+ def health_check():
110
+ return 'OK', 200
111
+
112
  @app.route('/')
113
  def home():
114
  return """
115
+ <h1>Media Downloader</h1>
116
+ <p>Use: /download?url=your_url_here</p>
117
  """
118
 
119
  @app.route('/download')
 
121
  try:
122
  url = request.args.get('url')
123
  if not url:
124
+ return "No URL provided", 400
125
 
126
  downloader = MediaDownloader()
127
 
 
130
 
131
  if files and len(files) > 0:
132
  if len(files) == 1:
 
133
  response = make_response(send_file(files[0], as_attachment=True))
134
  @response.call_on_close
135
  def cleanup():
136
  downloader.cleanup()
137
  return response
138
  else:
 
139
  def generate():
140
  for file_path in files:
141
  with open(file_path, 'rb') as f:
 
157
  return response
158
  else:
159
  downloader.cleanup()
160
+ return "Download failed", 400
161
 
162
  except Exception as e:
163
  downloader.cleanup()
164
+ return f"Error during download: {str(e)}", 500
165
 
166
  except Exception as e:
167
+ return f"Server error: {str(e)}", 500
168
 
169
  if __name__ == '__main__':
170
+ # Development only
171
+ app.run(host='0.0.0.0', port=7860, debug=False)