Spaces:
Sleeping
Sleeping
screenshot_path = screenshot_youtube_video(video_id, entry['start'])
Browse files
app.py
CHANGED
@@ -51,7 +51,7 @@ OUTPUT_PATH = 'videos'
|
|
51 |
OPEN_AI_KEY = os.getenv("OPEN_AI_KEY")
|
52 |
client = OpenAI(api_key=OPEN_AI_KEY)
|
53 |
|
54 |
-
#
|
55 |
def init_drive_service():
|
56 |
credentials_json_string = os.getenv("GOOGLE_APPLICATION_CREDENTIALS_JSON")
|
57 |
credentials_dict = json.loads(credentials_json_string)
|
@@ -158,6 +158,9 @@ def update_file_on_drive(service, file_id, file_content):
|
|
158 |
|
159 |
print(f"文件已更新,文件ID: {updated_file['id']}")
|
160 |
|
|
|
|
|
|
|
161 |
def process_file(file):
|
162 |
# 读取文件
|
163 |
if file.name.endswith('.csv'):
|
@@ -239,7 +242,7 @@ def process_transcript_and_screenshots(video_id):
|
|
239 |
# 处理逐字稿中的每个条目,检查并上传截图
|
240 |
for entry in transcript:
|
241 |
if 'img_src' not in entry:
|
242 |
-
screenshot_youtube_video(video_id, entry['start'])
|
243 |
img_file_id = upload_img_directly(service, f"{video_id}_{entry['start']}.jpg", folder_id, screenshot_path)
|
244 |
set_public_permission(service, img_file_id)
|
245 |
img_src = f"https://drive.google.com/uc?export=view&id={img_file_id}"
|
@@ -324,9 +327,12 @@ def download_youtube_video(youtube_id, output_path=OUTPUT_PATH):
|
|
324 |
|
325 |
def screenshot_youtube_video(youtube_id, snapshot_sec):
|
326 |
video_path = f'{OUTPUT_PATH}/{youtube_id}.mp4'
|
|
|
327 |
with VideoFileClip(video_path) as video:
|
328 |
screenshot_path = f'{OUTPUT_PATH}/{file_name}'
|
329 |
video.save_frame(screenshot_path, snapshot_sec)
|
|
|
|
|
330 |
|
331 |
def get_screenshot_from_video(video_link, start_time):
|
332 |
# 实现从视频中提取帧的逻辑
|
|
|
51 |
OPEN_AI_KEY = os.getenv("OPEN_AI_KEY")
|
52 |
client = OpenAI(api_key=OPEN_AI_KEY)
|
53 |
|
54 |
+
# # ====drive====初始化Google Drive服务
|
55 |
def init_drive_service():
|
56 |
credentials_json_string = os.getenv("GOOGLE_APPLICATION_CREDENTIALS_JSON")
|
57 |
credentials_dict = json.loads(credentials_json_string)
|
|
|
158 |
|
159 |
print(f"文件已更新,文件ID: {updated_file['id']}")
|
160 |
|
161 |
+
|
162 |
+
# ====drive====
|
163 |
+
|
164 |
def process_file(file):
|
165 |
# 读取文件
|
166 |
if file.name.endswith('.csv'):
|
|
|
242 |
# 处理逐字稿中的每个条目,检查并上传截图
|
243 |
for entry in transcript:
|
244 |
if 'img_src' not in entry:
|
245 |
+
screenshot_path = screenshot_youtube_video(video_id, entry['start'])
|
246 |
img_file_id = upload_img_directly(service, f"{video_id}_{entry['start']}.jpg", folder_id, screenshot_path)
|
247 |
set_public_permission(service, img_file_id)
|
248 |
img_src = f"https://drive.google.com/uc?export=view&id={img_file_id}"
|
|
|
327 |
|
328 |
def screenshot_youtube_video(youtube_id, snapshot_sec):
|
329 |
video_path = f'{OUTPUT_PATH}/{youtube_id}.mp4'
|
330 |
+
file_name = f"{youtube_id}_{snapshot_sec}.jpg"
|
331 |
with VideoFileClip(video_path) as video:
|
332 |
screenshot_path = f'{OUTPUT_PATH}/{file_name}'
|
333 |
video.save_frame(screenshot_path, snapshot_sec)
|
334 |
+
|
335 |
+
return screenshot_path
|
336 |
|
337 |
def get_screenshot_from_video(video_link, start_time):
|
338 |
# 实现从视频中提取帧的逻辑
|