Difference between revisions of "Module:Librivox book/sandbox"

From blackwiki
Jump to navigation Jump to search
blackwiki>GreenC
blackwiki>GreenC
Line 13: Line 13:
 
   local tagline = "public domain audiobook at [[LibriVox]]"
 
   local tagline = "public domain audiobook at [[LibriVox]]"
 
   local urlhead = "https://librivox.org/search?"
 
   local urlhead = "https://librivox.org/search?"
 +
  local italic  = "''"
  
 
   if args.id ~= "" and args.id ~= nil then
 
   if args.id ~= "" and args.id ~= nil then
     return "Wrong template. Please use {{Librivox author}}"
+
     return "Error in {{" .. tname .. "}}, id not supported. Please use {{Librivox author}}"
 
   end
 
   end
  
Line 33: Line 34:
 
   if args.dtitle ~= nil and args.dtitle ~= "" then
 
   if args.dtitle ~= nil and args.dtitle ~= "" then
 
     dtitle = mw.text.trim(args.dtitle)
 
     dtitle = mw.text.trim(args.dtitle)
 +
    italic  = ""
 
   end
 
   end
   dtitle = mw.ustring.gsub(dtitle,"%s%(.*%)", "") -- remove disambiguation ()  
+
   local dtitle = mw.ustring.gsub(dtitle,"%s%(.*%)", "") -- remove disambiguation ()  
   stitle = mw.ustring.gsub(stitle,"%s%(.*%)", "")
+
   local stitle = mw.ustring.gsub(stitle,"%s%(.*%)", "")
   stitle = mw.ustring.gsub(stitle," ", "+") -- replace "<space>" with "+"
+
   local stitle = mw.ustring.gsub(stitle," ", "+") -- replace "<space>" with "+"
  
 
   if args.author == "" or args.author == nil then
 
   if args.author == "" or args.author == nil then
     name = ""
+
     lname = ""
 
   else
 
   else
 
     --- Split name into words, count words, set name to last word
 
     --- Split name into words, count words, set name to last word
Line 47: Line 49:
 
   end
 
   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" .. " " .. "''" .. dtitle .. "''" .. "]" .. " " .. tagline
+
   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
 
   return url

Revision as of 00:02, 19 March 2015

Documentation for this module may be created at Module:Librivox book/sandbox/doc

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 dtitle  = nil -- display title (default: title field)
  local stitle  = nil -- search title (default: title field)
  local tagline = "public domain audiobook at [[LibriVox]]"
  local urlhead = "https://librivox.org/search?"
  local italic   = "''"

  if args.id ~= "" and args.id ~= nil then
    return "Error in {{" .. tname .. "}}, id not supported. Please use {{Librivox author}}"
  end

  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)
    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 "+"

  if args.author == "" or args.author == nil then
    lname = ""
  else
    --- Split name into words, count words, set name to last word
    local N = mw.text.split(mw.text.trim(args.author), " ")
    local l, count = mw.ustring.gsub(mw.text.trim(args.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

return p