메뉴 여닫기
환경 설정 메뉴 여닫기
개인 메뉴 여닫기
로그인하지 않음
지금 편집한다면 당신의 IP 주소가 공개될 수 있습니다.

(2025. 11. 12.) 제작자 문서에 대한 양식이 추가되었습니다. 공지 보기

이 모듈에 대한 설명문서는 모듈:월별 최초공개 릴레이/설명문서에서 만들 수 있습니다

local p = {}

function p.main(frame)
	
    local month = frame.args[1] or frame.args["월"]
    
    if not month or mw.text.trim(month) == "" then
        return '<span class="error">월(month) 변수가 입력되지 않았습니다. (예: 2025-08)</span>'
    end
    
    -- 앞뒤 공백 제거
    month = mw.text.trim(month)

    -- YYYY-MM 형식 검사 (숫자 4자리-숫자 2자리)
    if not string.match(month, "^%d%d%d%d%-%d%d$") then
        return '<span class="error">잘못된 날짜 형식입니다. YYYY-MM 형식으로 입력해주세요. (입력값: ' .. mw.text.nowiki(month) .. ')</span>'
    end
    
    local target_url = "https://changpop.wiki/premiere-relay-archive/api.php?month=" .. month
    
    -- ExternalData의 공식 Lua API를 통한 직접 호출
    local data, errors = mw.ext.externalData.getExternalData {
        url = target_url,
        format = "JSON"
    }
    
    if errors then
        return '<span class="error">데이터를 가져오는 중 오류가 발생했습니다.</span>'
    end
    
    -- ExternalData는 JSON 포맷 지정 시 전체 구조를 __json 변수에 담아 반환합니다.
    if not data or not data.__json then
        return '<span class="error">JSON 데이터를 파싱할 수 없습니다.</span>'
    end

    local json = data.__json
    local html = {}

    if json.days and type(json.days) == "table" then
        for _, day in ipairs(json.days) do
            local day_num = tonumber(string.match(day.date, "%d%d%d%d%-%d%d%-(%d+)"))
            
            table.insert(html, string.format('<h3>%d일</h3>', day_num))
            table.insert(html, '<div style="margin-block: var(--space-md); border-radius: var(--border-radius-medium); box-shadow: var(--box-shadow-border);">')
            
            if day.records and type(day.records) == "table" then
                for _, record in ipairs(day.records) do
                    local item_html = frame:expandTemplate{
                        title = '최초공개 릴레이/항목',
                        args = {
                            ['시간슬롯'] = record.time_slot or "",
                            ['예약자'] = record.column_a or "",
                            ['링크'] = record.column_b or "",
                            ['영상시간'] = record.column_c or "",
                            ['카운트다운'] = record.column_d or "",
                            ['기타표기사항'] = record.column_e or "",
                            ['영상Id'] = record.video_id or "",
                            ['채널Id'] = record.channel_id or "",
                            ['제목'] = record.title or "",
                            ['채널이름'] = record.channel_title or "",
                            ['시작시간'] = record.scheduled_start_time or ""
                        }
                    }
                    table.insert(html, item_html)
                end
            end
            
            table.insert(html, '</div>')
        end
    end

    return table.concat(html)
end

return p