serve: Handle TooManySessions on /open
This commit is contained in:
parent
5c1b0e89ef
commit
64ae5709d3
|
@ -3,6 +3,8 @@ import sys
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Optional, Union
|
from typing import Optional, Union
|
||||||
|
|
||||||
|
from pywidevine.exceptions import TooManySessions
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from aiohttp import web
|
from aiohttp import web
|
||||||
except ImportError:
|
except ImportError:
|
||||||
|
@ -60,7 +62,14 @@ async def open(request: web.Request) -> web.Response:
|
||||||
device = Device.load(request.app["config"]["devices"][device])
|
device = Device.load(request.app["config"]["devices"][device])
|
||||||
|
|
||||||
cdm = Cdm(device)
|
cdm = Cdm(device)
|
||||||
|
try:
|
||||||
session_id = cdm.open()
|
session_id = cdm.open()
|
||||||
|
except TooManySessions as e:
|
||||||
|
return web.json_response({
|
||||||
|
"status": 400,
|
||||||
|
"message": str(e)
|
||||||
|
}, status=400)
|
||||||
|
|
||||||
request.app["sessions"][session_id] = cdm
|
request.app["sessions"][session_id] = cdm
|
||||||
|
|
||||||
return web.json_response({
|
return web.json_response({
|
||||||
|
|
Loading…
Reference in New Issue