Content deleted Content added
No edit summary
No edit summary
Line 110:
-- Function to find and retrieve channel data from appropriate module
function getChannel(name)
if not name then return nil, i18n.errors.duplicateChannelschannelIsEmpty end
local modulesToTry = {}
table.insert(modulesToTry,local firstLetter = name:sub(1, 1):upper())
table.insert(modulesToTry, firstLetter)
-- Handle "The" prefix in channel names
local nameWithoutThe = name:lower():gsub("^the%s*", ""):gsub("%s*", "")
if nameWithoutThe ~= name:lower() then
table.insert(modulesToTry,local theFirstLetter = nameWithoutThe:sub(1, 1):upper())
if theFirstLetter ~= firstLetter then
table.insert(modulesToTry, theFirstLetter)
end
end
 
table.insert(modulesToTry, name:sub(1, 1):upper())
for _, module in ipairs(modulesToTry) do
local success, channelModule = pcall(require, 'Module:TVChannelList/' .. module)
if success then
if type(channelModule.redirects) == "table" and type(channelModule.redirects[name:lower(channels)] == "table" then
local matchedChannels = {}
local matchedChannels = {}
-- Check redirects using same pattern as CareerList
-- First try direct match or aliases
if channelModule.redirects and channelModule.redirects[name:lower()] then
returnfor getChannel_, channel in pairs(channelModule.redirects[name:lower()]channels) do
if channel.name:lower() == name:lower() or
end
(channel.aliases and table.contains(channel.aliases, name:lower())) then
-- Search using same pattern as CareerList table.insert(matchedChannels, channel)
for _, channel in pairs(channelModule.channels) do end
if channel.name:lower() == name:lower() or end
(channel.aliases and table.contains(channel.aliases, name:lower())) then
-- If found table.insert(matchedChannelsmatches, channel)return results
local if #matchedChannels => 1 {}then
return nil, i18n.errors.duplicateChannels
elseif #matchedChannels == 1 then
return matchedChannels[1]
end
-- If no direct matches found, try redirects
if channelModule.redirects and channelModule.redirects[name:lower()] then
return getChannel(channelModule.redirects[name:lower()])
end
endelse
mw.log('Invalid module structure: Module:TVChannelList/' .. module)
if #matchedChannels > 1 then
return nil, i18n.errors.duplicateChannels
elseif #matchedChannels == 1 then
return matchedChannels[1]
end
else