Refactor: run extract_info in separate thread
This commit is contained in:
parent
7b51c6f245
commit
baacf83974
2 changed files with 33 additions and 14 deletions
|
|
@ -1,3 +1,5 @@
|
||||||
|
import asyncio
|
||||||
|
import functools
|
||||||
import logging
|
import logging
|
||||||
import uuid
|
import uuid
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
|
|
@ -153,14 +155,22 @@ async def conditions_test(request: Request, encoder: Encoder, cache: Cache, conf
|
||||||
preset: str = params.get("preset", config.default_preset)
|
preset: str = params.get("preset", config.default_preset)
|
||||||
key: str = cache.hash(url + str(preset))
|
key: str = cache.hash(url + str(preset))
|
||||||
if not cache.has(key):
|
if not cache.has(key):
|
||||||
data: dict = extract_info(
|
data: dict | None = await asyncio.wait_for(
|
||||||
config=YTDLPOpts.get_instance().preset(name=preset).get_all(),
|
fut=asyncio.get_running_loop().run_in_executor(
|
||||||
url=url,
|
None,
|
||||||
debug=False,
|
functools.partial(
|
||||||
no_archive=True,
|
extract_info,
|
||||||
follow_redirect=True,
|
config=YTDLPOpts.get_instance().preset(name=preset).get_all(),
|
||||||
sanitize_info=True,
|
url=url,
|
||||||
|
debug=False,
|
||||||
|
no_archive=True,
|
||||||
|
follow_redirect=True,
|
||||||
|
sanitize_info=True,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
timeout=120,
|
||||||
)
|
)
|
||||||
|
|
||||||
if not data:
|
if not data:
|
||||||
return web.json_response(
|
return web.json_response(
|
||||||
data={"error": f"Failed to extract info from '{url!s}'."},
|
data={"error": f"Failed to extract info from '{url!s}'."},
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
import asyncio
|
||||||
|
import functools
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
import time
|
import time
|
||||||
|
|
@ -163,13 +165,20 @@ async def get_info(request: Request, cache: Cache, config: Config) -> Response:
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
data = extract_info(
|
data: dict | None = await asyncio.wait_for(
|
||||||
config=ytdlp_opts,
|
fut=asyncio.get_running_loop().run_in_executor(
|
||||||
url=url,
|
None,
|
||||||
debug=False,
|
functools.partial(
|
||||||
no_archive=True,
|
extract_info,
|
||||||
follow_redirect=True,
|
config=ytdlp_opts,
|
||||||
sanitize_info=True,
|
url=url,
|
||||||
|
debug=False,
|
||||||
|
no_archive=True,
|
||||||
|
follow_redirect=True,
|
||||||
|
sanitize_info=True,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
timeout=120,
|
||||||
)
|
)
|
||||||
|
|
||||||
if not data or not isinstance(data, dict):
|
if not data or not isinstance(data, dict):
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue