lcjln commited on
Commit
0ecfc82
Β·
verified Β·
1 Parent(s): dcd84ea

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -6
app.py CHANGED
@@ -4,16 +4,23 @@ import os
4
 
5
  # Streamlit 제λͺ©
6
  st.title('YouTube Video Downloader')
7
- st.write("<br>", unsafe_allow_html=True) # 1쀄 띄어쓰기
8
  st.write("μ‚¬μš©λ°©λ²•")
9
- st.write("<br>", unsafe_allow_html=True) # 1쀄 띄어쓰기
10
  st.write("1. λ‹€μš΄λ°›κ³ μžν•˜λŠ” 유튜브 μ˜μƒμ˜ 링크λ₯Ό μž…λ ₯ν•΄μ£Όμ„Έμš”")
11
  st.write("2. 링크λ₯Ό μž…λ ₯ν•˜κ³  ν™•μΈλ²„νŠΌμ„ λˆ„λ₯΄λ©΄ ν•΄λ‹Ή μ˜μƒμ˜ 썸넀일이 λ“±μž₯ν•©λ‹ˆλ‹€")
12
  st.write("3. 썸넀일 λ°‘μ˜ μ„ νƒλž€μ„ 톡해 해상도와 μ˜μƒ μš©λŸ‰μ„ ν™•μΈν•œ ν›„ μ›ν•˜λŠ” 해상도λ₯Ό μ„ νƒν•˜κ³  μΆ”μΆœ λ²„νŠΌμ„ λˆŒλŸ¬μ£Όμ„Έμš”")
13
  st.write("4. μž μ‹œ ν›„ λ‹€μš΄λ°›κ³ μžν•˜λŠ” μ˜μƒμ΄ 밑에 λ“±μž₯ν•˜κ³  μž¬μƒν•˜κ±°λ‚˜ λ‹€μš΄λ‘œλ“œ 받을 수 μžˆμŠ΅λ‹ˆλ‹€")
14
 
15
  # μœ μ €λ‘œλΆ€ν„° 유튜브 링크 μž…λ ₯λ°›κΈ°
16
- youtube_url = st.text_input('Enter YouTube video URL')
 
 
 
 
 
 
 
17
 
18
  if 'confirmed' not in st.session_state:
19
  st.session_state.confirmed = False
@@ -25,14 +32,15 @@ def fetch_video_info(youtube_url):
25
  return info_dict
26
 
27
  def get_available_formats(info_dict):
28
- formats = []
29
  for fmt in info_dict['formats']:
30
  if fmt.get('height') and fmt.get('ext') == 'mp4':
31
  filesize = fmt.get('filesize', 0)
32
  if filesize:
33
  filesize_mb = round(filesize / (1024 * 1024), 2)
34
- formats.append(f"{fmt['height']}p - {filesize_mb} MB")
35
- return formats
 
36
 
37
  if st.button('확인'):
38
  if youtube_url:
 
4
 
5
  # Streamlit 제λͺ©
6
  st.title('YouTube Video Downloader')
7
+ st.write("<br>", unsafe_allow_html=True) # 1쀄 띄어쓰기
8
  st.write("μ‚¬μš©λ°©λ²•")
9
+ st.write("<br>", unsafe_allow_html=True) # 1쀄 띄어쓰기
10
  st.write("1. λ‹€μš΄λ°›κ³ μžν•˜λŠ” 유튜브 μ˜μƒμ˜ 링크λ₯Ό μž…λ ₯ν•΄μ£Όμ„Έμš”")
11
  st.write("2. 링크λ₯Ό μž…λ ₯ν•˜κ³  ν™•μΈλ²„νŠΌμ„ λˆ„λ₯΄λ©΄ ν•΄λ‹Ή μ˜μƒμ˜ 썸넀일이 λ“±μž₯ν•©λ‹ˆλ‹€")
12
  st.write("3. 썸넀일 λ°‘μ˜ μ„ νƒλž€μ„ 톡해 해상도와 μ˜μƒ μš©λŸ‰μ„ ν™•μΈν•œ ν›„ μ›ν•˜λŠ” 해상도λ₯Ό μ„ νƒν•˜κ³  μΆ”μΆœ λ²„νŠΌμ„ λˆŒλŸ¬μ£Όμ„Έμš”")
13
  st.write("4. μž μ‹œ ν›„ λ‹€μš΄λ°›κ³ μžν•˜λŠ” μ˜μƒμ΄ 밑에 λ“±μž₯ν•˜κ³  μž¬μƒν•˜κ±°λ‚˜ λ‹€μš΄λ‘œλ“œ 받을 수 μžˆμŠ΅λ‹ˆλ‹€")
14
 
15
  # μœ μ €λ‘œλΆ€ν„° 유튜브 링크 μž…λ ₯λ°›κΈ°
16
+ col1, col2 = st.columns([4, 1])
17
+ with col1:
18
+ youtube_url = st.text_input('Enter YouTube video URL')
19
+
20
+ with col2:
21
+ if st.button('μƒˆλ‘œκ³ μΉ¨'):
22
+ st.session_state.clear() # μ„Έμ…˜ μ΄ˆκΈ°ν™”
23
+ st.experimental_rerun() # νŽ˜μ΄μ§€λ₯Ό μƒˆλ‘œκ³ μΉ¨ν•˜μ—¬ μ• ν”Œλ¦¬μΌ€μ΄μ…˜ μž¬μ‹€ν–‰
24
 
25
  if 'confirmed' not in st.session_state:
26
  st.session_state.confirmed = False
 
32
  return info_dict
33
 
34
  def get_available_formats(info_dict):
35
+ formats = {}
36
  for fmt in info_dict['formats']:
37
  if fmt.get('height') and fmt.get('ext') == 'mp4':
38
  filesize = fmt.get('filesize', 0)
39
  if filesize:
40
  filesize_mb = round(filesize / (1024 * 1024), 2)
41
+ resolution = f"{fmt['height']}p"
42
+ formats[resolution] = f"{resolution} - {filesize_mb} MB"
43
+ return list(formats.values())
44
 
45
  if st.button('확인'):
46
  if youtube_url: