52 lines
1.7 KiB
Plaintext
52 lines
1.7 KiB
Plaintext
import "pkg:/components/Services/Dash/DashManifest.bs"
|
|
import "pkg:/components/Services/Invidious/InvidiousService.bs"
|
|
import "pkg:/source/utils/Types.bs"
|
|
|
|
namespace Http
|
|
|
|
class DashRouter extends HttpRouter
|
|
function new(server as object)
|
|
super()
|
|
|
|
m.invidiousNode = server.task.invidious
|
|
m.invidiousService = new Invidious.InvidiousService(m.invidiousNode)
|
|
' No need to pass the invidious instance here, we will refresh it for
|
|
' each request to make sure we are using the latest one
|
|
m.dashManifest = new DashManifest("")
|
|
end function
|
|
|
|
@get("/api/dash")
|
|
function GenerateDashManifest(context as object) as boolean
|
|
request = context.request
|
|
response = context.response
|
|
|
|
v = request.query.v
|
|
local = request.query.local
|
|
|
|
if StringUtils.IsNullOrEmpty(v)
|
|
response.Default(400, "Missing video id")
|
|
return true
|
|
end if
|
|
|
|
metadataRequest = m.invidiousService.GetVideoMetadata(v)
|
|
if not metadataRequest.IsSuccess()
|
|
response.Default(metadataRequest.StatusCode(), metadataRequest.ErrorMessage())
|
|
return true
|
|
end if
|
|
|
|
metadata = metadataRequest.Json()
|
|
m.dashManifest.invidiousInstance = m.invidiousService.GetInstance()
|
|
|
|
xmlContent = m.dashManifest.fromVideoMetadata(metadata, ValidString(local) = "true")
|
|
|
|
response.http_code = 200
|
|
response.SetBodyDataString(xmlContent)
|
|
response.ContentType("application/dash+xml")
|
|
|
|
return true
|
|
end function
|
|
|
|
end class
|
|
|
|
end namespace
|