Skip to content

Commit

Permalink
URL service has been revised
Browse files Browse the repository at this point in the history
  • Loading branch information
CattoGamer committed Jul 4, 2024
1 parent fba2018 commit 01c8347
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 118 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
local SERVICE = {}

SERVICE.Name = "HLS Video"
SERVICE.Name = "URL (HLS Video)"
SERVICE.IsTimed = true

SERVICE.Dependency = DEPENDENCY_COMPLETE
Expand Down Expand Up @@ -137,7 +137,7 @@ function SERVICE:GetVideoInfo( data, onSuccess, onFailure )
info.title = ("HLS: %s"):format(data:Data())

if metadata.live then
info.type = "hls_live"
info.type = "url_hlslive"
info.duration = 0
else
info.duration = math.Round(tonumber(metadata.duration))
Expand All @@ -150,9 +150,9 @@ function SERVICE:GetVideoInfo( data, onSuccess, onFailure )

end

theater.RegisterService( "hls", SERVICE )
theater.RegisterService( "hls_live", {
Name = "HLS Live",
theater.RegisterService( "url_hls", SERVICE )
theater.RegisterService( "url_hlslive", {
Name = "URL (HLS Live)",
IsTimed = false,
Dependency = DEPENDENCY_COMPLETE,
Hidden = true,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
local SERVICE = {}

SERVICE.Name = "URL (Image)"
SERVICE.IsTimed = false
SERVICE.Hidden = true

SERVICE.IsCacheable = false
SERVICE.Dependency = DEPENDENCY_NONE


if (CLIENT) then
function SERVICE:LoadProvider( Video, panel )
panel:OpenURL(Video:Data())
end
end

if (SERVER) then
CreateConVar("cinema_service_imageduration", "0", {FCVAR_ARCHIVE, FCVAR_NEVER_AS_STRING}, "0 = Infinite, 60sec Max", 0, 60 )
end

theater.RegisterService( "image", SERVICE )
theater.RegisterService( "image_timed", {
Name = SERVICE.Name,
IsTimed = true,
IsCacheable = false,
Dependency = SERVICE.Dependency,
Hidden = true,
LoadProvider = CLIENT and SERVICE.LoadProvider or function() end
} )
Original file line number Diff line number Diff line change
@@ -1,40 +1,50 @@
local SERVICE = {}

SERVICE.Name = "File"
SERVICE.Name = "URL"
SERVICE.IsTimed = true
SERVICE.Hidden = true

SERVICE.Dependency = DEPENDENCY_COMPLETE
SERVICE.ExtentedVideoInfo = true

-- Which endings are allowed to go through
-- the match (regardless of whether CEF Codec Fix is present or not)
local validExtensions = {

-- Video
["mp4"] = true,
["webm"] = true,
-- Don't use the domains of the other Services.
local excludedDomains = {
GetConVar("cinema_url_search"):GetString(),
"youtu.?be[.com]?",
"bilibili.com",
"b23.tv",
"dailymotion.com",
"archive.org",
"ok.ru",
"rutube.ru",
"rumble.com",
"sibnet.ru",
"vimeo.com",
"vk.com",
"twitch.tv"
}

-- Audio
["mp3"] = true,
["m4a"] = true,
["wav"] = true,
["ogg"] = true,
local validImageExtensions = {
["jpg"] = true,
["png"] = true,
["bmp"] = true,
["jpeg"] = true,
["gif"] = true,
}

-- Which extensions are allowed if CEF Codec Fix is not present.
local limitedExtensions = {
function SERVICE:Match( url )
local allowed = false

-- Video
["webm"] = true,
for _, domain in pairs( excludedDomains ) do
allowed = false

-- Audio
["mp3"] = true,
["wav"] = true,
["ogg"] = true,
}
if url.host and url.encoded:find(domain) then
allowed = true
break
end
end

function SERVICE:Match( url )
return validExtensions[ string.GetExtensionFromFilename( url.path ) ] or GetConVar( "cinema_force_extension_bypass" ):GetBool()
return not allowed
end

if (CLIENT) then
Expand All @@ -57,28 +67,28 @@ if (CLIENT) then
</style>
<div id="player-wrapper"></div>
<script>
var video = document.createElement("video");
video.src = "{@VideoURL}";
video.autoplay = true;
video.controls = true;
video.muted = false;
document.getElementById("player-wrapper").appendChild(video);
</script>
<script>
var checkerInterval = setInterval(function() {
var checkerInterval = setInterval(function() {
if (!video.paused && video.readyState === 4) {
clearInterval(checkerInterval);
window.cinema_controller = video;
exTheater.controllerReady();
}
}, 50);
</script>
</body>
</html>
]]
Expand Down Expand Up @@ -151,42 +161,52 @@ end

function SERVICE:GetURLInfo( url )
if url and url.encoded then
return { Data = url.encoded }
local info = {}

info.Data = url.encoded
return info
end

return false
end

function SERVICE:GetVideoInfo( data, onSuccess, onFailure )

-- Image Service
if validImageExtensions[ string.GetExtensionFromFilename( data:Data() ) ] then
local info = {}
info.title = ("Image: %s"):format(data:Data())

local duration = GetConVar("cinema_service_imageduration"):GetInt()
if duration > 0 then
info.type = "image_timed"
info.duration = duration
else
info.type = "image"
end

if onSuccess then
pcall(onSuccess, info)
end

return
end

theater.FetchVideoMedata( data:GetOwner(), data, function(metadata)

if metadata.err then
return onFailure(metadata.err)
end

local info = {}
info.title = ("File: %s"):format(data:Data())
info.title = ("URL: %s"):format(data:Data())
info.duration = math.Round(tonumber(metadata.duration))

if limitedExtensions[ string.GetExtensionFromFilename( data:Data() ) ] then
info.type = "file_limited"
end

if onSuccess then
pcall(onSuccess, info)
end
end)

end

theater.RegisterService( "file", SERVICE )

-- Responsible that at least audio and WEBM videos without CEF codec work fix
theater.RegisterService( "file_limited", {
Name = "File (Limited)",
IsTimed = true,
Dependency = DEPENDENCY_PARTIAL,
Hidden = true,
LoadProvider = CLIENT and SERVICE.LoadProvider or function() end
} )
theater.RegisterService( "url", SERVICE )

0 comments on commit 01c8347

Please sign in to comment.