{"id":472,"date":"2025-10-22T17:15:24","date_gmt":"2025-10-22T17:15:24","guid":{"rendered":"https:\/\/divinewisdomministries.com\/?page_id=472"},"modified":"2025-10-22T17:17:48","modified_gmt":"2025-10-22T17:17:48","slug":"dj","status":"publish","type":"page","link":"https:\/\/divinewisdomministries.com\/ta\/dj\/","title":{"rendered":"dj"},"content":{"rendered":"<div data-elementor-type=\"wp-page\" data-elementor-id=\"472\" class=\"elementor elementor-472\">\n\t\t\t\t\t\t\t<div class=\"elementor-element elementor-element-9ca64a8 e-flex e-con-boxed e-con e-parent\" data-id=\"9ca64a8\" data-element_type=\"container\" data-settings=\"{&quot;content_width&quot;:&quot;boxed&quot;}\" data-core-v316-plus=\"true\">\n\t\t\t\t\t<div class=\"e-con-inner\">\n\t\t\t\t<div class=\"elementor-element elementor-element-467f169 elementor-widget elementor-widget-shortcode\" data-id=\"467f169\" data-element_type=\"widget\" data-widget_type=\"shortcode.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<div class=\"elementor-shortcode\">    <div id=\"ttv-dj-frontend\" style=\"max-width:760px; margin:0 auto; font-family:system-ui, -apple-system, 'Segoe UI', Roboto, Arial;\">\r\n        <h2>DJ Control Panel<\/h2>\r\n        <p>Enter the DJ password to unlock controls. (Ask an admin to set it via Settings \u2192 ThiruThoothar DJ.)<\/p>\r\n\r\n        <div id=\"ttv-dj-lock\">\r\n            <label for=\"ttv_front_pw\" style=\"display:block; margin-bottom:6px;\">DJ Password<\/label>\r\n            <input id=\"ttv_front_pw\" type=\"password\" style=\"width:100%; max-width:420px; padding:8px; margin-bottom:8px;\" autocomplete=\"off\" \/>\r\n            <div>\r\n                <button id=\"ttv_unlock_btn\" class=\"button\">Unlock Panel<\/button>\r\n                <span id=\"ttv_unlock_status\" style=\"margin-left:12px;\"><\/span>\r\n            <\/div>\r\n        <\/div>\r\n\r\n        <div id=\"ttv-dj-controls\" style=\"display:none; margin-top:18px;\">\r\n            <div style=\"margin-bottom:8px;\">\r\n                <button id=\"ttv_go_live\" class=\"button button-primary\">Go Live (auto-detect)<\/button>\r\n                <button id=\"ttv_stop_live\" class=\"button\">Stop Live<\/button>\r\n                <button id=\"ttv_lock_btn\" class=\"button\" style=\"margin-left:8px;\">Lock Panel<\/button>\r\n                <span id=\"ttv_action_status\" style=\"margin-left:12px;\"><\/span>\r\n            <\/div>\r\n\r\n            <div style=\"margin-top:12px;\">\r\n                <label style=\"display:block; margin-bottom:6px;\">DJ Name<\/label>\r\n                <input id=\"ttv_dj_name\" type=\"text\" placeholder=\"Presented By Nova\" style=\"width:100%; max-width:420px; padding:8px; margin-bottom:8px;\" \/>\r\n                <label style=\"display:block; margin-bottom:6px;\">Program Title<\/label>\r\n                <input id=\"ttv_program_title\" type=\"text\" placeholder=\"The Gods Plan\" style=\"width:100%; max-width:640px; padding:8px;\" \/>\r\n            <\/div>\r\n\r\n            <div style=\"margin-top:12px;\">\r\n                <label style=\"display:block; margin-bottom:6px;\">Fallback: Manually provide a YouTube URL (only used if auto-detect fails)<\/label>\r\n                <input id=\"ttv_embed_url\" type=\"url\" placeholder=\"https:\/\/www.youtube.com\/embed\/VIDEO_ID or https:\/\/youtu.be\/ID\" style=\"width:100%; max-width:640px; padding:8px;\" \/>\r\n            <\/div>\r\n\r\n            <div style=\"margin-top:12px; font-size:13px; color:#555;\">\r\n                <strong>Note:<\/strong> Auto-detect checks the configured channel for an active live stream. If none found, provide an embed URL as fallback.\r\n            <\/div>\r\n        <\/div>\r\n    <\/div>\r\n\r\n    <script>\r\n    (function(){\r\n        const adminAjax = 'https:\/\/divinewisdomministries.com\/wp-admin\/admin-ajax.php';\r\n\r\n        const unlockBtn = document.getElementById('ttv_unlock_btn');\r\n        const pwInput = document.getElementById('ttv_front_pw');\r\n        const unlockStatus = document.getElementById('ttv_unlock_status');\r\n        const controls = document.getElementById('ttv-dj-controls');\r\n        const lockBtn = document.getElementById('ttv_lock_btn');\r\n        const goBtn = document.getElementById('ttv_go_live');\r\n        const stopBtn = document.getElementById('ttv_stop_live');\r\n        const embedInput = document.getElementById('ttv_embed_url');\r\n        const actionStatus = document.getElementById('ttv_action_status');\r\n\r\n        \/\/ restore token from sessionStorage if present\r\n        let token = sessionStorage.getItem('ttv_dj_token') || null;\r\n        if ( token ) {\r\n            document.getElementById('ttv-dj-lock').style.display = 'none';\r\n            controls.style.display = 'block';\r\n            unlockStatus.textContent = 'Panel unlocked';\r\n            unlockStatus.style.color = 'green';\r\n        }\r\n\r\n        function setUnlockMessage(msg, ok) {\r\n            unlockStatus.textContent = msg;\r\n            unlockStatus.style.color = ok ? 'green' : 'red';\r\n        }\r\n        function setActionMessage(msg, ok) {\r\n            actionStatus.textContent = msg;\r\n            actionStatus.style.color = ok ? 'green' : 'red';\r\n        }\r\n\r\n        unlockBtn.addEventListener('click', function(e){\r\n            e.preventDefault();\r\n            const pw = pwInput.value.trim();\r\n            if (!pw) { setUnlockMessage('Enter password', false); return; }\r\n            setUnlockMessage('Unlocking...', true);\r\n\r\n            const data = new FormData();\r\n            data.append('action', 'ttv_front_dj_unlock');\r\n            data.append('password', pw);\r\n\r\n            fetch(adminAjax, {\r\n                method: 'POST',\r\n                credentials: 'same-origin',\r\n                body: data\r\n            }).then(r => r.json()).then(json => {\r\n                if ( json && json.success && json.data && json.data.token ) {\r\n                    token = json.data.token;\r\n                    sessionStorage.setItem('ttv_dj_token', token);\r\n                    setUnlockMessage('Panel unlocked \u2014 valid for ' + (json.data.expires_in || '7200') + ' seconds', true);\r\n                    pwInput.value = '';\r\n                    document.getElementById('ttv-dj-lock').style.display = 'none';\r\n                    controls.style.display = 'block';\r\n                } else {\r\n                    setUnlockMessage(json.data || json.message || 'Invalid password', false);\r\n                }\r\n            }).catch(err => {\r\n                console.error(err);\r\n                setUnlockMessage('Request failed', false);\r\n            });\r\n        });\r\n\r\n        lockBtn.addEventListener('click', function(e){\r\n            e.preventDefault();\r\n            token = null;\r\n            sessionStorage.removeItem('ttv_dj_token');\r\n            controls.style.display = 'none';\r\n            document.getElementById('ttv-dj-lock').style.display = 'block';\r\n            setUnlockMessage('Panel locked', true);\r\n        });\r\n\r\n        \/\/ embed helpers\r\n        function toYouTubeEmbedUrl(input) {\r\n            if (!input) return '';\r\n            const v = input.trim();\r\n            if ( v.includes('youtube.com\/embed\/') ) return v.replace(\/^http:\/,'https:');\r\n            const shortMatch = v.match(\/youtu\\.be\\\/([A-Za-z0-9_-]{6,})\/);\r\n            if ( shortMatch ) return 'https:\/\/www.youtube.com\/embed\/' + shortMatch[1];\r\n            const watchMatch = v.match(\/[?&]v=([A-Za-z0-9_-]{6,})\/);\r\n            if ( watchMatch ) return 'https:\/\/www.youtube.com\/embed\/' + watchMatch[1];\r\n            const idMatch = v.match(\/^([A-Za-z0-9_-]{6,})$\/);\r\n            if ( idMatch ) return 'https:\/\/www.youtube.com\/embed\/' + idMatch[1];\r\n            return '';\r\n        }\r\n\r\n        function callAction(action, embed, djName, programTitle) {\r\n            if (!token) { setActionMessage('Panel not unlocked', false); return; }\r\n            setActionMessage('Working...', true);\r\n            const data = new FormData();\r\n            data.append('action', 'ttv_front_dj_action');\r\n            data.append('token', token);\r\n            data.append('do', action);\r\n            if ( embed ) data.append('embed_url', embed);\r\n            if ( djName ) data.append('dj_name', djName);\r\n            if ( programTitle ) data.append('program_title', programTitle);\r\n\r\n            fetch(adminAjax, {\r\n                method: 'POST',\r\n                credentials: 'same-origin',\r\n                body: data\r\n            }).then(r => r.json()).then(json => {\r\n                if ( json && json.success ) {\r\n                    setActionMessage(json.data.msg || 'Success', true);\r\n\r\n                    if ( action === 'go_live' ) {\r\n                        \/\/ save last program locally (used by player after live ends)\r\n                        const last = { dj_name: djName || '', program_title: programTitle || '', updated_at: Date.now() };\r\n                        try { localStorage.setItem('ttv_last_program', JSON.stringify(last)); } catch(e){}\r\n                    }\r\n                } else {\r\n                    setActionMessage(json.data || json.message || 'Action failed', false);\r\n                }\r\n            }).catch(err => {\r\n                console.error(err);\r\n                setActionMessage('Request failed', false);\r\n            });\r\n        }\r\n\r\n        goBtn.addEventListener('click', function(e){\r\n            e.preventDefault();\r\n            if (!token) { setActionMessage('Panel not unlocked', false); return; }\r\n            setActionMessage('Checking YouTube channel for live stream...', true);\r\n            const fallbackRaw = embedInput.value.trim();\r\n            const fallback = toYouTubeEmbedUrl(fallbackRaw);\r\n            const djName = document.getElementById('ttv_dj_name').value.trim();\r\n            const programTitle = document.getElementById('ttv_program_title').value.trim();\r\n            callAction('go_live', fallback ? fallback : '', djName, programTitle);\r\n        });\r\n\r\n        stopBtn.addEventListener('click', function(e){\r\n            e.preventDefault();\r\n            callAction('stop_live', '', '', '');\r\n        });\r\n    })();\r\n    <\/script>\r\n    <\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t\t\t<\/div>","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-472","page","type-page","status-publish","hentry","entry"],"_links":{"self":[{"href":"https:\/\/divinewisdomministries.com\/ta\/wp-json\/wp\/v2\/pages\/472","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/divinewisdomministries.com\/ta\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/divinewisdomministries.com\/ta\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/divinewisdomministries.com\/ta\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/divinewisdomministries.com\/ta\/wp-json\/wp\/v2\/comments?post=472"}],"version-history":[{"count":4,"href":"https:\/\/divinewisdomministries.com\/ta\/wp-json\/wp\/v2\/pages\/472\/revisions"}],"predecessor-version":[{"id":478,"href":"https:\/\/divinewisdomministries.com\/ta\/wp-json\/wp\/v2\/pages\/472\/revisions\/478"}],"wp:attachment":[{"href":"https:\/\/divinewisdomministries.com\/ta\/wp-json\/wp\/v2\/media?parent=472"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}