lcjln commited on
Commit
8d4e91a
ยท
verified ยท
1 Parent(s): 3fc49ec

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -4
app.py CHANGED
@@ -31,8 +31,11 @@ def get_available_formats(info_dict):
31
  if filesize:
32
  filesize_mb = round(filesize / (1024 * 1024), 2)
33
  resolution = f"{fmt['height']}p"
34
- formats[resolution] = f"{resolution} - {filesize_mb} MB"
35
- return list(formats.values())
 
 
 
36
 
37
  # "ํ™•์ธ" ๋ฒ„ํŠผ์„ ๋ˆ„๋ฅด๋ฉด ์ฒ˜๋ฆฌํ•  ๋กœ์ง
38
  if st.button('ํ™•์ธ'):
@@ -60,7 +63,7 @@ if 'confirmed' in st.session_state and st.session_state.confirmed:
60
  st.image(st.session_state.thumbnail_url, caption='Video Thumbnail', use_column_width=True)
61
 
62
  # ํ•ด์ƒ๋„ ์„ ํƒ
63
- format_selection = st.selectbox('Select resolution', st.session_state.formats)
64
 
65
  def download_video(youtube_url, format_id):
66
  ydl_opts = {
@@ -75,7 +78,7 @@ if 'confirmed' in st.session_state and st.session_state.confirmed:
75
 
76
  # "์ถ”์ถœ" ๋ฒ„ํŠผ ์ถ”๊ฐ€
77
  if st.button('์ถ”์ถœ'):
78
- format_id = format_selection.split('p')[0]
79
  try:
80
  # ์„ธ์…˜ ์ƒํƒœ์˜ youtube_url ์‚ฌ์šฉ
81
  download_video(st.session_state.youtube_url, format_id)
 
31
  if filesize:
32
  filesize_mb = round(filesize / (1024 * 1024), 2)
33
  resolution = f"{fmt['height']}p"
34
+ formats[resolution] = {
35
+ 'id': fmt['format_id'],
36
+ 'info': f"{resolution} - {filesize_mb} MB"
37
+ }
38
+ return formats
39
 
40
  # "ํ™•์ธ" ๋ฒ„ํŠผ์„ ๋ˆ„๋ฅด๋ฉด ์ฒ˜๋ฆฌํ•  ๋กœ์ง
41
  if st.button('ํ™•์ธ'):
 
63
  st.image(st.session_state.thumbnail_url, caption='Video Thumbnail', use_column_width=True)
64
 
65
  # ํ•ด์ƒ๋„ ์„ ํƒ
66
+ format_selection = st.selectbox('Select resolution', list(st.session_state.formats.values()))
67
 
68
  def download_video(youtube_url, format_id):
69
  ydl_opts = {
 
78
 
79
  # "์ถ”์ถœ" ๋ฒ„ํŠผ ์ถ”๊ฐ€
80
  if st.button('์ถ”์ถœ'):
81
+ format_id = next(key for key, value in st.session_state.formats.items() if value['info'] == format_selection)
82
  try:
83
  # ์„ธ์…˜ ์ƒํƒœ์˜ youtube_url ์‚ฌ์šฉ
84
  download_video(st.session_state.youtube_url, format_id)