Module:XVideosRedList: Difference between revisions
Content deleted Content added
PeaceDeadC (talk | contribs) Created page with "-- This module handles the display of XVideos RED channel information local p = {} -- Load the i18n submodule for text strings and error messages local i18n = require('Module:XVideosRedList/i18n') -- Base URL for XVideos RED local BASE_URL = "https://www.xvideos.red/" -- Suffix to append to all XVideos RED URLs local URL_SUFFIX = "?sxcaf=TARTFSJC35" -- Main header URL for title link local HEADER_URL = "https://www.xvideos.red/gay?sxcaf=TARTFSJC35" -- Default category f..." |
PeaceDeadC (talk | contribs) No edit summary |
||
| (3 intermediate revisions by the same user not shown) | |||
Line 9:
-- Suffix to append to all XVideos RED URLs
local URL_SUFFIX = "?sxcaf=TARTFSJC35"
-- Tab suffix added after the main suffix
local TAB_SUFFIX = "#_tabRed"
-- Main header URL for title link
local HEADER_URL = "https://www.xvideos.red/gay?sxcaf=TARTFSJC35"
-- Default category for all channels
local DEFAULT_CATEGORY = "XVideos RED models"
-- Genre categories mapping
local GENRE_CATEGORIES = {
["Gay"] = "XVideos RED (gay) models",
["Straight"] = "XVideos RED (heterosexual) models",
["Bisexual"] = "XVideos RED (bisexual) models",
["Transexual"] = "XVideos RED (transsexual) models"
}
-- Genre display order priority
local GENRE_PRIORITY = {
["Gay"] = 1,
["Straight"] = 2,
["Bisexual"] = 3,
["Transexual"] = 4
}
-- Helper function to check if a table contains a specific value
Line 55 ⟶ 73:
-- @return boolean: True if the genre is valid, false otherwise
local function normalizeGenre(input)
if not input or input == '' then
return nil, false
end
local lowerInput = input:lower() -- Convert input to lowercase for case-insensitive comparison
for standard, aliases in pairs(genres) do
Line 62 ⟶ 84:
end
return input, false -- Return original input if no match is found, plus flag indicating no match
end
-- Function to format multiple genres with proper icons and formatting
-- @param genreList table: List of normalized genre names
-- @return string: Formatted genres with icons and proper separators
local function formatGenres(genreList)
if #genreList == 0 then
return '<span style="color:red;font-weight:bold;">' .. i18n.errors.noGenreProvided .. '</span>'
end
-- Sort genres according to priority order
table.sort(genreList, function(a, b)
return (GENRE_PRIORITY[a] or 99) < (GENRE_PRIORITY[b] or 99)
end)
local formattedGenres = {}
for _, genre in ipairs(genreList) do
if iconMap[genre] then
table.insert(formattedGenres, string.format('[[File:%s|13px|link=]] %s', iconMap[genre], genre))
else
table.insert(formattedGenres, genre)
end
end
-- Format with appropriate separators based on the number of genres
if #formattedGenres == 1 then
return formattedGenres[1]
elseif #formattedGenres == 2 then
return formattedGenres[1] .. ' & ' .. formattedGenres[2]
else
local result = ""
for i = 1, #formattedGenres - 1 do
if i == #formattedGenres - 1 then
result = result .. formattedGenres[i] .. ' & '
else
result = result .. formattedGenres[i] .. ', '
end
end
return result .. formattedGenres[#formattedGenres]
end
end
-- Function to format country flag using frame:expandTemplate
-- @param country string: The country code or name
-- @param frame table: The current frame object for template expansion
-- @return string: Formatted country flag or empty string if country is nil or empty
local function formatCountryFlag(country, frame)
if not country or country == "" then
return ""
end
-- Use frame:expandTemplate to process the flagicon template
local flagTemplate = frame:expandTemplate{
title = 'flagicon',
args = { country }
}
return flagTemplate .. ' '
end
Line 91 ⟶ 171:
end
--
local
-- Process primary genre
local primaryGenre = args.genre or channel.genre or ''
local normalizedGenre, isValid = normalizeGenre(primaryGenre)
if normalizedGenre then
table.insert(genreList, normalizedGenre)
if not isValid then
table.insert(invalidGenres, primaryGenre)
end
end
-- Process additional genres (genre2, genre3, genre4)
for i = 2, 4 do
local genreArg = args['genre'..i]
if genreArg and genreArg ~= '' then
local normalized, valid = normalizeGenre(genreArg)
if normalized and not table.contains(genreList, normalized) then
table.insert(genreList, normalized)
if not valid then
table.insert(invalidGenres, genreArg)
end
end
end
end
-- Check if at least one valid genre was provided
if #genreList == 0 then
return formatError(i18n.errors.noGenreProvided)
end
-- Format genres with appropriate icons and separators
local genreOutput = formatGenres(genreList)
-- Log any invalid genres for debugging
for _, invalidGenre in ipairs(invalidGenres) do
mw.log(string.format(i18n.errors.invalidGenre, invalidGenre))
end
-- Handle channel URL and country flag
local channelUrl = ""
local channelDisplay = channel.name
local countryFlag = formatCountryFlag(channel.country, frame)
if channel.channel and channel.channel ~= '' then
channelUrl = BASE_URL .. channel.channel .. URL_SUFFIX .. TAB_SUFFIX
channelDisplay = string.format('%s[%s %s]', countryFlag, channelUrl, channel.name)
end
Line 128 ⟶ 231:
)
-- Add
local ns = mw.title.getCurrentTitle().namespace
if ns == 0 then
-- Add default category for all entries
result = result .. '[[Category:' .. DEFAULT_CATEGORY .. ']]'
-- Add genre-specific categories
for _, genre in ipairs(genreList) do
if GENRE_CATEGORIES[genre] then
result = result .. '[[Category:' .. GENRE_CATEGORIES[genre] .. ']]'
end
end
-- Add tracking category for main namespace
result = result .. '[[Category:Articles using XVideosRedList]]'
| |||