-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
70 lines (49 loc) · 2.05 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import streamlit as st
import yt_dlp
from yt_dlp import YoutubeDL
st.set_page_config(page_title='YouTube Downloader')
@st.cache #_data
def download_video_from_url(url):
videoinfo = YoutubeDL().extract_info(url=url, download=False)
filename = f"./youtube/{videoinfo['id']}.mp4"
options = {
'format': 'best', # Use 'best' to download both video and audio
'keepvideo': True,
'outtmpl': filename,
}
with YoutubeDL(options) as ydl:
ydl.download([videoinfo['webpage_url']])
return filename
@st.cache #_data
def download_audio_from_url(url):
videoinfo = YoutubeDL().extract_info(url=url, download=False)
filename = f"./youtube/{videoinfo['id']}.mp3"
options = {
'format': 'bestaudio/best', # Download the best audio
'keepvideo': False, # Don't keep the video
'outtmpl': filename,
'postprocessors': [{
'key': 'FFmpegExtractAudio',
'preferredcodec': 'mp3', # Convert to MP3
'preferredquality': '192', # Audio quality
}],
}
with YoutubeDL(options) as ydl:
ydl.download([videoinfo['webpage_url']])
return filename
st.title("Supersimple YouTube Downloader")
st.info("Kopiere den Link rein der bei Share angegeben wird ")
url = st.text_input('Url reinkopieren:', '')
if url !="":
filename_video = download_video_from_url(url)
st.video(filename_video)
with open(filename_video, "rb") as f:
st.download_button("Download Video", data=f, file_name="YT_video.mp4")
_="""
# Add an option to download the audio -
Please install or provide the path using --ffmpeg-location," indicates that the yt-dlp library requires FFmpeg to be installed and properly configured in your system.
if st.button("Download Audio (MP3)"):
filename_audio = download_audio_from_url(url)
with open(filename_audio, "rb") as f:
st.download_button("Download Audio (MP3)", data=f, file_name="audio.mp3")
"""