-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Shadowsun™
authored and
Shadowsun™
committed
Nov 28, 2023
1 parent
d11267b
commit 87b38f6
Showing
4 changed files
with
116 additions
and
1 deletion.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
workshop/gamemodes/cinema_modded/gamemode/modules/theater/services/sh_rumble.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
local SERVICE = {} | ||
|
||
SERVICE.Name = "Rumble" | ||
SERVICE.IsTimed = true | ||
|
||
SERVICE.Dependency = DEPENDENCY_COMPLETE | ||
|
||
local API_URL = "https://rumble.com/api/Media/oembed.json?url=https://rumble.com/%s" | ||
|
||
function SERVICE:Match( url ) | ||
return url.host and url.host:match("rumble.com") | ||
end | ||
|
||
if (CLIENT) then | ||
local THEATER_JS = [[ | ||
var checkerInterval = setInterval(function() { | ||
var player = document.getElementsByTagName('video')[0]; | ||
if (!!player && player.paused == false && player.readyState == 4) { | ||
if (player.muted) {player.muted = false} | ||
clearInterval(checkerInterval); | ||
document.body.style.backgroundColor = "black"; | ||
window.cinema_controller = player; | ||
exTheater.controllerReady(); | ||
} | ||
}, 50); | ||
]] | ||
|
||
function SERVICE:LoadProvider( Video, panel ) | ||
|
||
local function onFail(msg) | ||
LocalPlayer():ChatPrint(("Rumble: %s"):format(msg)) | ||
end | ||
|
||
local url = API_URL:format( Video:Data() ) .. ".html" | ||
self:Fetch( url, function( body, length, headers, code ) | ||
local response = util.JSONToTable(body) | ||
if not response then | ||
return onFail("API Error") | ||
end | ||
|
||
local startTime = math.Round(CurTime() - Video:StartTime()) | ||
local embed = response.html:match("(https://rumble.com/embed/[%a%d-_]+/)") | ||
.. "?pub=7a20&rel=5&autoplay=2" | ||
.. (self.IsTimed and "&t=" .. startTime or "" ) | ||
|
||
panel:OpenURL(embed) | ||
panel.OnDocumentReady = function(pnl) | ||
self:LoadExFunctions( pnl ) | ||
pnl:QueueJavascript(THEATER_JS) | ||
end | ||
|
||
end, onFail) | ||
|
||
end | ||
end | ||
|
||
function SERVICE:GetURLInfo( url ) | ||
|
||
if url.path then | ||
local data = url.path:match("/([%a%d%p-_]+).html") | ||
if ( data ) then return { Data = data } end | ||
end | ||
|
||
return false | ||
end | ||
|
||
function SERVICE:GetVideoInfo( data, onSuccess, onFailure ) | ||
|
||
local onReceive = function( body, length, headers, code ) | ||
local response = util.JSONToTable(body) | ||
if not response then | ||
return onFailure( "Theater_RequestFailed" ) | ||
end | ||
|
||
local info = {} | ||
info.title = response.title | ||
info.thumbnail = response.thumbnail_url | ||
|
||
if response.duration == 0 then | ||
info.type = "rumblelive" | ||
info.duration = 0 | ||
else | ||
info.duration = response.duration | ||
end | ||
|
||
if onSuccess then | ||
pcall(onSuccess, info) | ||
end | ||
|
||
end | ||
|
||
local url = API_URL:format( data ) .. ".html" | ||
self:Fetch( url, onReceive, onFailure ) | ||
|
||
end | ||
|
||
theater.RegisterService( "rumble", SERVICE ) | ||
|
||
theater.RegisterService( "rumblelive", { | ||
Name = "Rumble Live", | ||
IsTimed = false, | ||
Hidden = true, | ||
LoadProvider = CLIENT and SERVICE.LoadProvider or function() end | ||
} ) |