coollsd commited on
Commit
9714a9a
·
verified ·
1 Parent(s): 0917beb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -5
app.py CHANGED
@@ -28,7 +28,7 @@ class MediaDownloader:
28
 
29
  def download_video(self, url):
30
  unique_id = str(uuid.uuid4())
31
- output_template = os.path.join(self.video_path, f'{unique_id}_%(title)s.%(ext)s')
32
  ydl_opts = {
33
  'format': 'best',
34
  'outtmpl': output_template,
@@ -75,11 +75,11 @@ class MediaDownloader:
75
  })
76
  response.raise_for_status()
77
 
78
- timestamp = datetime.now().strftime("%Y%m%d_%H%M%S_%f")
79
  ext = os.path.splitext(urlparse(img_url).path)[1]
80
  if not ext:
81
  ext = '.jpg'
82
- filename = f"image_{timestamp}{ext}"
83
  filepath = os.path.join(self.image_path, filename)
84
 
85
  with open(filepath, 'wb') as f:
@@ -143,7 +143,7 @@ def download():
143
  with open(file_path, 'rb') as f:
144
  content = f.read()
145
  filename = os.path.basename(file_path)
146
- yield f'Content-Disposition: attachment; filename=\n'.encode()
147
  yield f'Content-Type: {mimetypes.guess_type(file_path)[0]}\n'.encode()
148
  yield f'Content-Length: {len(content)}\n\n'.encode()
149
  yield content
@@ -169,5 +169,4 @@ def download():
169
  return f"Server error: {str(e)}", 500
170
 
171
  if __name__ == '__main__':
172
- # Development only
173
  app.run(host='0.0.0.0', port=7860, debug=False)
 
28
 
29
  def download_video(self, url):
30
  unique_id = str(uuid.uuid4())
31
+ output_template = os.path.join(self.video_path, f'{unique_id}.%(ext)s')
32
  ydl_opts = {
33
  'format': 'best',
34
  'outtmpl': output_template,
 
75
  })
76
  response.raise_for_status()
77
 
78
+ unique_id = str(uuid.uuid4())
79
  ext = os.path.splitext(urlparse(img_url).path)[1]
80
  if not ext:
81
  ext = '.jpg'
82
+ filename = f"{unique_id}{ext}"
83
  filepath = os.path.join(self.image_path, filename)
84
 
85
  with open(filepath, 'wb') as f:
 
143
  with open(file_path, 'rb') as f:
144
  content = f.read()
145
  filename = os.path.basename(file_path)
146
+ yield f'Content-Disposition: attachment; filename="{filename}"\n'.encode()
147
  yield f'Content-Type: {mimetypes.guess_type(file_path)[0]}\n'.encode()
148
  yield f'Content-Length: {len(content)}\n\n'.encode()
149
  yield content
 
169
  return f"Server error: {str(e)}", 500
170
 
171
  if __name__ == '__main__':
 
172
  app.run(host='0.0.0.0', port=7860, debug=False)