m8chaa commited on
Commit
bc066d5
ยท
verified ยท
1 Parent(s): 6c40d74

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +51 -70
app.py CHANGED
@@ -343,7 +343,7 @@ Output must be valid JSON with "receipts" and "busi_cards" arrays."""
343
  ์ด๋ฆ„: ๋ฐ•์žฅ์›
344
  ํšŒ์‚ฌ๋ช…: ์•„์ดํ”„๋ฆฌ๋งˆ
345
  ์†Œ์† ๋ฐ ์ง์œ„: ํŒ€์žฅ/์ •์ฑ…์‚ฌ์—…ํŒ€ R&D์‚ฌ์—…์‹ค
346
- ์ฃผ์†Œ: ๊ฒฝ๊ธฐ๋„ ํ™”์„ฑ์‹œ ์ •๋‚จ๋ฉด ๋งŒ๋…„๋กœ 98๋ฒˆ๊ธธ 55 (์šฐํŽธ๋ฒˆํ˜ธ) 18523
347
  ์ „ํ™”: (031) 000-0000
348
  ํœด๋Œ€ํฐ: (031) 000-0000
349
  ํŒฉ์Šค: 010-0000-0000
@@ -586,76 +586,57 @@ async def process_youtube_video(video_id: str, video_title: str = "") -> dict:
586
  """
587
  try:
588
  try:
589
- import requests
590
- import blackboxprotobuf
591
- import base64
592
-
593
- def getBase64Protobuf(message, typedef):
594
- data = blackboxprotobuf.encode_message(message, typedef)
595
- return base64.b64encode(data).decode('ascii')
596
-
597
- # Try to get auto-generated captions
598
- message = {
599
- '1': 'asr',
600
- '2': 'ko', # Try Korean first
601
  }
602
 
603
- typedef = {
604
- '1': {'type': 'string'},
605
- '2': {'type': 'string'},
606
- }
607
-
608
- two = getBase64Protobuf(message, typedef)
609
-
610
- message = {
611
- '1': video_id,
612
- '2': two,
613
- }
614
-
615
- typedef = {
616
- '1': {'type': 'string'},
617
- '2': {'type': 'string'},
618
- }
619
-
620
- params = getBase64Protobuf(message, typedef)
621
-
622
- url = 'https://www.youtube.com/youtubei/v1/get_transcript'
623
- headers = {
624
- 'Content-Type': 'application/json'
625
- }
626
- data = {
627
- 'context': {
628
- 'client': {
629
- 'clientName': 'WEB',
630
- 'clientVersion': '2.20240313'
631
- }
632
- },
633
- 'params': params
634
- }
635
-
636
- response = requests.post(url, headers=headers, json=data).json()
637
-
638
- if 'actions' not in response:
639
- # If Korean fails, try English
640
- message['2'] = getBase64Protobuf({'1': 'asr', '2': 'en'}, typedef)
641
- params = getBase64Protobuf(message, typedef)
642
- data['params'] = params
643
- response = requests.post(url, headers=headers, json=data).json()
644
-
645
- if 'actions' in response:
646
- transcript_parts = []
647
- for action in response['actions'][0]['updateEngagementPanelAction']['content']['transcriptRenderer']['content']['transcriptSearchPanelRenderer']['body']['transcriptSegmentListRenderer']['initialSegments']:
648
- segment = action['transcriptSegmentRenderer']['snippet']['runs'][0]['text']
649
- transcript_parts.append(segment)
650
 
651
- full_transcript = " ".join(transcript_parts)
652
- else:
653
- return {
654
- "title": video_title,
655
- "summary": "์ž๋ง‰์„ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.",
656
- "key_points": [],
657
- "timestamps": {}
658
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
659
 
660
  except Exception as e:
661
  logging.error(f"Failed to get captions: {str(e)}")
@@ -1026,7 +1007,7 @@ async def search_business_info(company_name: str, address: str, spreadsheet_id:
1026
  matches.append({
1027
  'score': total_score,
1028
  'data': {
1029
- "์‚ฌ๏ฟฝ๏ฟฝ์ž๋ฒˆํ˜ธ": str(row[2]) if len(row) > 2 else "",
1030
  "๋Œ€ํ‘œ์ž๋ช…": str(row[11]) if len(row) > 11 else "",
1031
  "์ „ํ™”๋ฒˆํ˜ธ": str(row[13]) if len(row) > 13 else "",
1032
  "์šฐํŽธ๋ฒˆํ˜ธ": str(row[14]) if len(row) > 14 else "",
@@ -1211,7 +1192,7 @@ async def process_photo(data_json: str = Form(...), user_id: str = Form(...)):
1211
 
1212
  try:
1213
  if data['isContacts']:
1214
- await update_user_sheet(user_data['gDrive_metadata']['spreadsheet'], "์—ฐ๋ฝ์ฒ˜", data['data'], True)
1215
  transaction_data['no_contacts'] += len(data['data'])
1216
  transaction_ref.update({'no_contacts': transaction_data['no_contacts']})
1217
 
 
343
  ์ด๋ฆ„: ๋ฐ•์žฅ์›
344
  ํšŒ์‚ฌ๋ช…: ์•„์ดํ”„๋ฆฌ๋งˆ
345
  ์†Œ์† ๋ฐ ์ง์œ„: ํŒ€์žฅ/์ •์ฑ…์‚ฌ์—…ํŒ€ R&D์‚ฌ์—…์‹ค
346
+ ์ฃผ๏ฟฝ๏ฟฝ๏ฟฝ: ๊ฒฝ๊ธฐ๋„ ํ™”์„ฑ์‹œ ์ •๋‚จ๋ฉด ๋งŒ๋…„๋กœ 98๋ฒˆ๊ธธ 55 (์šฐํŽธ๋ฒˆํ˜ธ) 18523
347
  ์ „ํ™”: (031) 000-0000
348
  ํœด๋Œ€ํฐ: (031) 000-0000
349
  ํŒฉ์Šค: 010-0000-0000
 
586
  """
587
  try:
588
  try:
589
+ import yt_dlp
590
+
591
+ ydl_opts = {
592
+ 'writesubtitles': True,
593
+ 'subtitleslangs': ['ko', 'en'], # Try Korean first, then English
594
+ 'skip_download': True,
595
+ 'quiet': True,
596
+ 'writeautomaticsub': True # Enable automatic captions
 
 
 
 
597
  }
598
 
599
+ with yt_dlp.YoutubeDL(ydl_opts) as ydl:
600
+ info = ydl.extract_info(f"https://www.youtube.com/watch?v={video_id}", download=False)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
601
 
602
+ # Try to get subtitles
603
+ subtitles = info.get('requested_subtitles', {})
604
+ if subtitles:
605
+ # Try Korean first
606
+ if 'ko' in subtitles:
607
+ full_transcript = subtitles['ko']
608
+ # Fall back to English if Korean not available
609
+ elif 'en' in subtitles:
610
+ full_transcript = subtitles['en']
611
+ else:
612
+ return {
613
+ "title": video_title,
614
+ "summary": "์ž๋ง‰์„ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.",
615
+ "key_points": [],
616
+ "timestamps": {}
617
+ }
618
+ else:
619
+ # Try automatic captions if no manual subtitles
620
+ auto_captions = info.get('automatic_captions', {})
621
+ if auto_captions:
622
+ if 'ko' in auto_captions:
623
+ full_transcript = auto_captions['ko'][0]['text']
624
+ elif 'en' in auto_captions:
625
+ full_transcript = auto_captions['en'][0]['text']
626
+ else:
627
+ return {
628
+ "title": video_title,
629
+ "summary": "์ž๋ง‰์„ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.",
630
+ "key_points": [],
631
+ "timestamps": {}
632
+ }
633
+ else:
634
+ return {
635
+ "title": video_title,
636
+ "summary": "์ž๋ง‰์„ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.",
637
+ "key_points": [],
638
+ "timestamps": {}
639
+ }
640
 
641
  except Exception as e:
642
  logging.error(f"Failed to get captions: {str(e)}")
 
1007
  matches.append({
1008
  'score': total_score,
1009
  'data': {
1010
+ "์‚ฌ์—…์ž๋ฒˆํ˜ธ": str(row[2]) if len(row) > 2 else "",
1011
  "๋Œ€ํ‘œ์ž๋ช…": str(row[11]) if len(row) > 11 else "",
1012
  "์ „ํ™”๋ฒˆํ˜ธ": str(row[13]) if len(row) > 13 else "",
1013
  "์šฐํŽธ๋ฒˆํ˜ธ": str(row[14]) if len(row) > 14 else "",
 
1192
 
1193
  try:
1194
  if data['isContacts']:
1195
+ await update_user_sheet(user_data['gDrive_metadata']['spreadsheet'], "์—ฐ๏ฟฝ๏ฟฝ์ฒ˜", data['data'], True)
1196
  transaction_data['no_contacts'] += len(data['data'])
1197
  transaction_ref.update({'no_contacts': transaction_data['no_contacts']})
1198