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 -- book title (default: current page)
local dtitle = nil -- display title (default: title field)
local stitle = nil -- search title (default: title field)
local name = nil -- author name (default: nil)
local tagline = "public domain audiobook at [[LibriVox]]"
local urlhead = "https://librivox.org/search?"
if args.title == "" or args.title == nil then
title = mw.title.getCurrentTitle().text
dtitle = title
stitle = dtitle
else
title = mw.text.trim(args.title)
dtitle = title
stitle = dtitle
end
if args.stitle ~= nil and args.stitle ~= "" then
stitle = mw.text.trim(args.stitle)
end
if args.dtitle ~= nil and args.dtitle ~= "" then
dtitle = mw.text.trim(args.dtitle)
end
dtitle = mw.ustring.gsub(dtitle,"%s%(.*%)", "") -- remove disambiguation ()
stitle = mw.ustring.gsub(stitle,"%s%(.*%)", "")
stitle = mw.ustring.gsub(stitle," ", "+") -- replace "<space>" with "+"
--- Split name into words, count words, set name to last word
local N = mw.text.split(name, " ")
local l, count = mw.ustring.gsub(name, "%S+", "")
name = N[count]
local url = "[" .. urlhead .. "title=" .. stitle .. "&author=" .. name .. "&reader=&keywords=&genre_id=0&status=all&project_type=either&recorded_language=&sort_order=catalog_date&search_page=1&search_form=advanced" .. " " .. tagline
return url
end