Skip to content

Commit

Permalink
Fix CVar not working on dedicated server
Browse files Browse the repository at this point in the history
  • Loading branch information
Myaats committed Aug 3, 2024
1 parent 613f2c9 commit 9cba3b2
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion lua/mediaplayer/services/youtube/cl_init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function SERVICE:OnBrowserReady( browser )
end

local url_prefix = htmlBaseUrl .. "youtube.html"
local invidious_cvar_sv = GetConVar("mediaplayer_invidious_instance_sv")
local invidious_cvar_sv = self.Cvars.InvidiousInstance
if cvInvidiousEnable:GetBool() then
url_prefix = htmlBaseUrl .. "invidious.html"
elseif invidious_cvar_sv:GetString():Trim() ~= "" then
Expand Down
9 changes: 1 addition & 8 deletions lua/mediaplayer/services/youtube/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,6 @@ include "shared.lua"
local TableLookup = MediaPlayerUtils.TableLookup
local htmlentities_decode = url.htmlentities_decode

local invidious_instance = CreateConVar( "mediaplayer_invidious_instance_sv", "", {
FCVAR_ARCHIVE,
FCVAR_NOTIFY,
FCVAR_REPLICATED,
FCVAR_SERVER_CAN_EXECUTE
}, "Serverside invidious instance, will be used clientside too" )

---
-- Helper function for converting ISO 8601 time strings; this is the formatting
-- used for duration specified in the YouTube v3 API.
Expand Down Expand Up @@ -88,7 +81,7 @@ function SERVICE:GetMetadata( callback )
else
local videoId = self:GetYouTubeVideoId()

local instance = invidious_instance:GetString()
local instance = self.Cvars.InvidiousInstance:GetString()
-- Use invidious serverside
if instance:Trim() ~= "" then
local videoUrl = instance .. "/api/v1/videos/" .. videoId
Expand Down
9 changes: 9 additions & 0 deletions lua/mediaplayer/services/youtube/shared.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ SERVICE.Name = "YouTube"
SERVICE.Id = "yt"
SERVICE.Base = "browser"

SERVICE.Cvars = SERVICE.Cvars or {}
SERVICE.Cvars.InvidiousInstance = CreateConVar( "mediaplayer_invidious_instance_sv", "", {
FCVAR_ARCHIVE,
FCVAR_NOTIFY,
FCVAR_REPLICATED,
FCVAR_SERVER_CAN_EXECUTE
}, "Serverside invidious instance, will be used clientside too" )


local YtVideoIdPattern = "[%a%d-_]+"
local UrlSchemes = {
"youtube%.com/watch%?v=" .. YtVideoIdPattern,
Expand Down

0 comments on commit 9cba3b2

Please sign in to comment.