feat: DeepSeek API + transcript fixes; add OAuth captions scope
This commit is contained in:
+14
-17
@@ -28,38 +28,35 @@ Keep the entire summary under 150 words. Be extremely direct so I can decide in
|
||||
Transcript:
|
||||
{transcript}"""
|
||||
|
||||
COOKIES_PATH = None
|
||||
for p in [os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "config/cookies.txt"),
|
||||
"/app/config/cookies.txt"]:
|
||||
if os.path.exists(p):
|
||||
COOKIES_PATH = p
|
||||
break
|
||||
|
||||
def download_transcript(video_id: str) -> str:
|
||||
try:
|
||||
session = requests.Session()
|
||||
session.headers.update({
|
||||
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
|
||||
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36",
|
||||
"Accept-Language": "en-US,en;q=0.9"
|
||||
})
|
||||
# Load cookies to bypass YouTube IP block
|
||||
for p in [os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "config/cookies.txt"),
|
||||
"/app/config/cookies.txt"]:
|
||||
if os.path.exists(p):
|
||||
from http.cookiejar import MozillaCookieJar
|
||||
cj = MozillaCookieJar(p)
|
||||
cj.load(ignore_discard=True, ignore_expires=True)
|
||||
session.cookies.update({c.name: c.value for c in cj})
|
||||
break
|
||||
if COOKIES_PATH:
|
||||
from http.cookiejar import MozillaCookieJar
|
||||
cj = MozillaCookieJar(COOKIES_PATH)
|
||||
cj.load(ignore_discard=True, ignore_expires=True)
|
||||
session.cookies.update({c.name: c.value for c in cj})
|
||||
transcript_list = YouTubeTranscriptApi(http_client=session).list(video_id)
|
||||
|
||||
# Try to find manual transcripts in preferred languages
|
||||
try:
|
||||
transcript = transcript_list.find_manually_created_transcript(['en', 'zh-Hans', 'zh-Hant', 'zh', 'ja'])
|
||||
except Exception:
|
||||
# Fallback to generated (auto-captions) in preferred languages
|
||||
try:
|
||||
transcript = transcript_list.find_generated_transcript(['en', 'zh-Hans', 'zh-Hant', 'zh', 'ja'])
|
||||
except Exception:
|
||||
# Fallback to any transcript
|
||||
transcript = next(iter(transcript_list))
|
||||
|
||||
parts = transcript.fetch()
|
||||
text = " ".join([part["text"] for part in parts])
|
||||
return text
|
||||
return " ".join([part["text"] for part in parts])
|
||||
except Exception as e:
|
||||
log.warning(f"Failed to fetch transcript for {video_id}: {e}")
|
||||
return None
|
||||
|
||||
Reference in New Issue
Block a user