Spaces:
Runtime error
Runtime error
Update ffmpeg_runner.py
#13
by kajalan - opened
191 unmodified lines1921931941951961971981992002012022032042052062072082092102112122132142152162172182 unmodified lines2212222232242252262272283 unmodified lines232233234235236237238239240241242243244191 unmodified linesdef _gdrive_download_keyed(url: str, dest_dir: Path, key: str) -> Path:"""Download a GDrive URL using gdown, renamed to `key + original_ext`.Used by download_input_files so placeholders resolve with correct extensions."""import gdownfile_id = _extract_gdrive_id(url)gdrive_url = f"https://drive.google.com/uc?id={file_id}&confirm=t" if file_id else url# Download to dest_dir — gdown uses the Drive filename automaticallyoutput = gdown.download(gdrive_url, output=str(dest_dir) + "/", quiet=True, fuzzy=True)if not output:raise RuntimeError("gdown failed to download the file. ""Ensure it is publicly shared (Anyone with the link → Viewer).")downloaded = Path(output)if not downloaded.exists() or downloaded.stat().st_size == 0:downloaded.unlink(missing_ok=True)raise RuntimeError("gdown returned an empty file.")# Rename to key + extension so {{placeholder}} resolves correctlyext = downloaded.suffix or ".bin"final_path = dest_dir / f"{key}{ext}"if downloaded != final_path:downloaded.rename(final_path)2 unmodified linesdef _gdrive_download_sync(url: str, dest_dir: Path) -> Path:"""Download a GDrive URL to a temp file using gdown.gdown handles virus-scan confirmation automatically."""import tempfileimport gdown3 unmodified linestmp.close()tmp_path = Path(tmp.name)gdrive_url = f"https://drive.google.com/uc?id={file_id}&confirm=t" if file_id else urlresult = gdown.download(gdrive_url, str(tmp_path), quiet=True, fuzzy=True)if not result or not tmp_path.exists() or tmp_path.stat().st_size == 0:tmp_path.unlink(missing_ok=True)raise RuntimeError(f"gdown failed to download the file. ""Ensure it is publicly shared (Anyone with the link → Viewer).")return tmp_path191 unmodified lines1921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412 unmodified lines2442452462472482492502513 unmodified lines255256257258259260261262263264265266267268269270271272273274275191 unmodified linesdef _gdrive_download_keyed(url: str, dest_dir: Path, key: str) -> Path:"""Download a GDrive URL using gdown, renamed to `key + original_ext`.Uses gdown's id= parameter (most reliable path for large files with virus-scan warning)."""import gdownfile_id = _extract_gdrive_id(url)if not file_id:raise RuntimeError(f"Could not extract a Google Drive file ID from URL: {url!r}. ""Expected a /file/d/ID or ?id=ID format.")# Use id= kwarg — bypasses the virus-scan confirmation page reliably in gdown 4.x+output = gdown.download(id=file_id,output=str(dest_dir) + "/",quiet=True,fuzzy=True,use_cookies=False, # avoids stale cookie issues in server environments)if not output:raise RuntimeError("gdown failed to download the Google Drive file. ""Ensure it is publicly shared (Anyone with the link → Viewer).")downloaded = Path(output)# Guard: gdown sometimes saves the HTML warning page instead of the fileif not downloaded.exists() or downloaded.stat().st_size == 0:downloaded.unlink(missing_ok=True)raise RuntimeError("gdown returned an empty file — check Drive sharing permissions.")if downloaded.stat().st_size < 1024:# Likely got the HTML "confirm download" pagecontent = downloaded.read_bytes()downloaded.unlink(missing_ok=True)if b"<html" in content.lower() or b"<!doctype" in content.lower():raise RuntimeError("gdown received an HTML page instead of the media file. ""The file may not be publicly shared, or it requires sign-in. ""Set sharing to 'Anyone with the link → Viewer'.")# Rename to key + extension so {{placeholder}} resolves correctlyext = downloaded.suffix or ".mp4"final_path = dest_dir / f"{key}{ext}"if downloaded != final_path:downloaded.rename(final_path)2 unmodified linesdef _gdrive_download_sync(url: str, dest_dir: Path) -> Path:"""Download a GDrive URL to a temp file using gdown (used by ffprobe).Uses id= parameter to bypass virus-scan confirmation for large files."""import tempfileimport gdown3 unmodified linestmp.close()tmp_path = Path(tmp.name)if file_id:result = gdown.download(id=file_id,output=str(tmp_path),quiet=True,fuzzy=True,use_cookies=False,)else:result = gdown.download(url, str(tmp_path), quiet=True, fuzzy=True, use_cookies=False)if not result or not tmp_path.exists() or tmp_path.stat().st_size == 0:tmp_path.unlink(missing_ok=True)raise RuntimeError("gdown failed to download the file. ""Ensure it is publicly shared (Anyone with the link → Viewer).")return tmp_path
ffmpeg_runner.py+43-12