Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -142,6 +142,154 @@
|
|
142 |
|
143 |
|
144 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
145 |
import streamlit as st
|
146 |
import yt_dlp
|
147 |
import os
|
@@ -184,7 +332,7 @@ def download_video(url, progress_bar, status_text):
|
|
184 |
'user_agent': random.choice(user_agents),
|
185 |
'referer': 'https://www.youtube.com/',
|
186 |
'http_chunk_size': random.randint(10000000, 15000000),
|
187 |
-
'retries': 5,
|
188 |
'sleep_interval': 3,
|
189 |
'max_sleep_interval': 8,
|
190 |
'headers': {
|
@@ -207,7 +355,7 @@ def download_video(url, progress_bar, status_text):
|
|
207 |
|
208 |
ydl_opts['progress_hooks'] = [progress_hook]
|
209 |
|
210 |
-
for attempt in range(5):
|
211 |
try:
|
212 |
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
213 |
info = ydl.extract_info(url, download=True)
|
@@ -219,8 +367,8 @@ def download_video(url, progress_bar, status_text):
|
|
219 |
time.sleep(random.uniform(3, 5))
|
220 |
continue
|
221 |
status_text.text(f"์ค๋ฅ ๋ฐ์: {str(e)}")
|
222 |
-
st.error(f"๋ค์ด๋ก๋ ์คํจ: {str(e)}")
|
223 |
-
st.info("๋ฌธ์ ๊ฐ ์ง์๋ ๊ฒฝ์ฐ URL์ด ์ฌ๋ฐ๋ฅธ์ง ํ์ธํ๊ณ ๋ค์ ์๋ํ์ธ์.")
|
224 |
return None
|
225 |
except Exception as e:
|
226 |
if attempt < 4:
|
@@ -228,8 +376,8 @@ def download_video(url, progress_bar, status_text):
|
|
228 |
time.sleep(2)
|
229 |
continue
|
230 |
status_text.text(f"์ค๋ฅ ๋ฐ์: {str(e)}")
|
231 |
-
st.error(f"๋ค์ด๋ก๋ ์คํจ: {str(e)}")
|
232 |
-
st.info("๋ฌธ์ ๊ฐ ์ง์๋ ๊ฒฝ์ฐ URL์ด ์ฌ๋ฐ๋ฅธ์ง ํ์ธํ๊ณ ๋ค์ ์๋ํ์ธ์.")
|
233 |
return None
|
234 |
|
235 |
except Exception as e:
|
@@ -286,4 +434,5 @@ if download_button:
|
|
286 |
# ์ด๊ธฐํ ๋ก์ง
|
287 |
if reset_button:
|
288 |
st.session_state.video_url = ""
|
289 |
-
|
|
|
|
142 |
|
143 |
|
144 |
|
145 |
+
# import streamlit as st
|
146 |
+
# import yt_dlp
|
147 |
+
# import os
|
148 |
+
# from pathlib import Path
|
149 |
+
# import random
|
150 |
+
# import time
|
151 |
+
|
152 |
+
# # ํ์ด์ง ์ค์
|
153 |
+
# st.set_page_config(page_title="Simple YouTube Downloader", page_icon="๐บ")
|
154 |
+
# st.title("Simple YouTube Downloader ๐บ")
|
155 |
+
|
156 |
+
# # ์คํ์ผ ์ค์
|
157 |
+
# st.markdown("""
|
158 |
+
# <style>
|
159 |
+
# .stButton > button {
|
160 |
+
# width: 100%;
|
161 |
+
# height: 60px;
|
162 |
+
# }
|
163 |
+
# </style>
|
164 |
+
# """, unsafe_allow_html=True)
|
165 |
+
|
166 |
+
# # ๋ค์ด๋ก๋ ํด๋ ์์ฑ
|
167 |
+
# output_dir = Path("downloads")
|
168 |
+
# output_dir.mkdir(exist_ok=True)
|
169 |
+
|
170 |
+
# def download_video(url, progress_bar, status_text):
|
171 |
+
# try:
|
172 |
+
# user_agents = [
|
173 |
+
# 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
|
174 |
+
# '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',
|
175 |
+
# 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:122.0) Gecko/20100101 Firefox/122.0'
|
176 |
+
# ]
|
177 |
+
|
178 |
+
# ydl_opts = {
|
179 |
+
# 'format': 'best',
|
180 |
+
# 'outtmpl': str(output_dir / '%(title)s.%(ext)s'),
|
181 |
+
# 'quiet': True,
|
182 |
+
# 'no_warnings': True,
|
183 |
+
# 'cookiefile': 'youtube.com_cookies.txt',
|
184 |
+
# 'user_agent': random.choice(user_agents),
|
185 |
+
# 'referer': 'https://www.youtube.com/',
|
186 |
+
# 'http_chunk_size': random.randint(10000000, 15000000),
|
187 |
+
# 'retries': 5, # ์ฌ์๋ ํ์๋ฅผ 5๋ก ๋๋ฆผ
|
188 |
+
# 'sleep_interval': 3,
|
189 |
+
# 'max_sleep_interval': 8,
|
190 |
+
# 'headers': {
|
191 |
+
# 'Accept-Language': 'en-US,en;q=0.9',
|
192 |
+
# 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
|
193 |
+
# },
|
194 |
+
# }
|
195 |
+
|
196 |
+
# def progress_hook(d):
|
197 |
+
# if d['status'] == 'downloading':
|
198 |
+
# try:
|
199 |
+
# progress = d['downloaded_bytes'] / d['total_bytes']
|
200 |
+
# progress_bar.progress(progress)
|
201 |
+
# status_text.text(f"๋ค์ด๋ก๋ ์ค: {progress:.1%}")
|
202 |
+
# except:
|
203 |
+
# status_text.text("๋ค์ด๋ก๋ ์ค...")
|
204 |
+
# elif d['status'] == 'finished':
|
205 |
+
# progress_bar.progress(1.0)
|
206 |
+
# status_text.text("์ฒ๋ฆฌ ์๋ฃ!")
|
207 |
+
|
208 |
+
# ydl_opts['progress_hooks'] = [progress_hook]
|
209 |
+
|
210 |
+
# for attempt in range(5): # ์ฌ์๋ ํ์๋ฅผ 5๋ก ์ค์
|
211 |
+
# try:
|
212 |
+
# with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
213 |
+
# info = ydl.extract_info(url, download=True)
|
214 |
+
# filename = ydl.prepare_filename(info)
|
215 |
+
# return filename
|
216 |
+
# except yt_dlp.utils.ExtractorError as e:
|
217 |
+
# if "Sign in to confirm you're not a bot" in str(e):
|
218 |
+
# status_text.text(f"์ฌ์๋ ์ค... ({attempt + 1}/5)")
|
219 |
+
# time.sleep(random.uniform(3, 5))
|
220 |
+
# continue
|
221 |
+
# status_text.text(f"์ค๋ฅ ๋ฐ์: {str(e)}")
|
222 |
+
# st.error(f"๋ค์ด๋ก๋ ์คํจ: {str(e)}") # ์คํจ ๋ฉ์์ง ํ์
|
223 |
+
# st.info("๋ฌธ์ ๊ฐ ์ง์๋ ๊ฒฝ์ฐ URL์ด ์ฌ๋ฐ๋ฅธ์ง ํ์ธํ๊ณ ๋ค์ ์๋ํ์ธ์.") # ์ถ๊ฐ ๋ฉ๋ชจ
|
224 |
+
# return None
|
225 |
+
# except Exception as e:
|
226 |
+
# if attempt < 4:
|
227 |
+
# status_text.text(f"์ฌ์๋ ์ค... ({attempt + 1}/5)")
|
228 |
+
# time.sleep(2)
|
229 |
+
# continue
|
230 |
+
# status_text.text(f"์ค๋ฅ ๋ฐ์: {str(e)}")
|
231 |
+
# st.error(f"๋ค์ด๋ก๋ ์คํจ: {str(e)}") # ์คํจ ๋ฉ์์ง ํ์
|
232 |
+
# st.info("๋ฌธ์ ๊ฐ ์ง์๋ ๊ฒฝ์ฐ URL์ด ์ฌ๋ฐ๋ฅธ์ง ํ์ธํ๊ณ ๋ค์ ์๋ํ์ธ์.") # ์ถ๊ฐ ๋ฉ๋ชจ
|
233 |
+
# return None
|
234 |
+
|
235 |
+
# except Exception as e:
|
236 |
+
# st.error(f"์ค๋ฅ ๋ฐ์: {str(e)}")
|
237 |
+
# return None
|
238 |
+
|
239 |
+
# # ์ฟ ํค ํ์ผ ์ฒดํฌ
|
240 |
+
# if not os.path.exists('youtube.com_cookies.txt'):
|
241 |
+
# st.warning("โ ๏ธ 'youtube.com_cookies.txt' ํ์ผ์ด ํ์ํฉ๋๋ค. YouTube์ ๋ก๊ทธ์ธ๋ ์ฟ ํค ํ์ผ์ ์
๋ก๋ํด์ฃผ์ธ์.")
|
242 |
+
# uploaded_file = st.file_uploader("์ฟ ํค ํ์ผ ์
๋ก๋", type=['txt'])
|
243 |
+
# if uploaded_file is not None:
|
244 |
+
# with open('youtube.com_cookies.txt', 'wb') as f:
|
245 |
+
# f.write(uploaded_file.getvalue())
|
246 |
+
# st.success("โ
์ฟ ํค ํ์ผ์ด ์
๋ก๋๋์์ต๋๋ค!")
|
247 |
+
# st.rerun()
|
248 |
+
|
249 |
+
# # ๋ฉ์ธ UI
|
250 |
+
# if 'video_url' not in st.session_state:
|
251 |
+
# st.session_state.video_url = ""
|
252 |
+
|
253 |
+
# video_url = st.text_input("YouTube URL ์
๋ ฅ:",
|
254 |
+
# value=st.session_state.video_url,
|
255 |
+
# placeholder="https://www.youtube.com/watch?v=...")
|
256 |
+
|
257 |
+
# # ๋ฒํผ์ ๊ฐ์ ์ค์ ๋ฐฐ์น
|
258 |
+
# col1, col2 = st.columns(2)
|
259 |
+
|
260 |
+
# with col1:
|
261 |
+
# download_button = st.button("๋ค์ด๋ก๋", type="primary", key="download_btn", use_container_width=True)
|
262 |
+
|
263 |
+
# with col2:
|
264 |
+
# reset_button = st.button("์ด๊ธฐํ", key="reset_btn", use_container_width=True)
|
265 |
+
|
266 |
+
# # ๋ค์ด๋ก๋ ๋ก์ง
|
267 |
+
# if download_button:
|
268 |
+
# if video_url:
|
269 |
+
# progress_bar = st.progress(0)
|
270 |
+
# status_text = st.empty()
|
271 |
+
|
272 |
+
# downloaded_file = download_video(video_url, progress_bar, status_text)
|
273 |
+
|
274 |
+
# if downloaded_file and os.path.exists(downloaded_file):
|
275 |
+
# with open(downloaded_file, 'rb') as file:
|
276 |
+
# st.download_button(
|
277 |
+
# label="โฌ๏ธ ํ์ผ ๋ค์ด๋ก๋",
|
278 |
+
# data=file,
|
279 |
+
# file_name=os.path.basename(downloaded_file),
|
280 |
+
# mime="video/mp4",
|
281 |
+
# use_container_width=True
|
282 |
+
# )
|
283 |
+
# else:
|
284 |
+
# st.warning("โ ๏ธ YouTube URL์ ์
๋ ฅํด์ฃผ์ธ์.")
|
285 |
+
|
286 |
+
# # ์ด๊ธฐํ ๋ก์ง
|
287 |
+
# if reset_button:
|
288 |
+
# st.session_state.video_url = ""
|
289 |
+
# st.rerun()
|
290 |
+
|
291 |
+
|
292 |
+
|
293 |
import streamlit as st
|
294 |
import yt_dlp
|
295 |
import os
|
|
|
332 |
'user_agent': random.choice(user_agents),
|
333 |
'referer': 'https://www.youtube.com/',
|
334 |
'http_chunk_size': random.randint(10000000, 15000000),
|
335 |
+
'retries': 5,
|
336 |
'sleep_interval': 3,
|
337 |
'max_sleep_interval': 8,
|
338 |
'headers': {
|
|
|
355 |
|
356 |
ydl_opts['progress_hooks'] = [progress_hook]
|
357 |
|
358 |
+
for attempt in range(5):
|
359 |
try:
|
360 |
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
361 |
info = ydl.extract_info(url, download=True)
|
|
|
367 |
time.sleep(random.uniform(3, 5))
|
368 |
continue
|
369 |
status_text.text(f"์ค๋ฅ ๋ฐ์: {str(e)}")
|
370 |
+
st.error(f"๋ค์ด๋ก๋ ์คํจ: {str(e)}")
|
371 |
+
st.info("๋ฌธ์ ๊ฐ ์ง์๋ ๊ฒฝ์ฐ URL์ด ์ฌ๋ฐ๋ฅธ์ง ํ์ธํ๊ณ ๋ค์ ์๋ํ์ธ์.")
|
372 |
return None
|
373 |
except Exception as e:
|
374 |
if attempt < 4:
|
|
|
376 |
time.sleep(2)
|
377 |
continue
|
378 |
status_text.text(f"์ค๋ฅ ๋ฐ์: {str(e)}")
|
379 |
+
st.error(f"๋ค์ด๋ก๋ ์คํจ: {str(e)}")
|
380 |
+
st.info("๋ฌธ์ ๊ฐ ์ง์๋ ๊ฒฝ์ฐ URL์ด ์ฌ๋ฐ๋ฅธ์ง ํ์ธํ๊ณ ๋ค์ ์๋ํ์ธ์.")
|
381 |
return None
|
382 |
|
383 |
except Exception as e:
|
|
|
434 |
# ์ด๊ธฐํ ๋ก์ง
|
435 |
if reset_button:
|
436 |
st.session_state.video_url = ""
|
437 |
+
video_url = "" # ์
๋ ฅ๋๋ ๋น์์ค
|
438 |
+
st.experimental_rerun() # ์๋ก๊ณ ์นจ์ ํตํด ์ํ๋ฅผ ์ด๊ธฐํ
|