연령 제한("Sign in to confirm your age") 영상이 플레이리스트 임포트에서
실패하던 문제 해결. 관리자 대시보드에서 Netscape cookies.txt 를 등록하면
단일/플레이리스트 probe 와 실제 다운로드에 모두 --cookies 로 적용된다.
쿠키는 data/cookies.txt 에 0600 으로 저장(git 제외). 연령/로그인 실패 시
yt-dlp 원문 대신 쿠키 등록을 안내하는 메시지를 표시.
Co-Authored-By: Claude Opus 4 <noreply@anthropic.com>
202 lines
7.7 KiB
JavaScript
202 lines
7.7 KiB
JavaScript
(function () {
|
|
var ctxMenu = document.getElementById('ctxMenu')
|
|
var targetId = null
|
|
var targetName = null
|
|
|
|
function showCtx(x, y) {
|
|
ctxMenu.style.left = x + 'px'
|
|
ctxMenu.style.top = y + 'px'
|
|
ctxMenu.hidden = false
|
|
}
|
|
function hideCtx() { ctxMenu.hidden = true; targetId = null; targetName = null }
|
|
|
|
document.querySelectorAll('.adminFolder').forEach(function (card) {
|
|
card.addEventListener('contextmenu', function (e) {
|
|
e.preventDefault()
|
|
targetId = card.getAttribute('data-folder-id')
|
|
targetName = card.getAttribute('data-name')
|
|
showCtx(e.clientX, e.clientY)
|
|
})
|
|
})
|
|
|
|
document.addEventListener('click', function (e) {
|
|
if (!ctxMenu.contains(e.target)) hideCtx()
|
|
})
|
|
|
|
ctxMenu.addEventListener('click', function (e) {
|
|
var btn = e.target.closest('button')
|
|
if (!btn || !targetId) return
|
|
var action = btn.getAttribute('data-action')
|
|
if (action === 'rename') {
|
|
var newName = window.prompt('새 폴더 이름', targetName)
|
|
if (newName && newName !== targetName) {
|
|
fetch('/op/folders/' + encodeURIComponent(targetId) + '/rename', {
|
|
method: 'POST',
|
|
headers: { 'content-type': 'application/json' },
|
|
body: JSON.stringify({ newName: newName })
|
|
}).then(function (r) { return r.json() }).then(function (j) {
|
|
if (j.ok) location.reload()
|
|
else alert(j.message || '이름 변경 실패')
|
|
})
|
|
}
|
|
} else if (action === 'delete') {
|
|
if (window.confirm('"' + targetName + '" 폴더를 정말 삭제할까요? 안의 영상이 모두 사라집니다.')) {
|
|
fetch('/op/folders/' + encodeURIComponent(targetId) + '/delete', {
|
|
method: 'POST'
|
|
}).then(function (r) { return r.json() }).then(function (j) {
|
|
if (j.ok) location.reload()
|
|
else alert(j.message || '삭제 실패')
|
|
})
|
|
}
|
|
}
|
|
hideCtx()
|
|
})
|
|
|
|
// 폴더 추가 모달
|
|
var addBtn = document.getElementById('addFolderBtn')
|
|
var modal = document.getElementById('addFolderModal')
|
|
var input = document.getElementById('addFolderInput')
|
|
var cancelBtn = document.getElementById('addFolderCancel')
|
|
var confirmBtn = document.getElementById('addFolderConfirm')
|
|
|
|
function openModal() { modal.hidden = false; input.value = ''; setTimeout(function () { input.focus() }, 0) }
|
|
function closeModal() { modal.hidden = true }
|
|
if (addBtn) {
|
|
addBtn.addEventListener('click', openModal)
|
|
cancelBtn.addEventListener('click', closeModal)
|
|
modal.addEventListener('click', function (e) { if (e.target === modal) closeModal() })
|
|
input.addEventListener('keydown', function (e) { if (e.key === 'Enter') confirmBtn.click() })
|
|
confirmBtn.addEventListener('click', function () {
|
|
var name = input.value.trim()
|
|
if (!name) return
|
|
fetch('/op/folders', {
|
|
method: 'POST',
|
|
headers: { 'content-type': 'application/json' },
|
|
body: JSON.stringify({ name: name })
|
|
}).then(function (r) { return r.json() }).then(function (j) {
|
|
if (j.ok) location.reload()
|
|
else alert(j.message || '폴더 생성 실패')
|
|
})
|
|
})
|
|
}
|
|
|
|
// 도구 관리(ffmpeg / yt-dlp)
|
|
function renderTool(name, tool) {
|
|
var card = document.querySelector('.toolCard[data-tool="' + name + '"]')
|
|
if (!card) return
|
|
var versionEl = card.querySelector('[data-field="version"]')
|
|
var pathEl = card.querySelector('[data-field="path"]')
|
|
if (!tool || !tool.available) {
|
|
versionEl.textContent = '설치되지 않음'
|
|
pathEl.textContent = ''
|
|
return
|
|
}
|
|
versionEl.textContent = (tool.version || '버전 미상') + (tool.managed ? ' · 직접 설치본' : '')
|
|
pathEl.textContent = tool.path || ''
|
|
}
|
|
|
|
function loadTools() {
|
|
fetch('/op/tools').then(function (r) { return r.json() }).then(function (j) {
|
|
if (!j.ok) return
|
|
renderTool('yt-dlp', j.tools.ytDlp)
|
|
renderTool('ffmpeg', j.tools.ffmpeg)
|
|
}).catch(function () {})
|
|
}
|
|
|
|
document.querySelectorAll('[data-action="update-tool"]').forEach(function (btn) {
|
|
btn.addEventListener('click', function () {
|
|
var name = btn.getAttribute('data-name')
|
|
var card = btn.closest('.toolCard')
|
|
var statusEl = card.querySelector('[data-field="status"]')
|
|
btn.disabled = true
|
|
statusEl.textContent = '재설치 중… (수십 초 걸릴 수 있습니다)'
|
|
fetch('/op/tools/' + encodeURIComponent(name) + '/update', { method: 'POST' })
|
|
.then(function (r) { return r.json() })
|
|
.then(function (j) {
|
|
if (j.ok) {
|
|
statusEl.textContent = '완료'
|
|
renderTool(name, j.tool)
|
|
} else {
|
|
statusEl.textContent = '실패: ' + (j.message || '알 수 없는 오류')
|
|
}
|
|
})
|
|
.catch(function (err) {
|
|
statusEl.textContent = '실패: ' + (err && err.message ? err.message : '요청 오류')
|
|
})
|
|
.then(function () { btn.disabled = false })
|
|
})
|
|
})
|
|
|
|
if (document.querySelector('.toolsSection')) loadTools()
|
|
|
|
// YouTube 쿠키 관리
|
|
var cookieSection = document.getElementById('cookiesSection')
|
|
if (cookieSection) {
|
|
var cookieStatusEl = document.getElementById('cookieStatus')
|
|
var cookieFileEl = document.getElementById('cookieFile')
|
|
var cookieUploadBtn = document.getElementById('cookieUploadBtn')
|
|
var cookieDeleteBtn = document.getElementById('cookieDeleteBtn')
|
|
var cookieMsgEl = document.getElementById('cookieMsg')
|
|
|
|
function renderCookies(c) {
|
|
if (c && c.present) {
|
|
var kb = Math.max(1, Math.round(c.bytes / 1024))
|
|
var when = c.updatedAt ? new Date(c.updatedAt).toLocaleString() : ''
|
|
cookieStatusEl.textContent = '등록됨 (' + kb + ' KB' + (when ? ' · ' + when : '') + ')'
|
|
cookieDeleteBtn.hidden = false
|
|
} else {
|
|
cookieStatusEl.textContent = '등록되지 않음'
|
|
cookieDeleteBtn.hidden = true
|
|
}
|
|
}
|
|
|
|
function loadCookies() {
|
|
fetch('/op/cookies').then(function (r) { return r.json() }).then(function (j) {
|
|
if (j.ok) renderCookies(j.cookies)
|
|
}).catch(function () {})
|
|
}
|
|
|
|
cookieUploadBtn.addEventListener('click', function () {
|
|
var file = cookieFileEl.files && cookieFileEl.files[0]
|
|
if (!file) { cookieMsgEl.textContent = '파일을 선택해 주세요.'; return }
|
|
var fd = new FormData()
|
|
fd.append('file', file)
|
|
cookieUploadBtn.disabled = true
|
|
cookieMsgEl.textContent = '등록 중…'
|
|
fetch('/op/cookies', { method: 'POST', body: fd })
|
|
.then(function (r) { return r.json() })
|
|
.then(function (j) {
|
|
if (j.ok) {
|
|
cookieMsgEl.textContent = '등록 완료'
|
|
cookieFileEl.value = ''
|
|
renderCookies(j.cookies)
|
|
} else {
|
|
cookieMsgEl.textContent = '실패: ' + (j.message || '알 수 없는 오류')
|
|
}
|
|
})
|
|
.catch(function (err) {
|
|
cookieMsgEl.textContent = '실패: ' + (err && err.message ? err.message : '요청 오류')
|
|
})
|
|
.then(function () { cookieUploadBtn.disabled = false })
|
|
})
|
|
|
|
cookieDeleteBtn.addEventListener('click', function () {
|
|
if (!window.confirm('등록된 YouTube 쿠키를 삭제할까요?')) return
|
|
cookieDeleteBtn.disabled = true
|
|
cookieMsgEl.textContent = '삭제 중…'
|
|
fetch('/op/cookies/delete', { method: 'POST' })
|
|
.then(function (r) { return r.json() })
|
|
.then(function (j) {
|
|
if (j.ok) { cookieMsgEl.textContent = '삭제됨'; renderCookies(j.cookies) }
|
|
else cookieMsgEl.textContent = '실패: ' + (j.message || '알 수 없는 오류')
|
|
})
|
|
.catch(function (err) {
|
|
cookieMsgEl.textContent = '실패: ' + (err && err.message ? err.message : '요청 오류')
|
|
})
|
|
.then(function () { cookieDeleteBtn.disabled = false })
|
|
})
|
|
|
|
loadCookies()
|
|
}
|
|
})()
|