Spaces:
Sleeping
Sleeping
Matias Macias Gomez commited on
Commit ·
8cd0c04
1
Parent(s): b6ca10f
Update. Improved functionality
Browse files- .gitignore +1 -0
- streamlit_app.py +21 -12
.gitignore
CHANGED
|
@@ -33,5 +33,6 @@ ENV/
|
|
| 33 |
.ipynb_checkpoints/
|
| 34 |
|
| 35 |
data/*.mp4
|
|
|
|
| 36 |
|
| 37 |
.idea
|
|
|
|
| 33 |
.ipynb_checkpoints/
|
| 34 |
|
| 35 |
data/*.mp4
|
| 36 |
+
data/*.webm
|
| 37 |
|
| 38 |
.idea
|
streamlit_app.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
import os
|
|
|
|
| 2 |
import yt_dlp
|
| 3 |
import string
|
| 4 |
import streamlit as st
|
|
@@ -12,14 +13,13 @@ if "downloaded" not in st.session_state:
|
|
| 12 |
st.session_state["downloaded"] = []
|
| 13 |
|
| 14 |
def download_video(url:str, save_path:str , download:bool, **kwargs):
|
|
|
|
| 15 |
ydl_opts = {
|
| 16 |
-
'outtmpl': f'{save_path}/
|
| 17 |
}
|
| 18 |
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
| 19 |
info_dict = ydl.extract_info(url, download=download)
|
| 20 |
-
|
| 21 |
-
video_title = f"{video_title}"
|
| 22 |
-
return video_title
|
| 23 |
|
| 24 |
|
| 25 |
st.title("Download Any Video")
|
|
@@ -35,11 +35,20 @@ if st.session_state["url"]:
|
|
| 35 |
st.session_state["downloaded"].append(st.session_state["url"])
|
| 36 |
|
| 37 |
if st.session_state["videos"]:
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
+
from glob import glob
|
| 3 |
import yt_dlp
|
| 4 |
import string
|
| 5 |
import streamlit as st
|
|
|
|
| 13 |
st.session_state["downloaded"] = []
|
| 14 |
|
| 15 |
def download_video(url:str, save_path:str , download:bool, **kwargs):
|
| 16 |
+
video_id =url.split("/")[-1]
|
| 17 |
ydl_opts = {
|
| 18 |
+
'outtmpl': f'{save_path}/{video_id}.%(ext)s',
|
| 19 |
}
|
| 20 |
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
| 21 |
info_dict = ydl.extract_info(url, download=download)
|
| 22 |
+
return video_id
|
|
|
|
|
|
|
| 23 |
|
| 24 |
|
| 25 |
st.title("Download Any Video")
|
|
|
|
| 35 |
st.session_state["downloaded"].append(st.session_state["url"])
|
| 36 |
|
| 37 |
if st.session_state["videos"]:
|
| 38 |
+
|
| 39 |
+
videos = glob(os.path.join(".", "data", "*.mp4")) \
|
| 40 |
+
+ glob(os.path.join(".", "data", "*.webm")) \
|
| 41 |
+
+ glob(os.path.join(".", "data", "*.mov")) \
|
| 42 |
+
+ glob(os.path.join(".", "data", "*.m4a"))
|
| 43 |
+
print("videos found:", videos)
|
| 44 |
+
for video in videos:
|
| 45 |
+
if st.session_state["videos"] in video:
|
| 46 |
+
st.write("**Title**:", st.session_state["videos"])
|
| 47 |
+
st.video(video)
|
| 48 |
+
video_file = open(video, "rb")
|
| 49 |
+
st.download_button("**Download Video 📁**",
|
| 50 |
+
data=video_file,
|
| 51 |
+
file_name=f"{st.session_state['videos'].lower().translate(str.maketrans('','', string.punctuation)).replace(' ', '_')}.mp4",
|
| 52 |
+
mime="video/mp4",
|
| 53 |
+
type="primary")
|
| 54 |
+
break
|