Spaces:
Running
Running
Fix Google Drive direct video downloads
Browse files
app.py
CHANGED
|
@@ -306,6 +306,10 @@ def drive_file_id(link):
|
|
| 306 |
return next(group for group in match.groups() if group)
|
| 307 |
|
| 308 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 309 |
def drive_file_name(content_disposition, file_id):
|
| 310 |
message = Message()
|
| 311 |
if content_disposition:
|
|
@@ -321,7 +325,7 @@ def drive_file_name(content_disposition, file_id):
|
|
| 321 |
|
| 322 |
async def download_drive_file(link, destination):
|
| 323 |
file_id = drive_file_id(link)
|
| 324 |
-
url =
|
| 325 |
total = 0
|
| 326 |
async with httpx.AsyncClient(follow_redirects=True, timeout=300) as client:
|
| 327 |
async with client.stream("GET", url) as response:
|
|
@@ -576,7 +580,7 @@ def probe_drive(payload: dict):
|
|
| 576 |
result = {"link": str(link)}
|
| 577 |
try:
|
| 578 |
file_id = drive_file_id(str(link))
|
| 579 |
-
with httpx.stream("GET",
|
| 580 |
content_type = response.headers.get("content-type", "")
|
| 581 |
content_disposition = response.headers.get("content-disposition", "")
|
| 582 |
size = int(response.headers.get("content-length", "0") or 0)
|
|
|
|
| 306 |
return next(group for group in match.groups() if group)
|
| 307 |
|
| 308 |
|
| 309 |
+
def drive_download_url(file_id):
|
| 310 |
+
return f"https://drive.usercontent.google.com/download?id={file_id}&export=download&confirm=t"
|
| 311 |
+
|
| 312 |
+
|
| 313 |
def drive_file_name(content_disposition, file_id):
|
| 314 |
message = Message()
|
| 315 |
if content_disposition:
|
|
|
|
| 325 |
|
| 326 |
async def download_drive_file(link, destination):
|
| 327 |
file_id = drive_file_id(link)
|
| 328 |
+
url = drive_download_url(file_id)
|
| 329 |
total = 0
|
| 330 |
async with httpx.AsyncClient(follow_redirects=True, timeout=300) as client:
|
| 331 |
async with client.stream("GET", url) as response:
|
|
|
|
| 580 |
result = {"link": str(link)}
|
| 581 |
try:
|
| 582 |
file_id = drive_file_id(str(link))
|
| 583 |
+
with httpx.stream("GET", drive_download_url(file_id), follow_redirects=True, timeout=30) as response:
|
| 584 |
content_type = response.headers.get("content-type", "")
|
| 585 |
content_disposition = response.headers.get("content-disposition", "")
|
| 586 |
size = int(response.headers.get("content-length", "0") or 0)
|