Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -9,17 +9,22 @@ import time
|
|
9 |
st.set_page_config(page_title="Simple YouTube Downloader", page_icon="๐บ")
|
10 |
st.title("Simple YouTube Downloader ๐บ")
|
11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
# ๋ค์ด๋ก๋ ํด๋ ์์ฑ
|
13 |
output_dir = Path("downloads")
|
14 |
output_dir.mkdir(exist_ok=True)
|
15 |
|
16 |
-
def reset_input():
|
17 |
-
# session_state ๋์ ๋น ๋ฌธ์์ด ๋ฐํ
|
18 |
-
return ""
|
19 |
-
|
20 |
def download_video(url, progress_bar, status_text):
|
21 |
try:
|
22 |
-
# User Agent ๋ชฉ๋ก
|
23 |
user_agents = [
|
24 |
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
|
25 |
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.2.1 Safari/605.1.15',
|
@@ -31,7 +36,8 @@ def download_video(url, progress_bar, status_text):
|
|
31 |
'outtmpl': str(output_dir / '%(title)s.%(ext)s'),
|
32 |
'quiet': True,
|
33 |
'no_warnings': True,
|
34 |
-
#
|
|
|
35 |
'user_agent': random.choice(user_agents),
|
36 |
'referer': 'https://www.youtube.com/',
|
37 |
'http_chunk_size': random.randint(10000000, 15000000),
|
@@ -58,7 +64,6 @@ def download_video(url, progress_bar, status_text):
|
|
58 |
|
59 |
ydl_opts['progress_hooks'] = [progress_hook]
|
60 |
|
61 |
-
# ์ฌ์๋ ๋ก์ง ์ถ๊ฐ
|
62 |
for attempt in range(3):
|
63 |
try:
|
64 |
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
@@ -67,7 +72,7 @@ def download_video(url, progress_bar, status_text):
|
|
67 |
return filename
|
68 |
except yt_dlp.utils.ExtractorError as e:
|
69 |
if "Sign in to confirm you're not a bot" in str(e):
|
70 |
-
status_text.text(f"
|
71 |
time.sleep(random.uniform(3, 5))
|
72 |
continue
|
73 |
raise e
|
@@ -82,6 +87,16 @@ def download_video(url, progress_bar, status_text):
|
|
82 |
st.error(f"์ค๋ฅ ๋ฐ์: {str(e)}")
|
83 |
return None
|
84 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
85 |
# ๋ฉ์ธ UI
|
86 |
if 'video_url' not in st.session_state:
|
87 |
st.session_state.video_url = ""
|
@@ -90,28 +105,36 @@ video_url = st.text_input("YouTube URL ์
๋ ฅ:",
|
|
90 |
value=st.session_state.video_url,
|
91 |
placeholder="https://www.youtube.com/watch?v=...")
|
92 |
|
|
|
93 |
col1, col2 = st.columns(2)
|
94 |
|
95 |
with col1:
|
96 |
-
|
97 |
-
if video_url:
|
98 |
-
progress_bar = st.progress(0)
|
99 |
-
status_text = st.empty()
|
100 |
-
|
101 |
-
downloaded_file = download_video(video_url, progress_bar, status_text)
|
102 |
-
|
103 |
-
if downloaded_file and os.path.exists(downloaded_file):
|
104 |
-
with open(downloaded_file, 'rb') as file:
|
105 |
-
st.download_button(
|
106 |
-
label="โฌ๏ธ ํ์ผ ๋ค์ด๋ก๋",
|
107 |
-
data=file,
|
108 |
-
file_name=os.path.basename(downloaded_file),
|
109 |
-
mime="video/mp4"
|
110 |
-
)
|
111 |
-
else:
|
112 |
-
st.warning("โ ๏ธ YouTube URL์ ์
๋ ฅํด์ฃผ์ธ์.")
|
113 |
|
114 |
with col2:
|
115 |
-
|
116 |
-
|
117 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
st.set_page_config(page_title="Simple YouTube Downloader", page_icon="๐บ")
|
10 |
st.title("Simple YouTube Downloader ๐บ")
|
11 |
|
12 |
+
# ์คํ์ผ ์ค์
|
13 |
+
st.markdown("""
|
14 |
+
<style>
|
15 |
+
.stButton > button {
|
16 |
+
width: 100%;
|
17 |
+
height: 60px;
|
18 |
+
}
|
19 |
+
</style>
|
20 |
+
""", unsafe_allow_html=True)
|
21 |
+
|
22 |
# ๋ค์ด๋ก๋ ํด๋ ์์ฑ
|
23 |
output_dir = Path("downloads")
|
24 |
output_dir.mkdir(exist_ok=True)
|
25 |
|
|
|
|
|
|
|
|
|
26 |
def download_video(url, progress_bar, status_text):
|
27 |
try:
|
|
|
28 |
user_agents = [
|
29 |
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
|
30 |
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.2.1 Safari/605.1.15',
|
|
|
36 |
'outtmpl': str(output_dir / '%(title)s.%(ext)s'),
|
37 |
'quiet': True,
|
38 |
'no_warnings': True,
|
39 |
+
# ์ฟ ํค ํ์ผ ์ค์
|
40 |
+
'cookiefile': 'youtube.com_cookies.txt',
|
41 |
'user_agent': random.choice(user_agents),
|
42 |
'referer': 'https://www.youtube.com/',
|
43 |
'http_chunk_size': random.randint(10000000, 15000000),
|
|
|
64 |
|
65 |
ydl_opts['progress_hooks'] = [progress_hook]
|
66 |
|
|
|
67 |
for attempt in range(3):
|
68 |
try:
|
69 |
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
|
|
72 |
return filename
|
73 |
except yt_dlp.utils.ExtractorError as e:
|
74 |
if "Sign in to confirm you're not a bot" in str(e):
|
75 |
+
status_text.text(f"์ฌ์๋ ์ค... ({attempt + 1}/3)")
|
76 |
time.sleep(random.uniform(3, 5))
|
77 |
continue
|
78 |
raise e
|
|
|
87 |
st.error(f"์ค๋ฅ ๋ฐ์: {str(e)}")
|
88 |
return None
|
89 |
|
90 |
+
# ์ฟ ํค ํ์ผ ์ฒดํฌ
|
91 |
+
if not os.path.exists('youtube.com_cookies.txt'):
|
92 |
+
st.warning("โ ๏ธ 'youtube.com_cookies.txt' ํ์ผ์ด ํ์ํฉ๋๋ค. YouTube์ ๋ก๊ทธ์ธ๋ ์ฟ ํค ํ์ผ์ ์
๋ก๋ํด์ฃผ์ธ์.")
|
93 |
+
uploaded_file = st.file_uploader("์ฟ ํค ํ์ผ ์
๋ก๋", type=['txt'])
|
94 |
+
if uploaded_file is not None:
|
95 |
+
with open('youtube.com_cookies.txt', 'wb') as f:
|
96 |
+
f.write(uploaded_file.getvalue())
|
97 |
+
st.success("โ
์ฟ ํค ํ์ผ์ด ์
๋ก๋๋์์ต๋๋ค!")
|
98 |
+
st.rerun()
|
99 |
+
|
100 |
# ๋ฉ์ธ UI
|
101 |
if 'video_url' not in st.session_state:
|
102 |
st.session_state.video_url = ""
|
|
|
105 |
value=st.session_state.video_url,
|
106 |
placeholder="https://www.youtube.com/watch?v=...")
|
107 |
|
108 |
+
# ๋ฒํผ์ ๊ฐ์ ์ค์ ๋ฐฐ์น
|
109 |
col1, col2 = st.columns(2)
|
110 |
|
111 |
with col1:
|
112 |
+
download_button = st.button("๋ค์ด๋ก๋", type="primary", key="download_btn", use_container_width=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
113 |
|
114 |
with col2:
|
115 |
+
reset_button = st.button("์ด๊ธฐํ", key="reset_btn", use_container_width=True)
|
116 |
+
|
117 |
+
# ๋ค์ด๋ก๋ ๋ก์ง
|
118 |
+
if download_button:
|
119 |
+
if video_url:
|
120 |
+
progress_bar = st.progress(0)
|
121 |
+
status_text = st.empty()
|
122 |
+
|
123 |
+
downloaded_file = download_video(video_url, progress_bar, status_text)
|
124 |
+
|
125 |
+
if downloaded_file and os.path.exists(downloaded_file):
|
126 |
+
with open(downloaded_file, 'rb') as file:
|
127 |
+
st.download_button(
|
128 |
+
label="โฌ๏ธ ํ์ผ ๋ค์ด๋ก๋",
|
129 |
+
data=file,
|
130 |
+
file_name=os.path.basename(downloaded_file),
|
131 |
+
mime="video/mp4",
|
132 |
+
use_container_width=True
|
133 |
+
)
|
134 |
+
else:
|
135 |
+
st.warning("โ ๏ธ YouTube URL์ ์
๋ ฅํด์ฃผ์ธ์.")
|
136 |
+
|
137 |
+
# ์ด๊ธฐํ ๋ก์ง
|
138 |
+
if reset_button:
|
139 |
+
st.session_state.video_url = ""
|
140 |
+
st.rerun()
|