25 lines
698 B
Python
25 lines
698 B
Python
import asyncio
|
|
import json
|
|
import subprocess
|
|
|
|
from v6d3music.utils.tor_prefix import tor_prefix
|
|
|
|
|
|
async def tor_extract(params: dict, url: str, **kwargs):
|
|
print(f'tor extracting {url}')
|
|
p = subprocess.Popen(
|
|
[*tor_prefix, 'python', '-m', 'v6d3music.run-extract'],
|
|
stdin=subprocess.PIPE,
|
|
stdout=subprocess.PIPE,
|
|
text=True
|
|
)
|
|
p.stdin.write(f'{json.dumps(params)}\n')
|
|
p.stdin.write(f'{json.dumps(url)}\n')
|
|
p.stdin.write(f'{json.dumps(kwargs)}\n')
|
|
p.stdin.flush()
|
|
p.stdin.close()
|
|
code = await asyncio.get_running_loop().run_in_executor(None, p.wait)
|
|
if code:
|
|
raise RuntimeError(code)
|
|
return json.loads(p.stdout.read())
|