Update app.py
Browse files
app.py
CHANGED
|
@@ -343,7 +343,7 @@ Output must be valid JSON with "receipts" and "busi_cards" arrays."""
|
|
| 343 |
์ด๋ฆ: ๋ฐ์ฅ์
|
| 344 |
ํ์ฌ๋ช
: ์์ดํ๋ฆฌ๋ง
|
| 345 |
์์ ๋ฐ ์ง์: ํ์ฅ/์ ์ฑ
์ฌ์
ํ R&D์ฌ์
์ค
|
| 346 |
-
์ฃผ
|
| 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
|
| 590 |
-
|
| 591 |
-
|
| 592 |
-
|
| 593 |
-
|
| 594 |
-
|
| 595 |
-
|
| 596 |
-
|
| 597 |
-
# Try to get auto-generated captions
|
| 598 |
-
message = {
|
| 599 |
-
'1': 'asr',
|
| 600 |
-
'2': 'ko', # Try Korean first
|
| 601 |
}
|
| 602 |
|
| 603 |
-
|
| 604 |
-
|
| 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 |
-
|
| 652 |
-
|
| 653 |
-
|
| 654 |
-
|
| 655 |
-
|
| 656 |
-
|
| 657 |
-
|
| 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 |
-
"์ฌ
|
| 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'], "์ฐ
|
| 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 |
|