From 364cc902977ab99efb3131a36546976366a7674d Mon Sep 17 00:00:00 2001 From: hjpalpha Date: Wed, 26 Jun 2024 18:06:48 +0200 Subject: [PATCH 01/19] refactor `Module:Links/Stream` - get rid of some anno warnings - add display components (in prep for moving it from js to lua) - add filter function - allow 2nd stream for any platform --- standard/links_stream.lua | 189 ++++++++++++++++++++++++++++---------- 1 file changed, 140 insertions(+), 49 deletions(-) diff --git a/standard/links_stream.lua b/standard/links_stream.lua index 78463a6f89f..0cbd61feac6 100644 --- a/standard/links_stream.lua +++ b/standard/links_stream.lua @@ -11,18 +11,19 @@ Module containing utility functions for streaming platforms. ]] local StreamLinks = {} +local Array = require('Module:Array') local Class = require('Module:Class') local Logic = require('Module:Logic') +local Page = require('Module:Page') local String = require('Module:StringUtils') +local Table = require('Module:Table') local Variables = require('Module:Variables') ---[[ -List of streaming platforms supported in Module:Countdown. This is a subset of -the list in Module:Links -]] +local TL_STREAM = 'stream' + +--List of streaming platforms supported in Module:Countdown. StreamLinks.countdownPlatformNames = { 'afreeca', - 'afreecatv', 'bilibili', 'cc163', 'dailymotion', @@ -34,30 +35,32 @@ StreamLinks.countdownPlatformNames = { 'loco', 'mildom', 'nimo', - 'stream', + TL_STREAM, 'tl', 'trovo', 'twitch', - 'twitch2', 'youtube', } - ---[[ -Lookup table of allowed inputs that use a plattform with a different name -]] -StreamLinks.streamPlatformLookupNames = { - twitch2 = 'twitch', +local PLATFORM_TO_ICON = { + cc163 = 'cc', + huomao = 'huomaotv', + huya = 'huyatv', + himo = 'nimotv', } +---@param key string +---@return boolean +function StreamLinks.isStream(key) + return Array.any(StreamLinks.countdownPlatformNames, function(platform) + return String.startsWith(key, platform) + end) +end + ---Extracts the streaming platform args from an argument table for use in Module:Countdown. ---@param args {[string]: string} ---@return table function StreamLinks.readCountdownStreams(args) - local stream = {} - for _, platformName in ipairs(StreamLinks.countdownPlatformNames) do - stream[platformName] = args[platformName] - end - return stream + return Table.filterByKey(args, StreamLinks.isStream) end ---Resolves the value of a stream given the platform @@ -83,47 +86,133 @@ function StreamLinks.processStreams(forwardedInputArgs) forwardedInputArgs.stream = nil end + local processedStreams = {} for _, platformName in pairs(StreamLinks.countdownPlatformNames) do - local streamValue = Logic.emptyOr( - streams[platformName], - forwardedInputArgs[platformName], - Variables.varDefault(platformName) + local streamValues = Table.merge( + Table.filterByKey(forwardedInputArgs, StreamLinks.isStream), + Table.filterByKey(streams, StreamLinks.isStream) ) - if String.isNotEmpty(streamValue) then - -- stream has no platform - if platformName ~= 'stream' then - local lookUpPlatform = StreamLinks.streamPlatformLookupNames[platformName] or platformName + if Table.isEmpty(streamValues) then + streamValues = {[platformName] = Variables.varDefault(platformName)} + end + + Table.mergeInto(processedStreams, StreamLinks._processStreamsOfPlatform(streamValues, platformName)) + end + + return processedStreams +end + +---@param streamValues {[string]: string} +---@param platformName string +---@return {[string]: string} +function StreamLinks._processStreamsOfPlatform(streamValues, platformName) + local platformStreams = {} + local legacyStreams = {} + local enCounter = 0 + + for key, streamValue in Table.iter.spairs(streamValues) do + if platformName ~= TL_STREAM then + streamValue = StreamLinks.resolve(platformName, streamValue) + end - streamValue = StreamLinks.resolve(lookUpPlatform, streamValue) + -- legacy key + if key:match('^' .. platformName .. '%d*$') then + table.insert(legacyStreams, streamValue) + elseif key:match('^' .. platformName .. '_%a+_%d+') then + local streamKey = StreamLinks.StreamKey(key) + if streamKey.languageCode == 'en' then + enCounter = enCounter + 1 end + platformStreams[streamKey:toString()] = streamValue + end + end - local key = StreamLinks.StreamKey(platformName):toString() - streams[key] = streamValue - streams[platformName] = streamValue -- Legacy + for _, streamValue in ipairs(legacyStreams) do + if not Table.includes(platformStreams, streamValue) then + enCounter = enCounter + 1 + local streamKey = StreamLinks.StreamKey(platformName, 'en', enCounter):toString() + platformStreams[streamKey] = streamValue + platformStreams[platformName] = streamValue -- Legacy end end + return platformStreams +end + +---@param platform string +---@param streamValue string +---@return string? +function StreamLinks.displaySingle(platform, streamValue) + local icon = '' + if platform == TL_STREAM then + return Page.makeExternalLink(icon, 'https://tl.net/video/streams/' .. streamValue) + end + + local streamLink = StreamLinks.resolve(platform, streamValue) + if not streamLink then return nil end + + return Page.makeInternalLink({}, icon, 'Special:Stream/' .. platform .. '/' .. streamValue) +end + +---@param streams {string: string[]} +---@return string? +function StreamLinks.display(streams) + local displays = {} + Array.forEach(StreamLinks.countdownPlatformNames, function(platform) + Array.forEach(streams[platform] or {}, function(streamValue) + table.insert(displays, StreamLinks.displaySingle(platform, streamValue)) + end) + end) + if Table.isEmpty(displays) then return nil end + return table.concat(displays, ' ') +end + +---filters streams so that if english streams are present only those are returned +---@param streamsInput {string: string} +---@return {string: string[]} +function StreamLinks.filterStreams(streamsInput) + local hasEnglishStream = Table.any(streamsInput, function(key) + return key:match('_en_') or Table.includes(StreamLinks.countdownPlatformNames, key) + end) + + local streams = {} + for rawHost, stream in Table.iter.spairs(streamsInput) do + if #(mw.text.split(rawHost, '_', true)) == 3 then + local streamKey = StreamLinks.StreamKey(rawHost) + local platform = streamKey.platform + if not streams[platform] then + streams[platform] = {} + end + table.insert(streams[platform], (not hasEnglishStream or streamKey.languageCode == 'en') and stream or nil) + end + end + + Array.forEach(StreamLinks.countdownPlatformNames, function(platformName) + local stream = streamsInput[platformName] + if type(streams[platformName]) == 'table' or String.isEmpty(stream) then return end + streams[platformName] = {stream, streamsInput[platformName .. 2]} + end) + return streams end --- StreamKey Class -- Contains the triplet that makes up a stream key -- [platform, languageCode, index] ----@class StreamKey +---@class StreamKey: BaseClass ---@operator call(...): StreamKey ---@field platform string ---@field languageCode string ---@field index integer ----@field is_a function -StreamLinks.StreamKey = Class.new( +local StreamKey = Class.new( function (self, ...) self:new(...) end ) -local StreamKey = StreamLinks.StreamKey +StreamLinks.StreamKey = StreamKey ----@param tbl string +---@param tbl string|StreamKey ---@param languageCode string ---@param index integer ---@overload fun(self, tbl: StreamKey): StreamKey @@ -142,11 +231,15 @@ function StreamKey:new(tbl, languageCode, index) local components = mw.text.split(tbl, '_', true) -- Input is in legacy format (eg. twitch2) if #components == 1 then - platform, index = self:_fromLegacy(tbl) + local tempIndex + platform, tempIndex = self:_fromLegacy(tbl) + index = tempIndex or index languageCode = 'en' -- Input is a StreamKey in string format elseif #components == 3 then - platform, languageCode, index = unpack(components) + local stringIndex + platform, languageCode, stringIndex = unpack(components) + index = tonumber(stringIndex) --[[@as integer]] end end @@ -161,27 +254,24 @@ end ---@return string?, integer? function StreamKey:_fromLegacy(input) for _, platform in pairs(StreamLinks.countdownPlatformNames) do - -- The intersection of values in countdownPlatformNames and keys in streamPlatformLookupNames - -- are not valid platforms. E.g. "twitch2" is not a valid platform. - if not StreamLinks.streamPlatformLookupNames[platform] then - -- Check if this platform matches the input - if string.find(input, platform .. '%d-$') then - local index = 1 - -- If the input is longer than the platform, there's an index at the end - -- Eg. In "twitch2", the 2 would the index. - if #input > #platform then - index = tonumber(input:sub(#platform + 1)) --[[@as integer]] - end - return platform, index + if string.find(input, platform .. '%d-$') then + local index = 1 + -- If the input is longer than the platform, there's an index at the end + -- Eg. In "twitch2", the 2 would be the index. + if #input > #platform then + index = tonumber(input:sub(#platform + 1)) or index end + return platform, index end end end +---@return string function StreamKey:toString() return self.platform .. '_' .. self.languageCode .. '_' .. self.index end +---@return string function StreamKey:toLegacy() -- Return twitch instead of twitch1 if self.index == 1 then @@ -190,6 +280,7 @@ function StreamKey:toLegacy() return self.platform .. self.index end +---@return boolean function StreamKey:_isValid() assert(Logic.isNotEmpty(self.platform), 'StreamKey: Platform is required') assert(Logic.isNotEmpty(self.languageCode), 'StreamKey: Language Code is required') From e906b159e5c140db6f0f06ca069497e69a2d17ee Mon Sep 17 00:00:00 2001 From: hjpalpha Date: Wed, 26 Jun 2024 18:26:14 +0200 Subject: [PATCH 02/19] add `module:COuntdown` --- standard/countdown.lua | 59 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 standard/countdown.lua diff --git a/standard/countdown.lua b/standard/countdown.lua new file mode 100644 index 00000000000..b8434a07885 --- /dev/null +++ b/standard/countdown.lua @@ -0,0 +1,59 @@ +--- +-- @Liquipedia +-- wiki=commons +-- page=Module:Countdown +-- +-- Please see https://github.com/Liquipedia/Lua-Modules to contribute +-- + +local Arguments = require('Module:Arguments') +local DateExt = require('Module:Date/Ext') +local Logic = require('Module:Logic') +local StreamLinks = require('Module:Links/Stream') + +local Countdown = {} + +---@param frame Frame +---@return string +function Countdown.create(frame) + return Countdown._create(Arguments.getArgs(frame)) +end + +---@param args table +---@return string +function Countdown._create(args) + if Logic.isEmpty(args.date) and not args.timestamp then + return '' + end + + local wrapper = mw.html.create('span') + :addClass('timer-object') + + if Logic.readBool(args.rawcountdown) then + wrapper:addClass('timer-object-countdown-only') + end + if Logic.readBool(args.rawdatetime) then + wrapper:addClass('timer-object-datetime-only') + end + if Logic.readBool(args.finished) then + wrapper:attr('data-finished', 'finished') + else + wrapper:attr('data-streams', StreamLinks.display(StreamLinks.filterStreams(args))) + end + + -- Timestamp + wrapper:attr('data-timestamp', args.timestamp or DateExt.readTimestampOrNil(args.date) or 'error') + + if args.text then + wrapper:attr('data-countdown-end-text', args.text) + end + if args.separator then + wrapper:attr('data-separator', args.separator) + end + + wrapper:wikitext(args.date) + + return tostring(wrapper:done()) +end + +return Countdown From c1fbe6afde78b11627daed036c7b75d29304f951 Mon Sep 17 00:00:00 2001 From: hjpalpha Date: Wed, 26 Jun 2024 18:31:06 +0200 Subject: [PATCH 03/19] adjust the js & add option to not show streams --- javascript/commons/Countdown.js | 67 +-------------------------------- standard/countdown.lua | 2 +- 2 files changed, 3 insertions(+), 66 deletions(-) diff --git a/javascript/commons/Countdown.js b/javascript/commons/Countdown.js index 90e8a8bc7fc..796a2a7ed9e 100644 --- a/javascript/commons/Countdown.js +++ b/javascript/commons/Countdown.js @@ -70,7 +70,6 @@ liquipedia.countdown = { ); }, setCountdownString: function( timerObjectNode ) { - const streamsarr = [ ]; let datestr = '', live = 'LIVE!'; if ( typeof timerObjectNode.dataset.countdownEndText !== 'undefined' ) { live = timerObjectNode.dataset.countdownEndText; @@ -106,75 +105,13 @@ liquipedia.countdown = { } else { datestr = ''; // DATE ERROR! } - if ( timerObjectNode.dataset.streamTwitch ) { - streamsarr.push( '' ); - } - if ( timerObjectNode.dataset.streamTwitch2 ) { - streamsarr.push( '' ); - } - if ( timerObjectNode.dataset.streamYoutube ) { - streamsarr.push( '' ); - } - if ( timerObjectNode.dataset.streamAfreeca ) { - streamsarr.push( '' ); - } - if ( timerObjectNode.dataset.streamAfreecatv ) { - streamsarr.push( '' ); - } - if ( timerObjectNode.dataset.streamBilibili ) { - streamsarr.push( '' ); - } - if ( timerObjectNode.dataset.streamBooyah ) { - streamsarr.push( '' ); - } - if ( timerObjectNode.dataset.streamCc163 ) { - streamsarr.push( '' ); - } - if ( timerObjectNode.dataset.streamDailymotion ) { - streamsarr.push( '' ); - } - if ( timerObjectNode.dataset.streamDouyu ) { - streamsarr.push( '' ); - } - if ( timerObjectNode.dataset.streamFacebook ) { - streamsarr.push( '' ); - } - if ( timerObjectNode.dataset.streamHuomao ) { - streamsarr.push( '' ); - } - if ( timerObjectNode.dataset.streamHuya ) { - streamsarr.push( '' ); - } - if ( timerObjectNode.dataset.streamKick ) { - streamsarr.push( '' ); - } - if ( timerObjectNode.dataset.streamLoco ) { - streamsarr.push( '' ); - } - if ( timerObjectNode.dataset.streamMildom ) { - streamsarr.push( '' ); - } - if ( timerObjectNode.dataset.streamNimo ) { - streamsarr.push( '' ); - } - if ( timerObjectNode.dataset.streamTrovo ) { - streamsarr.push( '' ); - } - if ( timerObjectNode.dataset.streamTl ) { - streamsarr.push( '' ); - } let html = '' + datestr + ''; - if ( datestr.length > 0 && streamsarr.length > 0 ) { + if ( datestr.length > 0 && timerObjectNode.dataset.streams.length > 0 ) { html += ' - '; - } - if ( timerObjectNode.dataset.finished !== 'finished' ) { - html += streamsarr.join( ' ' ); + html += timerObjectNode.dataset.streams; } timerObjectNode.querySelector( '.timer-object-countdown' ).innerHTML = html; }, - getStreamName: function( url ) { - return url.replace( /\s/g, '_' ); - }, timeZoneAbbr: new Map( [ [ 'Acre Time', 'ACT' ], [ 'Afghanistan Time', 'AFT' ], diff --git a/standard/countdown.lua b/standard/countdown.lua index b8434a07885..7c899b864d3 100644 --- a/standard/countdown.lua +++ b/standard/countdown.lua @@ -37,7 +37,7 @@ function Countdown._create(args) end if Logic.readBool(args.finished) then wrapper:attr('data-finished', 'finished') - else + elseif not Logic.readBool(args.nostreams) then wrapper:attr('data-streams', StreamLinks.display(StreamLinks.filterStreams(args))) end From 61eee43e76ca618798c4068b3b194dbd028d55cd Mon Sep 17 00:00:00 2001 From: hjpalpha Date: Fri, 28 Jun 2024 12:10:59 +0200 Subject: [PATCH 04/19] make space between the streams options --- standard/countdown.lua | 2 +- standard/links_stream.lua | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/standard/countdown.lua b/standard/countdown.lua index 7c899b864d3..dbeecc81804 100644 --- a/standard/countdown.lua +++ b/standard/countdown.lua @@ -38,7 +38,7 @@ function Countdown._create(args) if Logic.readBool(args.finished) then wrapper:attr('data-finished', 'finished') elseif not Logic.readBool(args.nostreams) then - wrapper:attr('data-streams', StreamLinks.display(StreamLinks.filterStreams(args))) + wrapper:attr('data-streams', StreamLinks.display(StreamLinks.filterStreams(args), {addSpace = true})) end -- Timestamp diff --git a/standard/links_stream.lua b/standard/links_stream.lua index 0cbd61feac6..6820689f275 100644 --- a/standard/links_stream.lua +++ b/standard/links_stream.lua @@ -156,8 +156,10 @@ function StreamLinks.displaySingle(platform, streamValue) end ---@param streams {string: string[]} +---@param options {addSpace: boolean?}? ---@return string? -function StreamLinks.display(streams) +function StreamLinks.display(streams, options) + options = options or {} local displays = {} Array.forEach(StreamLinks.countdownPlatformNames, function(platform) Array.forEach(streams[platform] or {}, function(streamValue) @@ -165,7 +167,7 @@ function StreamLinks.display(streams) end) end) if Table.isEmpty(displays) then return nil end - return table.concat(displays, ' ') + return table.concat(displays, options.addSpace and ' ' or nil) end ---filters streams so that if english streams are present only those are returned From c3e4bac1c2d26b8b0c09da446665decf1cf8dc86 Mon Sep 17 00:00:00 2001 From: hjpalpha Date: Fri, 5 Jul 2024 17:56:53 +0200 Subject: [PATCH 05/19] move stream adding completely to lua --- javascript/commons/Countdown.js | 11 ++++------- standard/countdown.lua | 21 +++++++++++++++++---- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/javascript/commons/Countdown.js b/javascript/commons/Countdown.js index 796a2a7ed9e..d3c74121dc6 100644 --- a/javascript/commons/Countdown.js +++ b/javascript/commons/Countdown.js @@ -45,7 +45,8 @@ liquipedia.countdown = { countdownChild.classList.add( 'timer-object-countdown' ); timerObjectNode.appendChild( countdownChild ); } ); - // Only run when the window is actually in the front, not in background tabs (on browsers that support it) + // Only run when the window is actually in the front, + // not in background tabs (on browsers that support it) mw.loader.using( 'mediawiki.visibleTimeout' ).then( ( require ) => { liquipedia.countdown.timeoutFunctions = require( 'mediawiki.visibleTimeout' ); liquipedia.countdown.runCountdown(); @@ -105,12 +106,8 @@ liquipedia.countdown = { } else { datestr = ''; // DATE ERROR! } - let html = '' + datestr + ''; - if ( datestr.length > 0 && timerObjectNode.dataset.streams.length > 0 ) { - html += ' - '; - html += timerObjectNode.dataset.streams; - } - timerObjectNode.querySelector( '.timer-object-countdown' ).innerHTML = html; + timerObjectNode.querySelector( '.timer-object-countdown' ).innerHTML = + '' + datestr + ''; }, timeZoneAbbr: new Map( [ [ 'Acre Time', 'ACT' ], diff --git a/standard/countdown.lua b/standard/countdown.lua index dbeecc81804..0c910d5bfee 100644 --- a/standard/countdown.lua +++ b/standard/countdown.lua @@ -9,7 +9,9 @@ local Arguments = require('Module:Arguments') local DateExt = require('Module:Date/Ext') local Logic = require('Module:Logic') -local StreamLinks = require('Module:Links/Stream') +local Lua = require('Module:Lua') + +local StreamLinks = Lua.import('Module:Links/Stream') local Countdown = {} @@ -35,14 +37,17 @@ function Countdown._create(args) if Logic.readBool(args.rawdatetime) then wrapper:addClass('timer-object-datetime-only') end + + local streams if Logic.readBool(args.finished) then wrapper:attr('data-finished', 'finished') elseif not Logic.readBool(args.nostreams) then - wrapper:attr('data-streams', StreamLinks.display(StreamLinks.filterStreams(args), {addSpace = true})) + streams = StreamLinks.display(StreamLinks.filterStreams(args), {addSpace = true}) end -- Timestamp - wrapper:attr('data-timestamp', args.timestamp or DateExt.readTimestampOrNil(args.date) or 'error') + local timestamp = args.timestamp or DateExt.readTimestampOrNil(args.date) or 'error' + wrapper:attr('data-timestamp', timestamp) if args.text then wrapper:attr('data-countdown-end-text', args.text) @@ -53,7 +58,15 @@ function Countdown._create(args) wrapper:wikitext(args.date) - return tostring(wrapper:done()) + if Logic.isEmpty(streams) then + return tostring(wrapper) + end + + return tostring(mw.html.create() + :node(wrapper) + :wikitext(Logic.isNumeric(timestamp) and ' - ' or nil) + :wikitext(streams) + ) end return Countdown From d8a7476388f8996f9163776bc561720ed12038c2 Mon Sep 17 00:00:00 2001 From: hjpalpha Date: Fri, 5 Jul 2024 18:08:48 +0200 Subject: [PATCH 06/19] simplify as per review --- standard/links_stream.lua | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/standard/links_stream.lua b/standard/links_stream.lua index 6820689f275..26305b86e1d 100644 --- a/standard/links_stream.lua +++ b/standard/links_stream.lua @@ -86,19 +86,15 @@ function StreamLinks.processStreams(forwardedInputArgs) forwardedInputArgs.stream = nil end - local processedStreams = {} - for _, platformName in pairs(StreamLinks.countdownPlatformNames) do - local streamValues = Table.merge( - Table.filterByKey(forwardedInputArgs, StreamLinks.isStream), - Table.filterByKey(streams, StreamLinks.isStream) - ) - - if Table.isEmpty(streamValues) then - streamValues = {[platformName] = Variables.varDefault(platformName)} - end + streams = Table.merge( + Table.filterByKey(forwardedInputArgs, StreamLinks.isStream), + Table.filterByKey(streams, StreamLinks.isStream) + ) - Table.mergeInto(processedStreams, StreamLinks._processStreamsOfPlatform(streamValues, platformName)) - end + local processedStreams = {} + Array.forEach(StreamLinks.countdownPlatformNames, function(platformName) + Table.mergeInto(processedStreams, StreamLinks._processStreamsOfPlatform(streams, platformName)) + end) return processedStreams end @@ -137,6 +133,10 @@ function StreamLinks._processStreamsOfPlatform(streamValues, platformName) end end + if Logic.isEmpty(platformStreams) then + platformStreams = {[platformName] = Variables.varDefault(platformName)} + end + return platformStreams end From 41cf2c04212d7d0835598cc7b089d83e160a0178 Mon Sep 17 00:00:00 2001 From: hjpalpha Date: Fri, 5 Jul 2024 18:20:12 +0200 Subject: [PATCH 07/19] do not display dash if live is over (12h, same as in js) --- standard/countdown.lua | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/standard/countdown.lua b/standard/countdown.lua index 0c910d5bfee..626291c144c 100644 --- a/standard/countdown.lua +++ b/standard/countdown.lua @@ -13,6 +13,8 @@ local Lua = require('Module:Lua') local StreamLinks = Lua.import('Module:Links/Stream') +local NOW = os.time() + local Countdown = {} ---@param frame Frame @@ -62,9 +64,12 @@ function Countdown._create(args) return tostring(wrapper) end + local sep = Logic.isNumeric(timestamp) and NOW < timestamp + 43200 + and ' - ' or nil + return tostring(mw.html.create() :node(wrapper) - :wikitext(Logic.isNumeric(timestamp) and ' - ' or nil) + :wikitext(sep) :wikitext(streams) ) end From 73092a009ee15d32b97eadb777c233690ff7dece Mon Sep 17 00:00:00 2001 From: hjpalpha Date: Mon, 8 Jul 2024 12:27:33 +0200 Subject: [PATCH 08/19] rename const var as per review --- standard/links_stream.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/standard/links_stream.lua b/standard/links_stream.lua index 26305b86e1d..88f71c331c3 100644 --- a/standard/links_stream.lua +++ b/standard/links_stream.lua @@ -19,7 +19,7 @@ local String = require('Module:StringUtils') local Table = require('Module:Table') local Variables = require('Module:Variables') -local TL_STREAM = 'stream' +local TLNET_STREAM = 'stream' --List of streaming platforms supported in Module:Countdown. StreamLinks.countdownPlatformNames = { @@ -35,7 +35,7 @@ StreamLinks.countdownPlatformNames = { 'loco', 'mildom', 'nimo', - TL_STREAM, + TLNET_STREAM, 'tl', 'trovo', 'twitch', @@ -108,7 +108,7 @@ function StreamLinks._processStreamsOfPlatform(streamValues, platformName) local enCounter = 0 for key, streamValue in Table.iter.spairs(streamValues) do - if platformName ~= TL_STREAM then + if platformName ~= TLNET_STREAM then streamValue = StreamLinks.resolve(platformName, streamValue) end @@ -145,7 +145,7 @@ end ---@return string? function StreamLinks.displaySingle(platform, streamValue) local icon = '' - if platform == TL_STREAM then + if platform == TLNET_STREAM then return Page.makeExternalLink(icon, 'https://tl.net/video/streams/' .. streamValue) end From d001c31db01391d5f5e7399781f359e50f74efc9 Mon Sep 17 00:00:00 2001 From: hjpalpha Date: Mon, 8 Jul 2024 12:34:41 +0200 Subject: [PATCH 09/19] refactor finished handling --- standard/countdown.lua | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/standard/countdown.lua b/standard/countdown.lua index 626291c144c..02fb504125c 100644 --- a/standard/countdown.lua +++ b/standard/countdown.lua @@ -40,17 +40,20 @@ function Countdown._create(args) wrapper:addClass('timer-object-datetime-only') end + -- Timestamp + local timestamp = args.timestamp or DateExt.readTimestampOrNil(args.date) or 'error' + wrapper:attr('data-timestamp', timestamp) + local streams - if Logic.readBool(args.finished) then + local isFinished = Logic.readBool(args.finished) + -- the js assumes a match finished if the match is live for 12 hours + or (NOW >= timestamp + 43200) + if isFinished then wrapper:attr('data-finished', 'finished') elseif not Logic.readBool(args.nostreams) then streams = StreamLinks.display(StreamLinks.filterStreams(args), {addSpace = true}) end - -- Timestamp - local timestamp = args.timestamp or DateExt.readTimestampOrNil(args.date) or 'error' - wrapper:attr('data-timestamp', timestamp) - if args.text then wrapper:attr('data-countdown-end-text', args.text) end @@ -64,9 +67,6 @@ function Countdown._create(args) return tostring(wrapper) end - local sep = Logic.isNumeric(timestamp) and NOW < timestamp + 43200 - and ' - ' or nil - return tostring(mw.html.create() :node(wrapper) :wikitext(sep) From a21092633f5c49ab791aa7d4d32d1d20423668f4 Mon Sep 17 00:00:00 2001 From: hjpalpha Date: Mon, 8 Jul 2024 12:41:20 +0200 Subject: [PATCH 10/19] fix --- standard/countdown.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/standard/countdown.lua b/standard/countdown.lua index 02fb504125c..b6d3209f59c 100644 --- a/standard/countdown.lua +++ b/standard/countdown.lua @@ -69,7 +69,7 @@ function Countdown._create(args) return tostring(mw.html.create() :node(wrapper) - :wikitext(sep) + :wikitext(isFinished and ' - ' or nil) :wikitext(streams) ) end From 63231d3174609e2f2cc415fc42e215c282cb47c2 Mon Sep 17 00:00:00 2001 From: hjpalpha Date: Mon, 8 Jul 2024 12:42:35 +0200 Subject: [PATCH 11/19] invert --- standard/countdown.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/standard/countdown.lua b/standard/countdown.lua index b6d3209f59c..ea99b75209e 100644 --- a/standard/countdown.lua +++ b/standard/countdown.lua @@ -69,7 +69,7 @@ function Countdown._create(args) return tostring(mw.html.create() :node(wrapper) - :wikitext(isFinished and ' - ' or nil) + :wikitext(not isFinished and ' - ' or nil) :wikitext(streams) ) end From 6996e032db9f0bef9a81c92710ef7949d234bb68 Mon Sep 17 00:00:00 2001 From: hjpalpha <75081997+hjpalpha@users.noreply.github.com> Date: Tue, 9 Jul 2024 11:57:51 +0200 Subject: [PATCH 12/19] Update standard/links_stream.lua --- standard/links_stream.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/standard/links_stream.lua b/standard/links_stream.lua index 88f71c331c3..a2245e870c0 100644 --- a/standard/links_stream.lua +++ b/standard/links_stream.lua @@ -214,7 +214,7 @@ local StreamKey = Class.new( ) StreamLinks.StreamKey = StreamKey ----@param tbl string|StreamKey +---@param tbl string ---@param languageCode string ---@param index integer ---@overload fun(self, tbl: StreamKey): StreamKey From 7d31a532194da81cc4cb45677d8e7163e878b782 Mon Sep 17 00:00:00 2001 From: hjpalpha Date: Thu, 11 Jul 2024 17:43:49 +0200 Subject: [PATCH 13/19] mirror old behaviour exactly - let js add the ` - ` with the same criteria as before - display streams if finished is not set but the time switch has already happened --> it will again show the date together with the stream but without dash and countdown --- javascript/commons/Countdown.js | 7 +++++-- standard/countdown.lua | 10 +++++----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/javascript/commons/Countdown.js b/javascript/commons/Countdown.js index d3c74121dc6..83ed8389f7e 100644 --- a/javascript/commons/Countdown.js +++ b/javascript/commons/Countdown.js @@ -106,8 +106,11 @@ liquipedia.countdown = { } else { datestr = ''; // DATE ERROR! } - timerObjectNode.querySelector( '.timer-object-countdown' ).innerHTML = - '' + datestr + ''; + let html = '' + datestr + ''; + if ( datestr.length > 0 && timerObjectNode.dataset.hasstreams === 'true' ) { + html += ' - '; + } + timerObjectNode.querySelector( '.timer-object-countdown' ).innerHTML = html; }, timeZoneAbbr: new Map( [ [ 'Acre Time', 'ACT' ], diff --git a/standard/countdown.lua b/standard/countdown.lua index ea99b75209e..455528adf95 100644 --- a/standard/countdown.lua +++ b/standard/countdown.lua @@ -45,14 +45,15 @@ function Countdown._create(args) wrapper:attr('data-timestamp', timestamp) local streams - local isFinished = Logic.readBool(args.finished) - -- the js assumes a match finished if the match is live for 12 hours - or (NOW >= timestamp + 43200) - if isFinished then + if Logic.readBool(args.finished) then wrapper:attr('data-finished', 'finished') elseif not Logic.readBool(args.nostreams) then streams = StreamLinks.display(StreamLinks.filterStreams(args), {addSpace = true}) end + if streams then + wrapper:attr('data-hasstreams', 'true') + end + if args.text then wrapper:attr('data-countdown-end-text', args.text) @@ -69,7 +70,6 @@ function Countdown._create(args) return tostring(mw.html.create() :node(wrapper) - :wikitext(not isFinished and ' - ' or nil) :wikitext(streams) ) end From 375668549ef9add4c03481dec1fc40583ffceae7 Mon Sep 17 00:00:00 2001 From: hjpalpha Date: Thu, 11 Jul 2024 17:48:22 +0200 Subject: [PATCH 14/19] kick unused const var --- standard/countdown.lua | 2 -- 1 file changed, 2 deletions(-) diff --git a/standard/countdown.lua b/standard/countdown.lua index 455528adf95..e3a91dcab31 100644 --- a/standard/countdown.lua +++ b/standard/countdown.lua @@ -13,8 +13,6 @@ local Lua = require('Module:Lua') local StreamLinks = Lua.import('Module:Links/Stream') -local NOW = os.time() - local Countdown = {} ---@param frame Frame From 9e10572acd289c5900caf129b54cee2b1379045c Mon Sep 17 00:00:00 2001 From: hjpalpha <75081997+hjpalpha@users.noreply.github.com> Date: Mon, 15 Jul 2024 14:37:55 +0200 Subject: [PATCH 15/19] Update standard/links_stream.lua Co-authored-by: Rikard Blixt --- standard/links_stream.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/standard/links_stream.lua b/standard/links_stream.lua index a2245e870c0..e8496f43304 100644 --- a/standard/links_stream.lua +++ b/standard/links_stream.lua @@ -170,7 +170,7 @@ function StreamLinks.display(streams, options) return table.concat(displays, options.addSpace and ' ' or nil) end ----filters streams so that if english streams are present only those are returned +---Filter non-english streams if english streams exists ---@param streamsInput {string: string} ---@return {string: string[]} function StreamLinks.filterStreams(streamsInput) From 9a690174df6f13599c514f977edbd5d70cce94dd Mon Sep 17 00:00:00 2001 From: hjpalpha Date: Mon, 15 Jul 2024 15:13:14 +0200 Subject: [PATCH 16/19] as per review --- standard/links_stream.lua | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/standard/links_stream.lua b/standard/links_stream.lua index e8496f43304..0d263f856e8 100644 --- a/standard/links_stream.lua +++ b/standard/links_stream.lua @@ -25,28 +25,22 @@ local TLNET_STREAM = 'stream' StreamLinks.countdownPlatformNames = { 'afreeca', 'bilibili', - 'cc163', + 'cc', 'dailymotion', 'douyu', 'facebook', - 'huomao', - 'huya', + 'huomaotv', + 'huyatv', 'kick', 'loco', 'mildom', - 'nimo', + 'nimotv', TLNET_STREAM, 'tl', 'trovo', 'twitch', 'youtube', } -local PLATFORM_TO_ICON = { - cc163 = 'cc', - huomao = 'huomaotv', - huya = 'huyatv', - himo = 'nimotv', -} ---@param key string ---@return boolean @@ -144,7 +138,7 @@ end ---@param streamValue string ---@return string? function StreamLinks.displaySingle(platform, streamValue) - local icon = '' + local icon = '' if platform == TLNET_STREAM then return Page.makeExternalLink(icon, 'https://tl.net/video/streams/' .. streamValue) end @@ -233,9 +227,7 @@ function StreamKey:new(tbl, languageCode, index) local components = mw.text.split(tbl, '_', true) -- Input is in legacy format (eg. twitch2) if #components == 1 then - local tempIndex - platform, tempIndex = self:_fromLegacy(tbl) - index = tempIndex or index + platform, index = self:_fromLegacy(tbl) languageCode = 'en' -- Input is a StreamKey in string format elseif #components == 3 then @@ -253,7 +245,7 @@ function StreamKey:new(tbl, languageCode, index) end ---@param input string ----@return string?, integer? +---@return string, integer function StreamKey:_fromLegacy(input) for _, platform in pairs(StreamLinks.countdownPlatformNames) do if string.find(input, platform .. '%d-$') then @@ -262,10 +254,12 @@ function StreamKey:_fromLegacy(input) -- Eg. In "twitch2", the 2 would be the index. if #input > #platform then index = tonumber(input:sub(#platform + 1)) or index + assert(index, '"' .. input .. '" is not a supported stream key') end return platform, index end end + error('"' .. input .. '" is not a supported stream key') end ---@return string From c2cadfeadc9e358e1f2f3f8e5f05c2004c692000 Mon Sep 17 00:00:00 2001 From: hjpalpha Date: Mon, 15 Jul 2024 15:56:19 +0200 Subject: [PATCH 17/19] as per review --- standard/links_stream.lua | 6 +++--- stylesheets/commons/Icons.less | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/standard/links_stream.lua b/standard/links_stream.lua index 0d263f856e8..b76d9bd7929 100644 --- a/standard/links_stream.lua +++ b/standard/links_stream.lua @@ -29,12 +29,12 @@ StreamLinks.countdownPlatformNames = { 'dailymotion', 'douyu', 'facebook', - 'huomaotv', - 'huyatv', + 'huomao', + 'huya', 'kick', 'loco', 'mildom', - 'nimotv', + 'nimo', TLNET_STREAM, 'tl', 'trovo', diff --git a/stylesheets/commons/Icons.less b/stylesheets/commons/Icons.less index e058a74dd54..fc0641f872b 100644 --- a/stylesheets/commons/Icons.less +++ b/stylesheets/commons/Icons.less @@ -118,6 +118,7 @@ Note: When adding a new icon, please add to .icon-make-image( mixer, "//liquipedia.net/commons/images/8/85/InfoboxIcon_Mixer.png" ); .icon-make-image( music, "//liquipedia.net/commons/images/3/37/InfoboxIcon_Music.png" ); .icon-make-image( niconico, "//liquipedia.net/commons/images/b/bf/InfoboxIcon_Niconico.png" ); + .icon-make-image( nimo, "//liquipedia.net/commons/images/f/f7/InfoboxIcon_NimoTV.png" ); .icon-make-image( nimotv, "//liquipedia.net/commons/images/f/f7/InfoboxIcon_NimoTV.png" ); .icon-make-image( nwc3l, "//liquipedia.net/commons/images/1/1c/InfoboxIcon_NWC3L.png" ); .icon-make-image( octane, "//liquipedia.net/commons/images/d/da/InfoboxIcon_Octane.png" ); From 0e3c5ff5a734a0a23e061879d2839ff756c433ca Mon Sep 17 00:00:00 2001 From: hjpalpha Date: Mon, 15 Jul 2024 16:59:45 +0200 Subject: [PATCH 18/19] as per review --- standard/countdown.lua | 3 ++- standard/links_stream.lua | 7 +++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/standard/countdown.lua b/standard/countdown.lua index e3a91dcab31..90778ecf0fb 100644 --- a/standard/countdown.lua +++ b/standard/countdown.lua @@ -46,9 +46,10 @@ function Countdown._create(args) if Logic.readBool(args.finished) then wrapper:attr('data-finished', 'finished') elseif not Logic.readBool(args.nostreams) then - streams = StreamLinks.display(StreamLinks.filterStreams(args), {addSpace = true}) + streams = StreamLinks.buildDisplays(StreamLinks.filterStreams(args), {addSpace = true}) end if streams then + streams = table.concat(streams, ' ') wrapper:attr('data-hasstreams', 'true') end diff --git a/standard/links_stream.lua b/standard/links_stream.lua index b76d9bd7929..209ffb50408 100644 --- a/standard/links_stream.lua +++ b/standard/links_stream.lua @@ -151,8 +151,8 @@ end ---@param streams {string: string[]} ---@param options {addSpace: boolean?}? ----@return string? -function StreamLinks.display(streams, options) +---@return string[]? +function StreamLinks.buildDisplays(streams, options) options = options or {} local displays = {} Array.forEach(StreamLinks.countdownPlatformNames, function(platform) @@ -160,8 +160,7 @@ function StreamLinks.display(streams, options) table.insert(displays, StreamLinks.displaySingle(platform, streamValue)) end) end) - if Table.isEmpty(displays) then return nil end - return table.concat(displays, options.addSpace and ' ' or nil) + return Table.isNotEmpty(displays) and displays or nil end ---Filter non-english streams if english streams exists From 3a42523502e616540f45a2e8af72ed1bf4cbf6ae Mon Sep 17 00:00:00 2001 From: hjpalpha Date: Mon, 15 Jul 2024 17:09:59 +0200 Subject: [PATCH 19/19] thx, linter --- standard/countdown.lua | 2 +- standard/links_stream.lua | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/standard/countdown.lua b/standard/countdown.lua index 90778ecf0fb..bf4210c2f33 100644 --- a/standard/countdown.lua +++ b/standard/countdown.lua @@ -46,7 +46,7 @@ function Countdown._create(args) if Logic.readBool(args.finished) then wrapper:attr('data-finished', 'finished') elseif not Logic.readBool(args.nostreams) then - streams = StreamLinks.buildDisplays(StreamLinks.filterStreams(args), {addSpace = true}) + streams = StreamLinks.buildDisplays(StreamLinks.filterStreams(args)) end if streams then streams = table.concat(streams, ' ') diff --git a/standard/links_stream.lua b/standard/links_stream.lua index 209ffb50408..98f19a41a8d 100644 --- a/standard/links_stream.lua +++ b/standard/links_stream.lua @@ -150,10 +150,8 @@ function StreamLinks.displaySingle(platform, streamValue) end ---@param streams {string: string[]} ----@param options {addSpace: boolean?}? ---@return string[]? -function StreamLinks.buildDisplays(streams, options) - options = options or {} +function StreamLinks.buildDisplays(streams) local displays = {} Array.forEach(StreamLinks.countdownPlatformNames, function(platform) Array.forEach(streams[platform] or {}, function(streamValue)