sunnynazir commited on
Commit
85a2721
·
verified ·
1 Parent(s): 62a4e2c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -17
app.py CHANGED
@@ -1,21 +1,5 @@
1
  import streamlit as st
2
 
3
- try:
4
- from youtube_dlp import YoutubeDLPDownloader
5
- except ModuleNotFoundError:
6
- st.error("The 'youtube-dlp' library is not installed. Downloading will be unavailable.")
7
- YoutubeDLPDownloader = None # Set to None to avoid further errors
8
-
9
- # ... rest of your app code ...
10
-
11
- # Download functionality (use YoutubeDLPDownloader if available)
12
- if YoutubeDLPDownloader:
13
- # ... download logic using YoutubeDLPDownloader ...
14
- else:
15
- st.warning("Download functionality is disabled due to missing 'youtube-dlp' library.")
16
-
17
- from youtube_dlp import YoutubeDLPDownloader # Assuming yt-dlp is installed
18
-
19
  # Title and description for your app
20
  st.title("Youtube Video Downloader")
21
  st.write("Download your favorite Youtube videos here!")
@@ -40,4 +24,30 @@ if st.button("Download"):
40
 
41
  st.success(f"Video '{video_title}' downloaded successfully in {quality}!")
42
  except Exception as e:
43
- st.error(f"An error occurred: {e}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  # Title and description for your app
4
  st.title("Youtube Video Downloader")
5
  st.write("Download your favorite Youtube videos here!")
 
24
 
25
  st.success(f"Video '{video_title}' downloaded successfully in {quality}!")
26
  except Exception as e:
27
+ st.error(f"An error occurred: {e}")
28
+
29
+ import streamlit as st
30
+
31
+ try:
32
+ from youtube_dlp import YoutubeDLPDownloader
33
+ except ModuleNotFoundError:
34
+ st.error("The 'youtube-dlp' library is not installed. Downloading will be unavailable.")
35
+ YoutubeDLPDownloader = None # Set to None to avoid further errors
36
+
37
+ # ... rest of your app code ...
38
+
39
+ # Download functionality (use YoutubeDLPDownloader if available)
40
+ if YoutubeDLPDownloader:
41
+ try:
42
+ with YoutubeDLPDownloader({"format": f"bestvideo[height<={quality[:-1]}]+bestaudio/best[height<={quality[:-1]}]"}) as ydl:
43
+ info_dict = ydl.extract_info(url, download=False)
44
+ video_title = info_dict.get("title", "video")
45
+
46
+ # Download the video
47
+ ydl.download([url])
48
+
49
+ st.success(f"Video '{video_title}' downloaded successfully in {quality}!")
50
+ except Exception as e:
51
+ st.error(f"An error occurred: {e}")
52
+ else:
53
+ st.warning("Download functionality is disabled due to missing 'youtube-dlp' library.")