Spaces:
Build error
Build error
Matias Macias Gomez commited on
Commit Β·
95b1fe5
1
Parent(s): 4677866
Error management
Browse files- streamlit_app.py +20 -9
streamlit_app.py
CHANGED
|
@@ -22,7 +22,8 @@ def _remove_video():
|
|
| 22 |
except FileNotFoundError:
|
| 23 |
print("Couldn't delete file")
|
| 24 |
|
| 25 |
-
|
|
|
|
| 26 |
video_id =url.split("/")[-1]
|
| 27 |
|
| 28 |
if len(video_id) < 1:
|
|
@@ -52,6 +53,7 @@ def download_video(url:str, save_path:str , **kwargs):
|
|
| 52 |
|
| 53 |
st.title("Download Any* Video")
|
| 54 |
|
|
|
|
| 55 |
with st.sidebar:
|
| 56 |
st.subheader("Cookies! :cookie:")
|
| 57 |
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,6 +62,7 @@ with st.sidebar:
|
|
| 60 |
st.file_uploader(label="**Upload TikTok Cookie** :cookie:", type=["txt", "json"],
|
| 61 |
accept_multiple_files=False, key="tt_cookie")
|
| 62 |
|
|
|
|
| 63 |
st.text_input("Video URL", key="url", placeholder="Enter Video URL and Hit Enter", on_change=_remove_video)
|
| 64 |
|
| 65 |
|
|
@@ -70,11 +73,19 @@ if st.session_state["url"]:
|
|
| 70 |
st.session_state["videos"] = video_path
|
| 71 |
|
| 72 |
if st.session_state["videos"]:
|
| 73 |
-
st.write("**Title**:", st.session_state["videos"])
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
except FileNotFoundError:
|
| 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:
|
|
|
|
| 53 |
|
| 54 |
st.title("Download Any* Video")
|
| 55 |
|
| 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")
|
|
|
|
| 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 |
|
|
|
|
| 73 |
st.session_state["videos"] = video_path
|
| 74 |
|
| 75 |
if st.session_state["videos"]:
|
| 76 |
+
st.write("**Title**:", st.session_state["videos"].split("/")[-1])
|
| 77 |
+
|
| 78 |
+
try:
|
| 79 |
+
st.video(st.session_state["videos"])
|
| 80 |
+
except Exception as e:
|
| 81 |
+
st.write("Couldn't show video")
|
| 82 |
+
|
| 83 |
+
try:
|
| 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="π")
|