Module:Random Video: Difference between revisions

From Comprehensible Input Wiki
Content added Content deleted
(Created page with "local p = {} function randomVideo() local g = mw.ext.externaldata.getWebData { url = 'https://comprehensibleinputwiki.com/randomvideo.php', data = {title, channel, id, difficulty, language_name}, format = 'JSON' } for key, value in ipairs(g) do video = mw.getCurrentFrame():callParserFunction( '#ev', 'youtube', value['id']) end return video end function dump(o) if type(o) == 'table' then...")
 
No edit summary
Line 4: Line 4:
local g = mw.ext.externaldata.getWebData {
local g = mw.ext.externaldata.getWebData {
url = 'https://comprehensibleinputwiki.com/randomvideo.php',
url = 'https://comprehensibleinputwiki.com/randomvideo.php',
data = {title, channel, id, difficulty, language_name},
format = 'JSON'
format = 'JSON'
}
}


main_index = g['main_index']
for key, value in ipairs(g) do
id = g['id']
video = mw.getCurrentFrame():callParserFunction( '#ev', 'youtube', value['id'])
difficulty = g['difficulty']
end
title = g['title']
language = g['language_name']
channel = g['channel']
vidJson = '{main_index: ' .. main_index .. ', id: ' .. id .. ', difficulty: ' .. difficulty .. ', title: ' .. title .. ', language: ' .. language .. ', channel: ' .. channel .. '}'
return video
return vidJson
end
end



Revision as of 17:24, 4 April 2023

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

local p = {}

function randomVideo()
        local g = mw.ext.externaldata.getWebData {
            url = 'https://comprehensibleinputwiki.com/randomvideo.php',
            format = 'JSON'
        }

	    main_index = g['main_index']
	    id = g['id']
	    difficulty = g['difficulty']
	    title = g['title']
	    language = g['language_name']
	    channel = g['channel']
	    
	    vidJson = '{main_index: ' .. main_index .. ', id: ' .. id .. ', difficulty: ' .. difficulty .. ', title: ' .. title .. ', language: ' .. language .. ', channel: ' .. channel .. '}'
	
        return vidJson
end

function dump(o)
   if type(o) == 'table' then
      local s = '{ '
      for k,v in pairs(o) do
         if type(k) ~= 'number' then k = '"'..k..'"' end
         s = s .. '\n['..k..'] = ' .. dump(v) .. ','
      end
      return s .. '} '
   else
      return tostring(o)
   end
end



p.randomVideo = function()
	return randomVideo()
end


return p