mmty commited on
Commit
bb048ec
·
verified ·
1 Parent(s): 44d9a2d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -7
app.py CHANGED
@@ -1,9 +1,9 @@
1
  import streamlit as st
2
  from moviepy.editor import VideoFileClip
3
  import os
4
- import requests
5
  from io import BytesIO
6
  from tempfile import NamedTemporaryFile
 
7
 
8
  # Function to compress the video
9
  def compress_video(input_path, output_path, target_bitrate="500k"):
@@ -11,15 +11,21 @@ def compress_video(input_path, output_path, target_bitrate="500k"):
11
  video.write_videofile(output_path, bitrate=target_bitrate)
12
  return output_path
13
 
14
- # Function to download video from URL
15
  def download_video(url):
16
- response = requests.get(url, stream=True)
17
- if response.status_code == 200:
 
 
 
 
18
  video_data = BytesIO(response.content)
19
  return video_data
20
- else:
21
- st.error("Error downloading the video. Please check the URL.")
22
- return None
 
 
23
 
24
  st.title("Advanced Video Compressor")
25
 
 
1
  import streamlit as st
2
  from moviepy.editor import VideoFileClip
3
  import os
 
4
  from io import BytesIO
5
  from tempfile import NamedTemporaryFile
6
+ import requests
7
 
8
  # Function to compress the video
9
  def compress_video(input_path, output_path, target_bitrate="500k"):
 
11
  video.write_videofile(output_path, bitrate=target_bitrate)
12
  return output_path
13
 
14
+ # Function to download video from URL with enhanced error handling
15
  def download_video(url):
16
+ headers = {
17
+ "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36"
18
+ }
19
+ try:
20
+ response = requests.get(url, headers=headers, stream=True)
21
+ response.raise_for_status()
22
  video_data = BytesIO(response.content)
23
  return video_data
24
+ except requests.exceptions.HTTPError as http_err:
25
+ st.error(f"HTTP error occurred: {http_err}")
26
+ except Exception as err:
27
+ st.error(f"An error occurred: {err}")
28
+ return None
29
 
30
  st.title("Advanced Video Compressor")
31