jpjp9292 commited on
Commit
c0c3b4a
โ€ข
1 Parent(s): 81377d5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -11
app.py CHANGED
@@ -296,6 +296,10 @@ import os
296
  from pathlib import Path
297
  import random
298
  import time
 
 
 
 
299
 
300
  # ํŽ˜์ด์ง€ ์„ค์ •
301
  st.set_page_config(page_title="Simple YouTube Downloader", page_icon="๐Ÿ“บ")
@@ -332,7 +336,7 @@ def download_video(url, progress_bar, status_text):
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': {
@@ -347,7 +351,8 @@ def download_video(url, progress_bar, status_text):
347
  progress = d['downloaded_bytes'] / d['total_bytes']
348
  progress_bar.progress(progress)
349
  status_text.text(f"๋‹ค์šด๋กœ๋“œ ์ค‘: {progress:.1%}")
350
- except:
 
351
  status_text.text("๋‹ค์šด๋กœ๋“œ ์ค‘...")
352
  elif d['status'] == 'finished':
353
  progress_bar.progress(1.0)
@@ -355,7 +360,7 @@ def download_video(url, progress_bar, status_text):
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)
@@ -366,22 +371,21 @@ def download_video(url, progress_bar, status_text):
366
  status_text.text(f"์žฌ์‹œ๋„ ์ค‘... ({attempt + 1}/5)")
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:
375
  status_text.text(f"์žฌ์‹œ๋„ ์ค‘... ({attempt + 1}/5)")
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:
384
- st.error(f"์˜ค๋ฅ˜ ๋ฐœ์ƒ: {str(e)}")
 
385
  return None
386
 
387
  # ์ฟ ํ‚ค ํŒŒ์ผ ์ฒดํฌ
@@ -434,5 +438,5 @@ if download_button:
434
  # ์ดˆ๊ธฐํ™” ๋กœ์ง
435
  if reset_button:
436
  st.session_state.video_url = ""
437
- video_url = "" # ์ž…๋ ฅ๋ž€๋„ ๋น„์›Œ์คŒ
438
- st.rerun() # ์ƒˆ๋กœ๊ณ ์นจ์„ ํ†ตํ•ด ์ƒํƒœ๋ฅผ ์ดˆ๊ธฐํ™”
 
296
  from pathlib import Path
297
  import random
298
  import time
299
+ import logging
300
+
301
+ # ๋กœ๊น… ์„ค์ •
302
+ logging.basicConfig(level=logging.ERROR, filename='error.log')
303
 
304
  # ํŽ˜์ด์ง€ ์„ค์ •
305
  st.set_page_config(page_title="Simple YouTube Downloader", page_icon="๐Ÿ“บ")
 
336
  'user_agent': random.choice(user_agents),
337
  'referer': 'https://www.youtube.com/',
338
  'http_chunk_size': random.randint(10000000, 15000000),
339
+ 'retries': 5, # ์žฌ์‹œ๋„ ํšŸ์ˆ˜๋ฅผ 5๋กœ ๋Š˜๋ฆผ
340
  'sleep_interval': 3,
341
  'max_sleep_interval': 8,
342
  'headers': {
 
351
  progress = d['downloaded_bytes'] / d['total_bytes']
352
  progress_bar.progress(progress)
353
  status_text.text(f"๋‹ค์šด๋กœ๋“œ ์ค‘: {progress:.1%}")
354
+ except Exception as e:
355
+ logging.error(f"Progress Hook Error: {e}")
356
  status_text.text("๋‹ค์šด๋กœ๋“œ ์ค‘...")
357
  elif d['status'] == 'finished':
358
  progress_bar.progress(1.0)
 
360
 
361
  ydl_opts['progress_hooks'] = [progress_hook]
362
 
363
+ for attempt in range(5): # ์žฌ์‹œ๋„ ํšŸ์ˆ˜๋ฅผ 5๋กœ ์„ค์ •
364
  try:
365
  with yt_dlp.YoutubeDL(ydl_opts) as ydl:
366
  info = ydl.extract_info(url, download=True)
 
371
  status_text.text(f"์žฌ์‹œ๋„ ์ค‘... ({attempt + 1}/5)")
372
  time.sleep(random.uniform(3, 5))
373
  continue
374
+ logging.error(f"Extractor Error: {str(e)}")
 
375
  st.info("๋ฌธ์ œ๊ฐ€ ์ง€์†๋  ๊ฒฝ์šฐ URL์ด ์˜ฌ๋ฐ”๋ฅธ์ง€ ํ™•์ธํ•˜๊ณ  ๋‹ค์‹œ ์‹œ๋„ํ•˜์„ธ์š”.")
376
  return None
377
  except Exception as e:
378
+ logging.error(f"Download Error: {str(e)}")
379
  if attempt < 4:
380
  status_text.text(f"์žฌ์‹œ๋„ ์ค‘... ({attempt + 1}/5)")
381
  time.sleep(2)
382
  continue
383
+ st.info("๋ฌธ์ œ๊ฐ€ ์ง€์†๋  ๊ฒฝ์šฐ ๋‹ค๋ฅธ URL์„ ์‹œ๋„ํ•ด์ฃผ์„ธ์š”.")
 
 
384
  return None
385
 
386
  except Exception as e:
387
+ logging.error(f"General Error: {str(e)}")
388
+ st.info("๋ฌธ์ œ๊ฐ€ ์ง€์†๋  ๊ฒฝ์šฐ ๋‹ค๋ฅธ URL์„ ์‹œ๋„ํ•ด์ฃผ์„ธ์š”.")
389
  return None
390
 
391
  # ์ฟ ํ‚ค ํŒŒ์ผ ์ฒดํฌ
 
438
  # ์ดˆ๊ธฐํ™” ๋กœ์ง
439
  if reset_button:
440
  st.session_state.video_url = ""
441
+ st.rerun() # st.experimental_rerun()์„ st.rerun()์œผ๋กœ ๋ณ€๊ฒฝํ–ˆ์Šต๋‹ˆ๋‹ค.
442
+