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 |
||
(8 intermediate revisions by the same user not shown) | |||
Line 3: | Line 3: | ||
function randomVideo() |
function randomVideo() |
||
local g = mw.ext.externaldata.getWebData { |
local g = mw.ext.externaldata.getWebData { |
||
url = 'https://comprehensibleinputwiki.com/ |
url = 'https://comprehensibleinputwiki.com/rvid.php', |
||
data = {title, channel, id, difficulty, language_name}, |
|||
format = 'JSON' |
format = 'JSON' |
||
} |
} |
||
vidJson = '[ ' |
|||
⚫ | |||
h=0 |
|||
video = mw.getCurrentFrame():callParserFunction( '#ev', 'youtube', value['id']) |
|||
⚫ | |||
⚫ | |||
main_index = v['main_index'] |
|||
id = v['id'] |
|||
difficulty = v['difficulty'] |
|||
title = string.gsub(v['title'], "[\\\"]", "\\%1") |
|||
language_name = (v['language_name'] ~= nil and v['language_name'] or '') |
|||
channel = v['channel'] |
|||
⚫ | |||
comma = (h < 99 and ',' or '') |
|||
h = h + 1 |
|||
vidJson = vidJson .. '{"main_index": ' .. main_index .. ', "id": "' .. id .. '", "difficulty": "' .. difficulty .. '", "title": "' .. title .. '", "language": "' .. language_name .. '", "channel": "' .. channel .. '"}' .. comma .. ' ' |
|||
end |
|||
vidJson = vidJson .. ']' |
|||
return vidJson |
|||
end |
end |
||
Latest revision as of 16:45, 16 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/rvid.php',
format = 'JSON'
}
vidJson = '[ '
h=0
for k, v in ipairs(g) do
main_index = v['main_index']
id = v['id']
difficulty = v['difficulty']
title = string.gsub(v['title'], "[\\\"]", "\\%1")
language_name = (v['language_name'] ~= nil and v['language_name'] or '')
channel = v['channel']
comma = (h < 99 and ',' or '')
h = h + 1
vidJson = vidJson .. '{"main_index": ' .. main_index .. ', "id": "' .. id .. '", "difficulty": "' .. difficulty .. '", "title": "' .. title .. '", "language": "' .. language_name .. '", "channel": "' .. channel .. '"}' .. comma .. ' '
end
vidJson = vidJson .. ']'
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