MujtabaAli commited on
Commit
149dc47
·
verified ·
1 Parent(s): b16d552

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -0
app.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import yt_dlp
3
+ import os
4
+
5
+ def download_video(url, download_path):
6
+ ydl_opts = {
7
+ 'format': 'best', # Download the best quality by default
8
+ 'outtmpl': os.path.join(download_path, '%(title)s.%(ext)s'),
9
+ 'noplaylist': True, # Don't download playlists
10
+ }
11
+
12
+ with yt_dlp.YoutubeDL(ydl_opts) as ydl:
13
+ info_dict = ydl.extract_info(url, download=False)
14
+ formats = info_dict.get('formats', [])
15
+ best_quality = formats[0]
16
+ for f in formats:
17
+ if f['height'] > best_quality['height']:
18
+ best_quality = f
19
+ download_url = best_quality['url']
20
+ file_extension = best_quality['ext']
21
+
22
+ # Initiate the download
23
+ ydl_opts['format'] = best_quality['format_id']
24
+ ydl_opts['outtmpl'] = os.path.join(download_path, '%(title)s.' + file_extension)
25
+ ydl.download([url])
26
+
27
+ return f"Downloaded: {info_dict['title']}.{file_extension}"
28
+
29
+ # Streamlit App
30
+ st.title('Video Downloader')
31
+ st.write("Enter the video link to download it from YouTube, Facebook, Instagram, X (formerly Twitter), or Telegram.")
32
+
33
+ # User input
34
+ video_url = st.text_input("Video URL")
35
+ download_button = st.button("Download Video")
36
+
37
+ if download_button:
38
+ if video_url:
39
+ with st.spinner("Downloading..."):
40
+ result = download_video(video_url, os.path.expanduser("~") + '/Downloads')
41
+ st.success(result)
42
+ else:
43
+ st.error("Please enter a valid video URL.")