Spaces:
Runtime error
Runtime error
| # import streamlit as st | |
| # import yt_dlp | |
| # import os | |
| # from pathlib import Path | |
| # import random | |
| # import time | |
| # # ํ์ด์ง ์ค์ | |
| # st.set_page_config(page_title="Simple YouTube Downloader", page_icon="๐บ") | |
| # st.title("Simple YouTube Downloader ๐บ") | |
| # # ์คํ์ผ ์ค์ | |
| # st.markdown(""" | |
| # <style> | |
| # .stButton > button { | |
| # width: 100%; | |
| # height: 60px; | |
| # } | |
| # </style> | |
| # """, unsafe_allow_html=True) | |
| # # ๋ค์ด๋ก๋ ํด๋ ์์ฑ | |
| # output_dir = Path("downloads") | |
| # output_dir.mkdir(exist_ok=True) | |
| # def download_video(url, progress_bar, status_text): | |
| # try: | |
| # user_agents = [ | |
| # 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36', | |
| # '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', | |
| # 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:122.0) Gecko/20100101 Firefox/122.0' | |
| # ] | |
| # ydl_opts = { | |
| # 'format': 'best', | |
| # 'outtmpl': str(output_dir / '%(title)s.%(ext)s'), | |
| # 'quiet': True, | |
| # 'no_warnings': True, | |
| # 'cookiefile': 'youtube.com_cookies.txt', | |
| # 'user_agent': random.choice(user_agents), | |
| # 'referer': 'https://www.youtube.com/', | |
| # 'http_chunk_size': random.randint(10000000, 15000000), | |
| # 'retries': 3, | |
| # 'sleep_interval': 3, | |
| # 'max_sleep_interval': 8, | |
| # 'headers': { | |
| # 'Accept-Language': 'en-US,en;q=0.9', | |
| # 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', | |
| # }, | |
| # } | |
| # def progress_hook(d): | |
| # if d['status'] == 'downloading': | |
| # try: | |
| # progress = d['downloaded_bytes'] / d['total_bytes'] | |
| # progress_bar.progress(progress) | |
| # status_text.text(f"๋ค์ด๋ก๋ ์ค: {progress:.1%}") | |
| # except: | |
| # status_text.text("๋ค์ด๋ก๋ ์ค...") | |
| # elif d['status'] == 'finished': | |
| # progress_bar.progress(1.0) | |
| # status_text.text("์ฒ๋ฆฌ ์๋ฃ!") | |
| # ydl_opts['progress_hooks'] = [progress_hook] | |
| # for attempt in range(3): | |
| # try: | |
| # with yt_dlp.YoutubeDL(ydl_opts) as ydl: | |
| # info = ydl.extract_info(url, download=True) | |
| # filename = ydl.prepare_filename(info) | |
| # return filename | |
| # except yt_dlp.utils.ExtractorError as e: | |
| # if "Sign in to confirm you're not a bot" in str(e): | |
| # status_text.text(f"์ฌ์๋ ์ค... ({attempt + 1}/3)") | |
| # time.sleep(random.uniform(3, 5)) | |
| # continue | |
| # raise e | |
| # except Exception as e: | |
| # if attempt < 2: | |
| # status_text.text(f"์ฌ์๋ ์ค... ({attempt + 1}/3)") | |
| # time.sleep(2) | |
| # continue | |
| # raise e | |
| # except Exception as e: | |
| # st.error(f"์ค๋ฅ ๋ฐ์: {str(e)}") | |
| # return None | |
| # # ์ฟ ํค ํ์ผ ์ฒดํฌ | |
| # if not os.path.exists('youtube.com_cookies.txt'): | |
| # st.warning("โ ๏ธ 'youtube.com_cookies.txt' ํ์ผ์ด ํ์ํฉ๋๋ค. YouTube์ ๋ก๊ทธ์ธ๋ ์ฟ ํค ํ์ผ์ ์ ๋ก๋ํด์ฃผ์ธ์.") | |
| # uploaded_file = st.file_uploader("์ฟ ํค ํ์ผ ์ ๋ก๋", type=['txt']) | |
| # if uploaded_file is not None: | |
| # with open('youtube.com_cookies.txt', 'wb') as f: | |
| # f.write(uploaded_file.getvalue()) | |
| # st.success("โ ์ฟ ํค ํ์ผ์ด ์ ๋ก๋๋์์ต๋๋ค!") | |
| # st.rerun() | |
| # # ๋ฉ์ธ UI | |
| # if 'video_url' not in st.session_state: | |
| # st.session_state.video_url = "" | |
| # video_url = st.text_input("YouTube URL ์ ๋ ฅ:", | |
| # value=st.session_state.video_url, | |
| # placeholder="https://www.youtube.com/watch?v=...") | |
| # # ๋ฒํผ์ ๊ฐ์ ์ค์ ๋ฐฐ์น | |
| # col1, col2 = st.columns(2) | |
| # with col1: | |
| # download_button = st.button("๋ค์ด๋ก๋", type="primary", key="download_btn", use_container_width=True) | |
| # with col2: | |
| # reset_button = st.button("์ด๊ธฐํ", key="reset_btn", use_container_width=True) | |
| # # ๋ค์ด๋ก๋ ๋ก์ง | |
| # if download_button: | |
| # if video_url: | |
| # progress_bar = st.progress(0) | |
| # status_text = st.empty() | |
| # downloaded_file = download_video(video_url, progress_bar, status_text) | |
| # if downloaded_file and os.path.exists(downloaded_file): | |
| # with open(downloaded_file, 'rb') as file: | |
| # st.download_button( | |
| # label="โฌ๏ธ ํ์ผ ๋ค์ด๋ก๋", | |
| # data=file, | |
| # file_name=os.path.basename(downloaded_file), | |
| # mime="video/mp4", | |
| # use_container_width=True | |
| # ) | |
| # else: | |
| # st.warning("โ ๏ธ YouTube URL์ ์ ๋ ฅํด์ฃผ์ธ์.") | |
| # # ์ด๊ธฐํ ๋ก์ง | |
| # if reset_button: | |
| # st.session_state.video_url = "" | |
| # st.rerun() | |
| # import streamlit as st | |
| # import yt_dlp | |
| # import os | |
| # from pathlib import Path | |
| # import random | |
| # import time | |
| # # ํ์ด์ง ์ค์ | |
| # st.set_page_config(page_title="Simple YouTube Downloader", page_icon="๐บ") | |
| # st.title("Simple YouTube Downloader ๐บ") | |
| # # ์คํ์ผ ์ค์ | |
| # st.markdown(""" | |
| # <style> | |
| # .stButton > button { | |
| # width: 100%; | |
| # height: 60px; | |
| # } | |
| # </style> | |
| # """, unsafe_allow_html=True) | |
| # # ๋ค์ด๋ก๋ ํด๋ ์์ฑ | |
| # output_dir = Path("downloads") | |
| # output_dir.mkdir(exist_ok=True) | |
| # def download_video(url, progress_bar, status_text): | |
| # try: | |
| # user_agents = [ | |
| # 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36', | |
| # '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', | |
| # 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:122.0) Gecko/20100101 Firefox/122.0' | |
| # ] | |
| # ydl_opts = { | |
| # 'format': 'best', | |
| # 'outtmpl': str(output_dir / '%(title)s.%(ext)s'), | |
| # 'quiet': True, | |
| # 'no_warnings': True, | |
| # 'cookiefile': 'youtube.com_cookies.txt', | |
| # 'user_agent': random.choice(user_agents), | |
| # 'referer': 'https://www.youtube.com/', | |
| # 'http_chunk_size': random.randint(10000000, 15000000), | |
| # 'retries': 5, # ์ฌ์๋ ํ์๋ฅผ 5๋ก ๋๋ฆผ | |
| # 'sleep_interval': 3, | |
| # 'max_sleep_interval': 8, | |
| # 'headers': { | |
| # 'Accept-Language': 'en-US,en;q=0.9', | |
| # 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', | |
| # }, | |
| # } | |
| # def progress_hook(d): | |
| # if d['status'] == 'downloading': | |
| # try: | |
| # progress = d['downloaded_bytes'] / d['total_bytes'] | |
| # progress_bar.progress(progress) | |
| # status_text.text(f"๋ค์ด๋ก๋ ์ค: {progress:.1%}") | |
| # except: | |
| # status_text.text("๋ค์ด๋ก๋ ์ค...") | |
| # elif d['status'] == 'finished': | |
| # progress_bar.progress(1.0) | |
| # status_text.text("์ฒ๋ฆฌ ์๋ฃ!") | |
| # ydl_opts['progress_hooks'] = [progress_hook] | |
| # for attempt in range(5): # ์ฌ์๋ ํ์๋ฅผ 5๋ก ์ค์ | |
| # try: | |
| # with yt_dlp.YoutubeDL(ydl_opts) as ydl: | |
| # info = ydl.extract_info(url, download=True) | |
| # filename = ydl.prepare_filename(info) | |
| # return filename | |
| # except yt_dlp.utils.ExtractorError as e: | |
| # if "Sign in to confirm you're not a bot" in str(e): | |
| # status_text.text(f"์ฌ์๋ ์ค... ({attempt + 1}/5)") | |
| # time.sleep(random.uniform(3, 5)) | |
| # continue | |
| # status_text.text(f"์ค๋ฅ ๋ฐ์: {str(e)}") | |
| # st.error(f"๋ค์ด๋ก๋ ์คํจ: {str(e)}") # ์คํจ ๋ฉ์์ง ํ์ | |
| # st.info("๋ฌธ์ ๊ฐ ์ง์๋ ๊ฒฝ์ฐ URL์ด ์ฌ๋ฐ๋ฅธ์ง ํ์ธํ๊ณ ๋ค์ ์๋ํ์ธ์.") # ์ถ๊ฐ ๋ฉ๋ชจ | |
| # return None | |
| # except Exception as e: | |
| # if attempt < 4: | |
| # status_text.text(f"์ฌ์๋ ์ค... ({attempt + 1}/5)") | |
| # time.sleep(2) | |
| # continue | |
| # status_text.text(f"์ค๋ฅ ๋ฐ์: {str(e)}") | |
| # st.error(f"๋ค์ด๋ก๋ ์คํจ: {str(e)}") # ์คํจ ๋ฉ์์ง ํ์ | |
| # st.info("๋ฌธ์ ๊ฐ ์ง์๋ ๊ฒฝ์ฐ URL์ด ์ฌ๋ฐ๋ฅธ์ง ํ์ธํ๊ณ ๋ค์ ์๋ํ์ธ์.") # ์ถ๊ฐ ๋ฉ๋ชจ | |
| # return None | |
| # except Exception as e: | |
| # st.error(f"์ค๋ฅ ๋ฐ์: {str(e)}") | |
| # return None | |
| # # ์ฟ ํค ํ์ผ ์ฒดํฌ | |
| # if not os.path.exists('youtube.com_cookies.txt'): | |
| # st.warning("โ ๏ธ 'youtube.com_cookies.txt' ํ์ผ์ด ํ์ํฉ๋๋ค. YouTube์ ๋ก๊ทธ์ธ๋ ์ฟ ํค ํ์ผ์ ์ ๋ก๋ํด์ฃผ์ธ์.") | |
| # uploaded_file = st.file_uploader("์ฟ ํค ํ์ผ ์ ๋ก๋", type=['txt']) | |
| # if uploaded_file is not None: | |
| # with open('youtube.com_cookies.txt', 'wb') as f: | |
| # f.write(uploaded_file.getvalue()) | |
| # st.success("โ ์ฟ ํค ํ์ผ์ด ์ ๋ก๋๋์์ต๋๋ค!") | |
| # st.rerun() | |
| # # ๋ฉ์ธ UI | |
| # if 'video_url' not in st.session_state: | |
| # st.session_state.video_url = "" | |
| # video_url = st.text_input("YouTube URL ์ ๋ ฅ:", | |
| # value=st.session_state.video_url, | |
| # placeholder="https://www.youtube.com/watch?v=...") | |
| # # ๋ฒํผ์ ๊ฐ์ ์ค์ ๋ฐฐ์น | |
| # col1, col2 = st.columns(2) | |
| # with col1: | |
| # download_button = st.button("๋ค์ด๋ก๋", type="primary", key="download_btn", use_container_width=True) | |
| # with col2: | |
| # reset_button = st.button("์ด๊ธฐํ", key="reset_btn", use_container_width=True) | |
| # # ๋ค์ด๋ก๋ ๋ก์ง | |
| # if download_button: | |
| # if video_url: | |
| # progress_bar = st.progress(0) | |
| # status_text = st.empty() | |
| # downloaded_file = download_video(video_url, progress_bar, status_text) | |
| # if downloaded_file and os.path.exists(downloaded_file): | |
| # with open(downloaded_file, 'rb') as file: | |
| # st.download_button( | |
| # label="โฌ๏ธ ํ์ผ ๋ค์ด๋ก๋", | |
| # data=file, | |
| # file_name=os.path.basename(downloaded_file), | |
| # mime="video/mp4", | |
| # use_container_width=True | |
| # ) | |
| # else: | |
| # st.warning("โ ๏ธ YouTube URL์ ์ ๋ ฅํด์ฃผ์ธ์.") | |
| # # ์ด๊ธฐํ ๋ก์ง | |
| # if reset_button: | |
| # st.session_state.video_url = "" | |
| # st.rerun() | |
| import streamlit as st | |
| import yt_dlp | |
| import os | |
| from pathlib import Path | |
| import random | |
| import time | |
| import logging | |
| # ๋ก๊น ์ค์ | |
| logging.basicConfig(level=logging.ERROR, filename='error.log') | |
| # ํ์ด์ง ์ค์ | |
| st.set_page_config(page_title="Simple YouTube Downloader", page_icon="๐บ") | |
| st.title("Simple YouTube Downloader ๐บ") | |
| # ์คํ์ผ ์ค์ | |
| st.markdown(""" | |
| <style> | |
| .stButton > button { | |
| width: 100%; | |
| height: 60px; | |
| } | |
| </style> | |
| """, unsafe_allow_html=True) | |
| # ๋ค์ด๋ก๋ ํด๋ ์์ฑ | |
| output_dir = Path("downloads") | |
| output_dir.mkdir(exist_ok=True) | |
| def download_video(url, progress_bar, status_text): | |
| try: | |
| user_agents = [ | |
| 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36', | |
| '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', | |
| 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:122.0) Gecko/20100101 Firefox/122.0' | |
| ] | |
| ydl_opts = { | |
| 'format': 'best', | |
| 'outtmpl': str(output_dir / '%(title)s.%(ext)s'), | |
| 'quiet': True, | |
| 'no_warnings': True, | |
| 'cookiefile': 'youtube.com_cookies.txt', | |
| 'user_agent': random.choice(user_agents), | |
| 'referer': 'https://www.youtube.com/', | |
| 'http_chunk_size': random.randint(100000000, 150000000), | |
| 'retries': 5, # ์ฌ์๋ ํ์ | |
| 'sleep_interval': 4, | |
| 'max_sleep_interval': 8, | |
| 'headers': { | |
| 'Accept-Language': 'en-US,en;q=0.9', | |
| 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', | |
| }, | |
| } | |
| def progress_hook(d): | |
| if d['status'] == 'downloading': | |
| try: | |
| progress = d['downloaded_bytes'] / d['total_bytes'] | |
| progress_bar.progress(progress) | |
| status_text.text(f"๋ค์ด๋ก๋ ์ค: {progress:.1%}") | |
| except Exception as e: | |
| logging.error(f"Progress Hook Error: {e}") | |
| status_text.text("๋ค์ด๋ก๋ ์ค...") | |
| elif d['status'] == 'finished': | |
| progress_bar.progress(1.0) | |
| status_text.text("์ฒ๋ฆฌ ์๋ฃ!") | |
| ydl_opts['progress_hooks'] = [progress_hook] | |
| for attempt in range(5): # ์ฌ์๋ ํ์๋ฅผ 5๋ก ์ค์ | |
| try: | |
| with yt_dlp.YoutubeDL(ydl_opts) as ydl: | |
| info = ydl.extract_info(url, download=True) | |
| filename = ydl.prepare_filename(info) | |
| return filename | |
| except yt_dlp.utils.ExtractorError as e: | |
| if "Sign in to confirm you're not a bot" in str(e): | |
| status_text.text(f"์ฌ์๋ ์ค... ({attempt + 1}/5)") | |
| time.sleep(random.uniform(3, 5)) | |
| continue | |
| logging.error(f"Extractor Error: {str(e)}") | |
| st.info("๋ฌธ์ ๊ฐ ์ง์๋ ๊ฒฝ์ฐ URL์ด ์ฌ๋ฐ๋ฅธ์ง ํ์ธํ๊ณ ๋ค์ ์๋ํ์ธ์.") | |
| return None | |
| except Exception as e: | |
| logging.error(f"Download Error: {str(e)}") | |
| if attempt < 4: | |
| status_text.text(f"์ฌ์๋ ์ค... ({attempt + 1}/5)") | |
| time.sleep(2) | |
| continue | |
| st.info("๋ฌธ์ ๊ฐ ์ง์๋ ๊ฒฝ์ฐ ๋ค๋ฅธ URL์ ์๋ํด์ฃผ์ธ์.") | |
| return None | |
| except Exception as e: | |
| logging.error(f"General Error: {str(e)}") | |
| st.info("๋ฌธ์ ๊ฐ ์ง์๋ ๊ฒฝ์ฐ ๋ค๋ฅธ URL์ ์๋ํด์ฃผ์ธ์.") | |
| return None | |
| # ์ฟ ํค ํ์ผ ์ฒดํฌ | |
| if not os.path.exists('youtube.com_cookies.txt'): | |
| st.warning("โ ๏ธ 'youtube.com_cookies.txt' ํ์ผ์ด ํ์ํฉ๋๋ค. YouTube์ ๋ก๊ทธ์ธ๋ ์ฟ ํค ํ์ผ์ ์ ๋ก๋ํด์ฃผ์ธ์.") | |
| uploaded_file = st.file_uploader("์ฟ ํค ํ์ผ ์ ๋ก๋", type=['txt']) | |
| if uploaded_file is not None: | |
| with open('youtube.com_cookies.txt', 'wb') as f: | |
| f.write(uploaded_file.getvalue()) | |
| st.success("โ ์ฟ ํค ํ์ผ์ด ์ ๋ก๋๋์์ต๋๋ค!") | |
| st.rerun() | |
| # ๋ฉ์ธ UI | |
| if 'video_url' not in st.session_state: | |
| st.session_state.video_url = "" | |
| video_url = st.text_input("YouTube URL ์ ๋ ฅ:", | |
| value=st.session_state.video_url, | |
| placeholder="https://www.youtube.com/watch?v=...") | |
| # ๋ฒํผ์ ๊ฐ์ ์ค์ ๋ฐฐ์น | |
| col1, col2 = st.columns(2) | |
| with col1: | |
| download_button = st.button("๋ค์ด๋ก๋", type="primary", key="download_btn", use_container_width=True) | |
| with col2: | |
| reset_button = st.button("์ด๊ธฐํ", key="reset_btn", use_container_width=True) | |
| # ๋ค์ด๋ก๋ ๋ก์ง | |
| if download_button: | |
| if video_url: | |
| progress_bar = st.progress(0) | |
| status_text = st.empty() | |
| downloaded_file = download_video(video_url, progress_bar, status_text) | |
| if downloaded_file and os.path.exists(downloaded_file): | |
| with open(downloaded_file, 'rb') as file: | |
| st.download_button( | |
| label="โฌ๏ธ ํ์ผ ๋ค์ด๋ก๋", | |
| data=file, | |
| file_name=os.path.basename(downloaded_file), | |
| mime="video/mp4", | |
| use_container_width=True | |
| ) | |
| else: | |
| st.warning("โ ๏ธ YouTube URL์ ์ ๋ ฅํด์ฃผ์ธ์.") | |
| # ์ด๊ธฐํ ๋ก์ง | |
| if reset_button: | |
| st.session_state.video_url = "" | |
| st.rerun() | |