youngtsai commited on
Commit
44c77f0
·
1 Parent(s): 62dae33

if is_new_transcript:

Browse files
Files changed (1) hide show
  1. app.py +15 -9
app.py CHANGED
@@ -489,6 +489,7 @@ def process_transcript_and_screenshots_on_gcs(video_id):
489
  transcript_file_name = f'{video_id}_transcript.json'
490
  transcript_blob_name = f"{video_id}/{transcript_file_name}"
491
  # 检查逐字稿是否存在
 
492
  is_transcript_exists = GCS_SERVICE.check_file_exists(bucket_name, transcript_blob_name)
493
  if not is_transcript_exists:
494
  # 从YouTube获取逐字稿并上传
@@ -507,6 +508,7 @@ def process_transcript_and_screenshots_on_gcs(video_id):
507
 
508
  transcript_text = json.dumps(transcript, ensure_ascii=False, indent=2)
509
  upload_file_to_gcs_with_json_string(gcs_client, bucket_name, transcript_blob_name, transcript_text)
 
510
  else:
511
  # 逐字稿已存在,下载逐字稿内容
512
  print("逐字稿已存在于GCS中")
@@ -542,15 +544,19 @@ def process_transcript_and_screenshots_on_gcs(video_id):
542
  img_file_id = upload_img_and_get_public_url(gcs_client, bucket_name, screenshot_blob_name, screenshot_path)
543
  entry['img_file_id'] = img_file_id
544
  print(f"截图已上传到GCS: {img_file_id}")
545
-
546
- # 更新逐字稿文件
547
- print("===更新逐字稿文件===")
548
- print(transcript)
549
- print("===更新逐字稿文件===")
550
- updated_transcript_text = json.dumps(transcript, ensure_ascii=False, indent=2)
551
- upload_file_to_gcs_with_json_string(gcs_client, bucket_name, transcript_blob_name, updated_transcript_text)
552
- print("逐字稿已更新,包括截图链接")
553
- updated_transcript_json = json.loads(updated_transcript_text)
 
 
 
 
554
 
555
  return updated_transcript_json
556
 
 
489
  transcript_file_name = f'{video_id}_transcript.json'
490
  transcript_blob_name = f"{video_id}/{transcript_file_name}"
491
  # 检查逐字稿是否存在
492
+ is_new_transcript = False
493
  is_transcript_exists = GCS_SERVICE.check_file_exists(bucket_name, transcript_blob_name)
494
  if not is_transcript_exists:
495
  # 从YouTube获取逐字稿并上传
 
508
 
509
  transcript_text = json.dumps(transcript, ensure_ascii=False, indent=2)
510
  upload_file_to_gcs_with_json_string(gcs_client, bucket_name, transcript_blob_name, transcript_text)
511
+ is_new_transcript = True
512
  else:
513
  # 逐字稿已存在,下载逐字稿内容
514
  print("逐字稿已存在于GCS中")
 
544
  img_file_id = upload_img_and_get_public_url(gcs_client, bucket_name, screenshot_blob_name, screenshot_path)
545
  entry['img_file_id'] = img_file_id
546
  print(f"截图已上传到GCS: {img_file_id}")
547
+ is_new_transcript = True
548
+
549
+ if is_new_transcript:
550
+ # 更新逐字稿文件
551
+ print("===更新逐字稿文件===")
552
+ print(transcript)
553
+ print("===更新逐字稿文件===")
554
+ updated_transcript_text = json.dumps(transcript, ensure_ascii=False, indent=2)
555
+ upload_file_to_gcs_with_json_string(gcs_client, bucket_name, transcript_blob_name, updated_transcript_text)
556
+ print("逐字稿已更新,包括截图链接")
557
+ updated_transcript_json = json.loads(updated_transcript_text)
558
+ else:
559
+ updated_transcript_json = transcript
560
 
561
  return updated_transcript_json
562