Matias Macias Gomez commited on
Commit
0b76276
Β·
1 Parent(s): 95b1fe5

update yt-dlp added video cleanup option

Browse files
Files changed (2) hide show
  1. requirements.txt +1 -1
  2. streamlit_app.py +20 -7
requirements.txt CHANGED
@@ -1,2 +1,2 @@
1
  streamlit==1.27.2
2
- yt-dlp==2023.10.13
 
1
  streamlit==1.27.2
2
+ yt-dlp
streamlit_app.py CHANGED
@@ -4,7 +4,6 @@ import yt_dlp
4
  import string
5
  import streamlit as st
6
 
7
-
8
  # Config
9
  if "videos" not in st.session_state:
10
  st.session_state["videos"] = ""
@@ -23,8 +22,21 @@ def _remove_video():
23
  print("Couldn't delete file")
24
 
25
 
26
- def download_video(url: str, save_path: str, **kwargs):
27
- video_id =url.split("/")[-1]
 
 
 
 
 
 
 
 
 
 
 
 
 
28
 
29
  if len(video_id) < 1:
30
  video_id = url.split("/")[-2]
@@ -56,16 +68,17 @@ st.title("Download Any* Video")
56
  # Side bar content
57
  with st.sidebar:
58
  st.subheader("Cookies! :cookie:")
59
- st.write("For some websites that have a more strict bot control it's necessary to upload a cookie file to download content from them")
 
60
  st.file_uploader(label="**Upload Instagram Cookie** :cookie:", type=["txt", "json"],
61
  accept_multiple_files=False, key="ig_cookie")
62
  st.file_uploader(label="**Upload TikTok Cookie** :cookie:", type=["txt", "json"],
63
  accept_multiple_files=False, key="tt_cookie")
 
64
 
65
  # Main content
66
  st.text_input("Video URL", key="url", placeholder="Enter Video URL and Hit Enter", on_change=_remove_video)
67
 
68
-
69
  if st.session_state["url"]:
70
  download = st.button("Load Video")
71
  if download:
@@ -84,8 +97,8 @@ if st.session_state["videos"]:
84
  video_file = open(st.session_state["videos"], "rb")
85
  st.download_button("**Download Video πŸ“**",
86
  data=video_file,
87
- file_name=f"{st.session_state['videos'].lower().translate(str.maketrans('','', string.punctuation)).replace(' ', '_')}.mp4",
88
  mime="video/mp4",
89
  type="primary")
90
  except Exception as e:
91
- st.error("Failed downloading the video", icon="πŸ˜”")
 
4
  import string
5
  import streamlit as st
6
 
 
7
  # Config
8
  if "videos" not in st.session_state:
9
  st.session_state["videos"] = ""
 
22
  print("Couldn't delete file")
23
 
24
 
25
+ def _remove_all_videos():
26
+ videos = glob(os.path.join(".", "data", "*.mp4")) \
27
+ + glob(os.path.join(".", "data", "*.webm")) \
28
+ + glob(os.path.join(".", "data", "*.mov")) \
29
+ + glob(os.path.join(".", "data", "*.m4a"))
30
+ for video in videos:
31
+ try:
32
+ os.remove(video)
33
+ except FileNotFoundError:
34
+ print("Couldn't delete file:", video)
35
+
36
+
37
+ # Main function
38
+ def download_video(url: str, save_path: str, **kwargs):
39
+ video_id = url.split("/")[-1]
40
 
41
  if len(video_id) < 1:
42
  video_id = url.split("/")[-2]
 
68
  # Side bar content
69
  with st.sidebar:
70
  st.subheader("Cookies! :cookie:")
71
+ st.write(
72
+ "For some websites that have a more strict bot control it's necessary to upload a cookie file to download content from them")
73
  st.file_uploader(label="**Upload Instagram Cookie** :cookie:", type=["txt", "json"],
74
  accept_multiple_files=False, key="ig_cookie")
75
  st.file_uploader(label="**Upload TikTok Cookie** :cookie:", type=["txt", "json"],
76
  accept_multiple_files=False, key="tt_cookie")
77
+ st.button("Clear Videos", on_click=_remove_all_videos)
78
 
79
  # Main content
80
  st.text_input("Video URL", key="url", placeholder="Enter Video URL and Hit Enter", on_change=_remove_video)
81
 
 
82
  if st.session_state["url"]:
83
  download = st.button("Load Video")
84
  if download:
 
97
  video_file = open(st.session_state["videos"], "rb")
98
  st.download_button("**Download Video πŸ“**",
99
  data=video_file,
100
+ file_name=f"{st.session_state['videos'].lower().translate(str.maketrans('', '', string.punctuation)).replace(' ', '_')}.mp4",
101
  mime="video/mp4",
102
  type="primary")
103
  except Exception as e:
104
+ st.error("Failed downloading the video", icon="πŸ˜”")