openrouter

This commit is contained in:
2026-02-17 09:30:35 +00:00
parent e8492c3fa9
commit 95bd651377
4 changed files with 167 additions and 17 deletions

View File

@@ -49,18 +49,21 @@ def get_subtitles(url, lang='en'):
f.unlink()
# First, get video info
info_cmd = [yt_dlp, '--dump-json', '--no-download', url]
try:
result = subprocess.run(info_cmd, capture_output=True, text=True, timeout=30)
if result.returncode == 0:
title = "Unknown"
info_cmd = [yt_dlp, '--js-runtimes', 'node', '--dump-json', '--no-download', url]
result = subprocess.run(info_cmd, capture_output=True, text=True, timeout=30)
print(f"INFO: returncode={result.returncode}, stderr={result.stderr[:200]}", file=sys.stderr)
if result.returncode == 0:
try:
info = json.loads(result.stdout)
title = info.get('title', 'Unknown')
duration = info.get('duration', 0)
print(f"Title: {title}", file=sys.stderr)
print(f"Duration: {duration//60}:{duration%60:02d}", file=sys.stderr)
except Exception as e:
title = "Unknown"
print(f"Could not get video info: {e}", file=sys.stderr)
except Exception as e:
print(f"JSON parse error: {e}", file=sys.stderr)
else:
print(f"yt-dlp failed: {result.stderr[:500]}", file=sys.stderr)
# Try to get subtitles in order of preference
lang_preferences = [lang, 'ro', 'en', 'en-US', 'en-GB']
@@ -69,6 +72,7 @@ def get_subtitles(url, lang='en'):
# Try manual subtitles first
cmd = [
yt_dlp,
'--js-runtimes', 'node',
'--write-subs',
'--sub-langs', try_lang,
'--skip-download',
@@ -88,6 +92,7 @@ def get_subtitles(url, lang='en'):
for try_lang in lang_preferences:
cmd = [
yt_dlp,
'--js-runtimes', 'node',
'--write-auto-subs',
'--sub-langs', try_lang,
'--skip-download',
@@ -104,7 +109,7 @@ def get_subtitles(url, lang='en'):
if text:
return title, text
return title, None
return title or "Unknown", None
if __name__ == '__main__':
if len(sys.argv) < 2: