Fix Google Drive support

This commit is contained in:
Xerasin 2021-10-24 16:55:07 -07:00
parent b81a56083a
commit 13b09b7335
2 changed files with 20 additions and 2 deletions

View File

@ -152,11 +152,27 @@ if CLIENT then
})
end
local patterns = {
["drive.google.com/file/d/([%d%w]+)/view"] = "https://drive.google.com/u/0/uc?id=%s&export=download",
}
function wowozela.ProcessURL(url)
for pattern, replace in pairs(patterns) do
local match = string.match(url, pattern)
if match then
return string.format(replace, match)
end
end
return url
end
function wowozela.PlayURL(name, settings, callback, failurecallback)
if #name == 0 then return failurecallback and failurecallback("Empty URL?") end
if not wowozela.URLWhitelist(name) then
return failurecallback and failurecallback("Not a whitelisted URL.")
end
name = wowozela.ProcessURL(name)
GetURLSound(name, function(sndPath)
sound.PlayFile(sndPath, settings, callback)
end, failurecallback or function() end)
@ -891,6 +907,9 @@ simple [[onedrive.live.com/redir]]
--- https://docs.google.com/uc?export=download&confirm=UYyi&id=0BxUpZqVaDxVPeENDM1RtZDRvaTA
simple [[docs.google.com/uc]]
simple [[drive.google.com/file/d/]]
simple [[drive.google.com/u/0/uc]]
--[=[
-- Imgur
--- Examples:

View File

@ -1034,12 +1034,11 @@ if CLIENT then
end)
end
local function soundError(reason)
LocalPlayer():ChatPrint(("Unable to load sound: %s"):format(reason))
end
Menu:AddOption("custom...", function()
Derma_StringRequest("Sound (Mp3/Ogg)", "Insert a web-hosted ogg or mp3.\n(GitHub, Vocaroo, Dropbox, Puush, Google Drive or similar sites)", "", function(text)
Derma_StringRequest("Sound (Mp3/Ogg)", "Insert a web-hosted ogg or mp3.\n(GitHub, Vocaroo, Puush, Google Drive or similar sites)", "", function(text)
if text:sub(1, 4) ~= "http" then return end
if text:sub(1, 19) == "https://github.com/" and text:sub(-9) ~= "?raw=true" then