Migrate search to Vertex AI and enhance preview modal
All checks were successful
build-push / docker (push) Successful in 4m1s
All checks were successful
build-push / docker (push) Successful in 4m1s
This commit is contained in:
@@ -28,7 +28,7 @@ def run(cmd):
|
||||
|
||||
def parse_duration(value):
|
||||
if value is None:
|
||||
return "00:00:10"
|
||||
return "00:00:00"
|
||||
total = int(float(value))
|
||||
hours = total // 3600
|
||||
minutes = (total % 3600) // 60
|
||||
@@ -61,6 +61,24 @@ def build_quality_options(formats: List[dict]):
|
||||
return options
|
||||
|
||||
|
||||
def preview_stream_url(url):
|
||||
candidates = [
|
||||
"best[ext=mp4]/best",
|
||||
"best",
|
||||
]
|
||||
for selector in candidates:
|
||||
proc = subprocess.run(
|
||||
["yt-dlp", "-g", "--no-playlist", "-f", selector, url],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
)
|
||||
if proc.returncode == 0:
|
||||
lines = [line.strip() for line in proc.stdout.splitlines() if line.strip()]
|
||||
if lines:
|
||||
return lines[0]
|
||||
return ""
|
||||
|
||||
|
||||
def probe(url):
|
||||
cmd = ["yt-dlp", "--dump-single-json", "--no-playlist", url]
|
||||
proc = run(cmd)
|
||||
@@ -71,6 +89,7 @@ def probe(url):
|
||||
preview = {
|
||||
"title": payload.get("title") or "Untitled",
|
||||
"thumbnail": thumbnail,
|
||||
"previewStreamUrl": preview_stream_url(url),
|
||||
"durationSeconds": duration or 0,
|
||||
"duration": parse_duration(duration),
|
||||
"startDefault": "00:00:00",
|
||||
@@ -85,8 +104,8 @@ def main():
|
||||
parser.add_argument("--mode", choices=["probe", "download"], default="download")
|
||||
parser.add_argument("--url", required=True)
|
||||
parser.add_argument("--start", default="00:00:00")
|
||||
parser.add_argument("--end", default="00:00:10")
|
||||
parser.add_argument("--output", required=True)
|
||||
parser.add_argument("--end", default="00:00:00")
|
||||
parser.add_argument("--output", default="")
|
||||
parser.add_argument("--quality", default="best")
|
||||
args = parser.parse_args()
|
||||
|
||||
@@ -94,6 +113,8 @@ def main():
|
||||
probe(args.url)
|
||||
return
|
||||
|
||||
if not args.output:
|
||||
raise RuntimeError("output path is required for download mode")
|
||||
os.makedirs(os.path.dirname(args.output), exist_ok=True)
|
||||
emit("starting", 5, "Resolving media stream")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user