lcjln commited on
Commit
1dae269
Β·
verified Β·
1 Parent(s): 5b59009

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -21
app.py CHANGED
@@ -1,5 +1,3 @@
1
- import os
2
- import time
3
  import streamlit as st
4
  import pandas as pd
5
  import plotly.graph_objects as go
@@ -8,6 +6,8 @@ import datetime
8
  import re
9
  import requests
10
  import yt_dlp
 
 
11
 
12
  # νŽ˜μ΄μ§€ ꡬ성을 'wide'둜 μ„€μ •ν•˜μ—¬ μ—¬λ°± μ΅œμ†Œν™”
13
  st.set_page_config(layout="wide")
@@ -115,6 +115,11 @@ def crawl_chats(vod_url):
115
 
116
  return "\n".join(chat_logs), chat_counts, laugh_counts
117
 
 
 
 
 
 
118
  # μ„ νƒλœ μ‹œκ°„λŒ€λ₯Ό ν‘œμ‹œ 및 μ‚­μ œ κΈ°λŠ₯
119
  def display_selected_times():
120
  if st.session_state['selected_times']:
@@ -140,13 +145,13 @@ def download_clips():
140
  # yt-dlp λ‹€μš΄λ‘œλ“œ λͺ…λ Ήμ–΄ μ‹€ν–‰
141
  output_filename = f"clip_{idx + 1}.mp4"
142
  ydl_opts = {
143
- 'outtmpl': os.path.join(os.path.expanduser("~/Downloads"), output_filename), # Downloads 폴더에 μ €μž₯
144
  'download_sections': [f"*{start_time_str}-{end_time_str}"]
145
  }
146
 
147
  st.write(f"λ‹€μš΄λ‘œλ“œ 쀑: {start_time_str} ~ {end_time_str} | 파일λͺ…: {output_filename}")
148
  with yt_dlp.YoutubeDL(ydl_opts) as ydl:
149
- ydl.download([vod_url]) # μ›λž˜ URL μ‚¬μš©
150
 
151
  # λ²„νŠΌμ„ λˆŒλ €μ„ λ•Œ μ±„νŒ… 크둀링 μ‹œμž‘
152
  if 'chat_logs' not in st.session_state:
@@ -226,24 +231,13 @@ if st.session_state['chat_logs']:
226
  # κ·Έλž˜ν”„ 좜λ ₯
227
  st.plotly_chart(fig, use_container_width=True)
228
 
229
- # μ‹œκ°„ μž…λ ₯ ν•„λ“œ
230
- col1, col2 = st.columns([1, 1])
231
- with col1:
232
- hour = st.number_input("μ‹œκ°„", min_value=0, max_value=23, value=0)
233
- with col2:
234
- minute = st.number_input("λΆ„", min_value=0, max_value=59, value=0)
235
-
236
- # μ„ νƒλœ μ‹œκ°„λŒ€ μΆ”κ°€ λ²„νŠΌ
237
- if st.button("μ‹œκ°„λŒ€ 선택"):
238
- selected_time = f"{hour:02}:{minute:02}:00" # "HH:MM:SS" ν˜•μ‹μœΌλ‘œ λ³€ν™˜
239
- if selected_time not in st.session_state['selected_times']:
240
- st.session_state['selected_times'].append(selected_time)
241
-
242
- # μž…λ ₯ μΉΈ μ΄ˆκΈ°ν™”
243
- hour = 0
244
- minute = 0
245
 
246
- # μ„ νƒλœ μ‹œκ°„λŒ€λ₯Ό ν‘œμ‹œ 및 μ‚­μ œ κΈ°λŠ₯
247
  display_selected_times()
248
 
249
  # λ‹€μš΄λ‘œλ“œ λ²„νŠΌ ν‘œμ‹œ
 
 
 
1
  import streamlit as st
2
  import pandas as pd
3
  import plotly.graph_objects as go
 
6
  import re
7
  import requests
8
  import yt_dlp
9
+ import os
10
+ import time
11
 
12
  # νŽ˜μ΄μ§€ ꡬ성을 'wide'둜 μ„€μ •ν•˜μ—¬ μ—¬λ°± μ΅œμ†Œν™”
13
  st.set_page_config(layout="wide")
 
115
 
116
  return "\n".join(chat_logs), chat_counts, laugh_counts
117
 
118
+ # ν΄λ¦­ν•œ μ‹œκ°„λŒ€λ₯Ό 선택 및 좜λ ₯
119
+ def add_selected_time(time):
120
+ if time not in st.session_state['selected_times']:
121
+ st.session_state['selected_times'].append(time)
122
+
123
  # μ„ νƒλœ μ‹œκ°„λŒ€λ₯Ό ν‘œμ‹œ 및 μ‚­μ œ κΈ°λŠ₯
124
  def display_selected_times():
125
  if st.session_state['selected_times']:
 
145
  # yt-dlp λ‹€μš΄λ‘œλ“œ λͺ…λ Ήμ–΄ μ‹€ν–‰
146
  output_filename = f"clip_{idx + 1}.mp4"
147
  ydl_opts = {
148
+ 'outtmpl': output_filename,
149
  'download_sections': [f"*{start_time_str}-{end_time_str}"]
150
  }
151
 
152
  st.write(f"λ‹€μš΄λ‘œλ“œ 쀑: {start_time_str} ~ {end_time_str} | 파일λͺ…: {output_filename}")
153
  with yt_dlp.YoutubeDL(ydl_opts) as ydl:
154
+ ydl.download([vod_url])
155
 
156
  # λ²„νŠΌμ„ λˆŒλ €μ„ λ•Œ μ±„νŒ… 크둀링 μ‹œμž‘
157
  if 'chat_logs' not in st.session_state:
 
231
  # κ·Έλž˜ν”„ 좜λ ₯
232
  st.plotly_chart(fig, use_container_width=True)
233
 
234
+ # κ·Έλž˜ν”„ 클릭 μ‹œ μ‹œκ°„λŒ€ μΆ”κ°€
235
+ click_data = st.session_state.get('click_data')
236
+ if click_data:
237
+ time_selected = click_data['points'][0]['x']
238
+ add_selected_time(time_selected)
 
 
 
 
 
 
 
 
 
 
 
239
 
240
+ # μ„ νƒλœ μ‹œκ°„λŒ€ ν‘œμ‹œ
241
  display_selected_times()
242
 
243
  # λ‹€μš΄λ‘œλ“œ λ²„νŠΌ ν‘œμ‹œ