forked from DRMTalks/devine
Fix regression that broke pproxy
This commit is contained in:
parent
19ca567019
commit
9fff14af30
|
@ -1,5 +1,6 @@
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import asyncio
|
||||||
import html
|
import html
|
||||||
import logging
|
import logging
|
||||||
import math
|
import math
|
||||||
|
@ -791,13 +792,13 @@ class dl:
|
||||||
prepare_drm(drm)
|
prepare_drm(drm)
|
||||||
track.drm = [drm]
|
track.drm = [drm]
|
||||||
|
|
||||||
aria2c(
|
asyncio.run(aria2c(
|
||||||
uri=track.url,
|
uri=track.url,
|
||||||
out=save_path,
|
out=save_path,
|
||||||
headers=service.session.headers,
|
headers=service.session.headers,
|
||||||
proxy=proxy if track.needs_proxy else None,
|
proxy=proxy if track.needs_proxy else None,
|
||||||
progress=progress
|
progress=progress
|
||||||
)
|
))
|
||||||
|
|
||||||
track.path = save_path
|
track.path = save_path
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import asyncio
|
||||||
import subprocess
|
import subprocess
|
||||||
import textwrap
|
import textwrap
|
||||||
from functools import partial
|
from functools import partial
|
||||||
|
@ -11,7 +12,7 @@ from devine.core.console import console
|
||||||
from devine.core.utilities import get_binary_path, start_pproxy
|
from devine.core.utilities import get_binary_path, start_pproxy
|
||||||
|
|
||||||
|
|
||||||
def aria2c(
|
async def aria2c(
|
||||||
uri: Union[str, list[str]],
|
uri: Union[str, list[str]],
|
||||||
out: Path,
|
out: Path,
|
||||||
headers: Optional[dict] = None,
|
headers: Optional[dict] = None,
|
||||||
|
@ -83,25 +84,35 @@ def aria2c(
|
||||||
if proxy.lower().split(":")[0] != "http":
|
if proxy.lower().split(":")[0] != "http":
|
||||||
# HTTPS proxies are not supported by aria2(c).
|
# HTTPS proxies are not supported by aria2(c).
|
||||||
# Proxy the proxy via pproxy to access it as an HTTP proxy.
|
# Proxy the proxy via pproxy to access it as an HTTP proxy.
|
||||||
with start_pproxy(proxy) as pproxy_:
|
async with start_pproxy(proxy) as pproxy_:
|
||||||
return aria2c(uri, out, headers, pproxy_)
|
return await aria2c(uri, out, headers, pproxy_, silent, segmented, progress, *args)
|
||||||
arguments += ["--all-proxy", proxy]
|
arguments += ["--all-proxy", proxy]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
p = subprocess.Popen(
|
p = await asyncio.create_subprocess_exec(
|
||||||
[executable, *arguments],
|
executable,
|
||||||
|
*arguments,
|
||||||
stdin=subprocess.PIPE,
|
stdin=subprocess.PIPE,
|
||||||
stdout=[subprocess.PIPE, subprocess.DEVNULL][silent],
|
stdout=[subprocess.PIPE, subprocess.DEVNULL][silent]
|
||||||
universal_newlines=True
|
|
||||||
)
|
)
|
||||||
p._stdin_write(uri) # noqa
|
|
||||||
|
p.stdin.write(uri.encode())
|
||||||
|
await p.stdin.drain()
|
||||||
|
p.stdin.close()
|
||||||
|
|
||||||
if p.stdout:
|
if p.stdout:
|
||||||
is_dl_summary = False
|
is_dl_summary = False
|
||||||
aria_log_buffer = ""
|
aria_log_buffer = ""
|
||||||
for line in iter(p.stdout.readline, ""):
|
while True:
|
||||||
line = line.strip()
|
try:
|
||||||
if line:
|
chunk = await p.stdout.readuntil(b"\r")
|
||||||
|
except asyncio.IncompleteReadError as e:
|
||||||
|
chunk = e.partial
|
||||||
|
if not chunk:
|
||||||
|
break
|
||||||
|
for line in chunk.decode().strip().splitlines():
|
||||||
|
if not line:
|
||||||
|
continue
|
||||||
if line.startswith("Download Results"):
|
if line.startswith("Download Results"):
|
||||||
# we know it's 100% downloaded, but let's use the avg dl speed value
|
# we know it's 100% downloaded, but let's use the avg dl speed value
|
||||||
is_dl_summary = True
|
is_dl_summary = True
|
||||||
|
@ -133,7 +144,7 @@ def aria2c(
|
||||||
))
|
))
|
||||||
console.log(Text.from_ansi("\n[Aria2c]: " + aria_log_buffer))
|
console.log(Text.from_ansi("\n[Aria2c]: " + aria_log_buffer))
|
||||||
|
|
||||||
p.wait()
|
await p.wait()
|
||||||
|
|
||||||
if p.returncode != 0:
|
if p.returncode != 0:
|
||||||
raise subprocess.CalledProcessError(p.returncode, arguments)
|
raise subprocess.CalledProcessError(p.returncode, arguments)
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import asyncio
|
||||||
import base64
|
import base64
|
||||||
import logging
|
import logging
|
||||||
import math
|
import math
|
||||||
|
@ -467,13 +468,13 @@ class DASH:
|
||||||
segment_save_path.parent.mkdir(parents=True, exist_ok=True)
|
segment_save_path.parent.mkdir(parents=True, exist_ok=True)
|
||||||
segment_save_path.write_bytes(res.content)
|
segment_save_path.write_bytes(res.content)
|
||||||
else:
|
else:
|
||||||
aria2c(
|
asyncio.run(aria2c(
|
||||||
uri=segment_uri,
|
uri=segment_uri,
|
||||||
out=segment_save_path,
|
out=segment_save_path,
|
||||||
headers=session.headers,
|
headers=session.headers,
|
||||||
proxy=proxy,
|
proxy=proxy,
|
||||||
segmented=True
|
segmented=True
|
||||||
)
|
))
|
||||||
|
|
||||||
data_size = segment_save_path.stat().st_size
|
data_size = segment_save_path.stat().st_size
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import asyncio
|
||||||
import logging
|
import logging
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
|
@ -287,13 +288,13 @@ class HLS:
|
||||||
segment_save_path.parent.mkdir(parents=True, exist_ok=True)
|
segment_save_path.parent.mkdir(parents=True, exist_ok=True)
|
||||||
segment_save_path.write_bytes(res.content)
|
segment_save_path.write_bytes(res.content)
|
||||||
else:
|
else:
|
||||||
aria2c(
|
asyncio.run(aria2c(
|
||||||
uri=segment.uri,
|
uri=segment.uri,
|
||||||
out=segment_save_path,
|
out=segment_save_path,
|
||||||
headers=session.headers,
|
headers=session.headers,
|
||||||
proxy=proxy,
|
proxy=proxy,
|
||||||
segmented=True
|
segmented=True
|
||||||
)
|
))
|
||||||
|
|
||||||
data_size = segment_save_path.stat().st_size
|
data_size = segment_save_path.stat().st_size
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue