Files changed (1) hide show
  1. app.py +0 -59
app.py DELETED
@@ -1,59 +0,0 @@
1
- import streamlit as st
2
- from pytube import YouTube
3
-
4
- class YouTubeDownloader:
5
- @staticmethod
6
- def run():
7
- st.header("YouTube Video Downloader")
8
- url = st.text_input("Enter YouTube URL to download:")
9
- if url:
10
- YouTubeDownloader.validate_url(url)
11
- with st.expander("preview video"):
12
- st.video(url)
13
- if st.button("Download"):
14
- YouTubeDownloader.cleanup()
15
- file_ = YouTubeDownloader.download_video(url)
16
- st.video(file_)
17
- YouTubeDownloader.helper_message()
18
- st.markdown("> App made by Abhay Koul ([HelpingAI on GitHub](https://github.com/HelpingAI))")
19
-
20
-
21
- @staticmethod
22
- def download_video(url):
23
- with st.spinner("Downloading..."):
24
- local_file = (
25
- YouTube(url)
26
- .streams.filter(progressive=True, file_extension="mp4")
27
- .first()
28
- .download()
29
- )
30
- st.success("Downloaded")
31
- return local_file
32
-
33
- @staticmethod
34
- def validate_url(url):
35
- import validators
36
-
37
- if not validators.url(url):
38
- st.error("Hi there 👋 URL seems invalid 👽")
39
- st.stop()
40
-
41
- @classmethod
42
- def cleanup(cls):
43
- import pathlib
44
- import glob
45
-
46
- junks = glob.glob("*.mp4")
47
- for junk in junks:
48
- pathlib.Path(junk).unlink()
49
-
50
- @classmethod
51
- def helper_message(cls):
52
- st.write(
53
- "> To save the video to local computer, "
54
- "click the vertical ... icon (aka hamburger button) in the bottom-right corner (in the video above) and click download."
55
- )
56
-
57
-
58
- if __name__ == "__main__":
59
- YouTubeDownloader.run()