JUNGU commited on
Commit
99baa8d
·
verified ·
1 Parent(s): 20a7e87

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -44
app.py CHANGED
@@ -1,52 +1,40 @@
1
  import gradio as gr
2
- from pytube import YouTube
3
- import os
4
 
5
- def download_youtube_videos(urls):
6
- """Downloads multiple YouTube videos and returns a list of downloaded file paths."""
7
- downloaded_files = []
8
- for url in urls:
9
- try:
10
- yt = YouTube(url)
11
- video = yt.streams.filter(progressive=True, file_extension='mp4').order_by('resolution').desc().first()
12
- filename = f"{yt.title}.mp4"
13
- video.download(filename=filename)
14
- downloaded_files.append(filename)
15
- except Exception as e:
16
- print(f"Error downloading {url}: {str(e)}")
17
-
18
- return downloaded_files
 
 
 
 
 
 
 
 
19
 
20
- def app(urls):
21
- # Split the input string into a list of URLs
22
- url_list = [url.strip() for url in urls.split('\n') if url.strip()]
23
 
24
- if not url_list:
25
- return None, "No valid URLs provided. Please enter at least one YouTube URL."
 
26
 
27
- downloaded_files = download_youtube_videos(url_list)
28
 
29
- if downloaded_files:
30
- # Create a list of (filename, file path) tuples for Gradio File component
31
- file_tuples = [(f, f) for f in downloaded_files if os.path.exists(f)]
32
- message = f"Successfully downloaded {len(file_tuples)} videos."
33
- return file_tuples, message
34
- else:
35
- return None, "Download failed. Please check the URLs and try again."
36
-
37
- with gr.Blocks() as interface:
38
- gr.Markdown("## YouTube Batch Video Downloader")
39
- urls_input = gr.Textbox(label="Enter YouTube links (one per line) 🔗", lines=5)
40
- download_button = gr.Button("Download Videos")
41
- output = gr.File(label="Downloaded Videos", file_count="multiple")
42
- message = gr.Markdown()
43
-
44
- download_button.click(
45
- fn=app,
46
- inputs=urls_input,
47
- outputs=[output, message],
48
- api_name="download"
49
- )
50
 
51
  if __name__ == "__main__":
52
- interface.launch(debug=True)
 
1
  import gradio as gr
2
+ from yt_dlp import YoutubeDL
 
3
 
4
+ def extract_metadata(youtube_url):
5
+ ydl_opts = {'quiet': True}
6
+ try:
7
+ with YoutubeDL(ydl_opts) as ydl:
8
+ info = ydl.extract_info(youtube_url, download=False)
9
+
10
+ metadata = {
11
+ "제목": info.get('title', 'N/A'),
12
+ "채널": info.get('channel', 'N/A'),
13
+ "업로드 날짜": info.get('upload_date', 'N/A'),
14
+ "조회수": info.get('view_count', 'N/A'),
15
+ "좋아요 수": info.get('like_count', 'N/A'),
16
+ "길이 (초)": info.get('duration', 'N/A'),
17
+ "설명": info.get('description', 'N/A')[:500] + '...' # 설명 일부만 표시
18
+ }
19
+
20
+ return "\n".join([f"{k}: {v}" for k, v in metadata.items()])
21
+ except Exception as e:
22
+ return f"오류 발생: {str(e)}"
23
+
24
+ def check_yt_dlp_version():
25
+ return f"yt-dlp 버전: {YoutubeDL.version.__version__}"
26
 
27
+ with gr.Blocks() as demo:
28
+ gr.Markdown("## YouTube 메타데이터 추출기")
29
+ gr.Markdown(check_yt_dlp_version())
30
 
31
+ with gr.Row():
32
+ youtube_url_input = gr.Textbox(label="YouTube URL 입력")
33
+ extract_button = gr.Button("메타데이터 추출")
34
 
35
+ output = gr.Textbox(label="추출된 메타데이터", lines=10)
36
 
37
+ extract_button.click(fn=extract_metadata, inputs=youtube_url_input, outputs=output)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
 
39
  if __name__ == "__main__":
40
+ demo.launch()