Module:PD-US-music

From Wikisource
Jump to navigation Jump to search

--[=[
Implements [[Template:PD-US-music]]
]=]

local p = {} --p stands for package

local getArgs = require('Module:Arguments').getArgs
local PD = require('Module:PD')

function p._PD_US_music(args)
	local deathyear = PD.getAuthorDeathYear({args[1], args.deathyear})
	
	-- Pre-1923 recordings are PD
	-- 1923–1946 recordings are PD after 100 years: 2024–2047
	-- 1947–1956 recordings are PD after 110 years: 2058–2067
	-- Post-1956 recordings are PD on February 15, 2067
	local cutoff
	if PD.currentyear > 2067 or (PD.currentyear == 2067 and PD.currentmonth > 2) or (PD.currentyear == 2067 and PD.currentmonth == 2 and PD.currentday >= 15) then
		cutoff = ""
	else
		local maxyear
		if PD.currentyear < 2024 then
			maxyear = 1923
		elseif PD.currentyear < 2048 then
			maxyear = PD.currentyear - 100
		elseif PD.currentyear < 2058 then
			maxyear = 1947
		else
			maxyear = PD.currentyear - 110
		end
		cutoff = " and published before " .. maxyear
	end
	
	local text = "Under the Classics Protection and Access Act ([https://www.law.cornell.edu/uscode/text/17/1401 17 U.S.C. § 1401]), " .. PD.license_scope({lc=true}) .. " in the '''[[w:public domain|public domain]]''' in the '''United States''' because " .. PD.license_grammar({"it is a sound recording which was", "they are sound recordings which were"}) .. " fixed before February 15, 1972" .. cutoff .. "." .. PD.shorter_term_text(deathyear)
	
	return PD.license({
		['image'] = PD.PD_image,
		['image_r'] = PD.US_flag_image,
		['text'] = text,
		['category'] = args.category or "PD-US-music"
	})
end

function p.PD_US_music(frame)
	return p._PD_US_music(getArgs(frame))
end

return p