Module:RandomArchiveVideo: Difference between revisions

From Tony Chase
Jump to navigation Jump to search
(THE SATELLITE MAN IS MAKING ME USE TEMPORARY CODE)
 
mNo edit summary
 
Line 1: Line 1:
-- Module:RandomVideoEmbedder
local p = {}
local p = {}


function p.main(frame)
function p.main(frame)
     local xmlData = p.fetchXmlData()
    local http = require('http') -- Loads the http module explicitly now
     local xmlData = p.fetchXmlData(http)
     local videoUrl = p.getRandomVideoUrl(xmlData)
     local videoUrl = p.getRandomVideoUrl(xmlData)
     return p.embedVideo(videoUrl)
     return p.embedVideo(videoUrl)
end
end


function p.fetchXmlData()
function p.fetchXmlData(http)
    -- Fetch XML data from the server and return it as a string
     local url = 'https://tonyy.us-southeast-1.linodeobjects.com/'
     local url = 'https://tonyy.us-southeast-1.linodeobjects.com/'
     local result, data = pcall(mw.ext.http.get, url)
     local result, data = pcall(http.get, url)
     if result then
     if result then
         return data
         return data
Line 21: Line 19:


function p.getRandomVideoUrl(xmlData)
function p.getRandomVideoUrl(xmlData)
     -- Parse XML data and return a random video URL
     return 'https://example.com/sample.mp4' -- Replace with actual logic pls
    -- Implement your XML parsing logic here
    -- For simplicity, let's assume the XML contains video URLs as direct text content of 'video' elements
    local videos = mw.text.split(xmlData, '\n') -- Change this based on your actual XML structure
    return videos[math.random(#videos)]
end
end


function p.embedVideo(videoUrl)
function p.embedVideo(videoUrl)
    -- Use the Html5media widget to embed the video
     local width = 640
     local width = 640
     local height = 360
     local height = 360

Latest revision as of 21:38, 17 January 2024

Documentation for this module may be created at Module:RandomArchiveVideo/doc

local p = {}

function p.main(frame)
    local http = require('http') -- Loads the http module explicitly now
    local xmlData = p.fetchXmlData(http)
    local videoUrl = p.getRandomVideoUrl(xmlData)
    return p.embedVideo(videoUrl)
end

function p.fetchXmlData(http)
    local url = 'https://tonyy.us-southeast-1.linodeobjects.com/'
    local result, data = pcall(http.get, url)
    if result then
        return data
    else
        return ''
    end
end

function p.getRandomVideoUrl(xmlData)
    return 'https://example.com/sample.mp4' -- Replace with actual logic pls
end

function p.embedVideo(videoUrl)
    local width = 640
    local height = 360
    return mw.getCurrentFrame():expandTemplate{
        title = '#widget:Html5media',
        args = {
            url = videoUrl,
            width = width,
            height = height
        }
    }
end

return p