Module:Librivox book
Appearance
![]() | This module is rated as beta, and is ready for widespread use. It is still new and should be used with some caution to ensure the results are as expected. |
![]() | This module is subject to page protection. It is a highly visible module in use by a very large number of pages, or is substituted very frequently. Because vandalism or mistakes would affect many pages, and even trivial editing might cause substantial load on the servers, it is protected from editing. |
Usage
There is currently 1 template that invokes this module, {{Librivox book}}
.
local p = {}
function p.book(frame)
local pframe = frame:getParent()
local args = pframe.args
local tname = "Librivox book" -- name of calling template. Change if template rename.
local title = nil -- display and search title
local dtitle = nil -- display title (default: title)
local stitle = nil -- search title (default: title)
local lname = nil -- last name
local id = nil -- unsupported argument
local author = nil -- author
local tagline = "public domain audiobook at [[LibriVox]]"
local urlhead = "https://librivox.org/search?"
local italic = "''"
id = trimArg(args.id)
if id then
error("Error in {{" .. tname .. "}}, id not supported. Please use {{Librivox author}}")
end
title = trimArg(args.title)
if not title then
title = mw.title.getCurrentTitle().text:gsub('%s+%([^%(]-%)$', '') -- Current page name without the final parentheses
dtitle = title
stitle = dtitle
else
dtitle = title
stitle = dtitle
end
if trimArg(args.stitle) then
stitle = trimArg(args.stitle)
end
if trimArg(args.dtitle) then
dtitle = trimArg(args.dtitle)
italic = ""
end
local dtitle = mw.ustring.gsub(dtitle,"%s+%([^%(]-%)$", "") -- remove disambiguation ()
local stitle = mw.ustring.gsub(stitle,"%s+%([^%(]-%)$", "")
local stitle = mw.ustring.gsub(stitle," ", "+") -- replace "<space>" with "+"
author = trimArg(args.author)
if not author then
lname = ""
else
--- Split name into words, count words, set name to last word
local N = mw.text.split(author, " ")
local l, count = mw.ustring.gsub(author, "%S+", "")
lname = N[count]
end
local url = "[[Image:Speaker Icon.svg|20px]] " .. "[" .. urlhead .. "title=" .. stitle .. "&author=" .. lname .. "&reader=&keywords=&genre_id=0&status=all&project_type=either&recorded_language=&sort_order=catalog_date&search_page=1&search_form=advanced" .. " " .. italic .. dtitle .. italic .. "]" .. " " .. tagline
return url
end
function trimArg(arg)
if arg == "" or arg == nil then
return nil
else
return mw.text.trim(arg)
end
end
return p