let current_data = "";
let current_airing_data = "";
let code = "";
let div_visible = false;
let total_page = "";
const params = new Proxy(new URLSearchParams(window.location.search), {
get: (searchParams, prop) => searchParams.get(prop),
});
// console.log('current_airing_data', current_airing_data);
// const get_airing_list = () => {
// $.ajax({
// url: "/" + package_name + "/ajax/airing_list",
// type: "GET",
// cache: false,
// dataType: "json",
// success: (ret) => {
// if (ret.ret == "success" && ret.episode != null) {
// current_airing_data = ret;
// total_page = ret.total_page;
// // console.log(ret)
// if (current_airing_data !== "") {
// make_airing_list(ret);
// div_visible = true;
// // console.log(div_visible)
// }
// } else {
// $.notify("분석 실패
" + ret.log, {
// type: "warning",
// });
// }
// },
// });
//
// if (div_visible) {
// // {#$('#airing_list').toggle()#}
// }
// };
// console.log(div_visible)
$(document).on("click", "button.code-button", function (e) {
e.preventDefault();
// console.log('click')
// console.log('code to click:' + $(this).data("code"))
document.getElementById("code").value = $(this).data("code");
$("#code").val($(this).data("code"));
$("#airing_list").toggle();
code = document.getElementById("code").value;
document.getElementById("analysis_btn").click();
});
$(".code-button").tooltip();
$("body").on("click", "#analysis_btn", function (e) {
e.preventDefault();
if (document.getElementById("code").value !== "") {
code = document.getElementById("code").value;
}
// console.log('#analysis_btn >>> code::', code)
if (code === "") {
console.log("code 값을 입력해주세요.");
$.notify("code 값을 입력해주세요.
");
return;
}
if (current_data === "" || current_data.data.code !== code) {
$.ajax({
url: "/" + package_name + "/ajax/analysis",
type: "POST",
cache: false,
data: {code: code},
dataType: "json",
success: function (ret) {
if (ret.ret == "success" && ret.data != null) {
console.log(ret)
// console.log('분석: %s', ret)
make_program(ret.data);
run_time = Math.floor(new Date().getTime() / 1000)
current_data = ret
} else {
$.notify("분석 실패
" + ret.log, {
type: "warning",
});
}
},
});
} else {
console.log('과도한 사이트 조회 금지')
}
});
$("body").on("click", "#go_inflearn_btn", function (e) {
e.preventDefault();
window.open(inflearn_url, "_blank");
});
function make_airing_list(data) {
let str = "";
let tmp = "";
tmp =
'
';
tmp += "
";
str += m_hr_black();
// {#str += m_row_start(0);#}
// {##}
// {#str += m_row_end();#}
// {#str += m_hr_black();#}
str +=
'';
for (i in data.episode) {
// {#str += m_row_start();#}
// {#tmp = '
' + data.episode[i].title+ '';#}
//
// {#tmp += '
'#}
// {#tmp += '' + data.episode[i].code + '
';#}
// {#str += m_col(12, tmp)#}
tmp =
'
";
// {#if (i === 10) {#}
// {# tmp += '
'#}
str += tmp;
}
str += "
";
str += m_hr_black();
document.getElementById("airing_list").innerHTML = str;
}
function make_program(data) {
current_data = data;
// console.log('current_data:: ', data)
str = "";
tmp = '';
tmp += m_button("check_download_btn", "선택 다운로드 추가", []);
tmp += m_button("all_check_on_btn", "전체 선택", []);
tmp += m_button("all_check_off_btn", "전체 해제", []);
tmp +=
' ';
tmp += "
";
tmp += '';
tmp += m_button("apply_new_title_btn", "저장폴더명 변경", []);
// tmp +=
// ' ';
// tmp += m_button("apply_new_season_btn", "시즌 변경 (숫자만 가능)", []);
// tmp += m_button("search_tvdb_btn", "TVDB", []);
tmp += m_button("add_whitelist", "스케쥴링 추가", []);
tmp += "
";
tmp = m_button_group(tmp);
str += tmp;
// program
str += m_hr_black();
str += m_row_start(0);
tmp = "";
if (data.poster_url != null)
tmp = '
';
str += m_col(3, tmp);
tmp = "";
tmp += m_row_start(0);
tmp += m_col(3, "제목", "right");
tmp += m_col(9, data.title);
tmp += m_row_end();
tmp += m_row_start(0);
tmp += m_col(3, "시즌", "right");
tmp += m_col(9, data.season);
tmp += m_row_end();
for (i in data.detail) {
tmp += m_row_start(0);
key = Object.keys(data.detail[i])[0];
value = data.detail[i][key];
tmp += m_col(3, key, "right");
tmp += m_col(9, value);
tmp += m_row_end();
}
str += m_col(9, tmp);
str += m_row_end();
str += m_hr_black();
for (i in data.episode) {
str += m_row_start();
// tmp = '
'
// str += m_col(3, tmp)
tmp = "" + data.episode[i].title + "";
tmp += "
";
tmp += data.episode[i].filename + "
";
tmp += '';
tmp +=
' ';
// tmp += m_button('add_queue_btn', '다운로드 추가', [{'key': 'code', 'value': data.episode[i].code}])
tmp += m_button("add_download", "다운로드 추가", [
{key: "idx", value: i},
]);
tmp += "
";
str += m_col(12, tmp);
str += m_row_end();
if (i != data.length - 1) str += m_hr(0);
}
document.getElementById("episode_list").innerHTML = str;
$('input[id^="checkbox_"]').bootstrapToggle();
}
$("body").on("click", "#all_check_on_btn", function (e) {
e.preventDefault();
$('input[id^="checkbox_"]').bootstrapToggle("on");
});
$("body").on("click", "#all_check_off_btn", function (e) {
e.preventDefault();
$('input[id^="checkbox_"]').bootstrapToggle("off");
});
$("body").on("click", "#search_tvdb_btn", function (e) {
e.preventDefault();
const new_title = document.getElementById("new_title").value;
let url = "https://www.thetvdb.com/search?query=" + new_title;
window.open(url, "_blank");
});
$("body").on("click", "#add_whitelist", function (e) {
e.preventDefault();
$.ajax({
url: "/" + package_name + "/ajax/add_whitelist",
type: "POST",
cache: false,
dataType: "json",
success: function (ret) {
if (ret.ret) {
$.notify("추가하였습니다.
", {
type: "success",
});
make_program(ret);
} else {
$.notify("추가 실패
" + ret.log, {
type: "warning",
});
}
},
});
});
$("body").on("click", "#apply_new_title_btn", function (e) {
e.preventDefault();
const new_title = document.getElementById("new_title").value;
$.ajax({
url: "/" + package_name + "/ajax/apply_new_title",
type: "POST",
cache: false,
data: {new_title: new_title},
dataType: "json",
success: function (ret) {
if (ret.ret) {
$.notify("적용하였습니다.
", {
type: "success",
});
// console.log(ret)
make_program(ret);
} else {
$.notify("적용 실패
" + ret.log, {
type: "warning",
});
}
},
});
});
$("body").on("click", "#apply_new_season_btn", function (e) {
e.preventDefault();
const new_season = document.getElementById("new_season").value;
if ($.isNumeric(new_season) == false) {
$.notify("시즌은 숫자여야 합니다.
" + ret.log, {
type: "warning",
});
} else {
$.ajax({
url: "/" + package_name + "/ajax/apply_new_season",
type: "POST",
cache: false,
data: {new_season: new_season},
dataType: "json",
success: function (ret) {
if (ret.ret) {
$.notify("적용하였습니다.
", {
type: "success",
});
make_program(ret);
} else {
$.notify("적용 실패
" + ret.log, {
type: "warning",
});
}
},
});
}
});
// 하나씩 다운로드 추가
$("body").on("click", "#add_download", function (e) {
e.preventDefault();
// code = $(this).data('code');
code = current_data.data.episode[$(this).data("idx")].code;
// console.log('code:: ', code)
let data = current_data.data.episode[$(this).data("idx")];
// console.log('data:: ', data)
$.ajax({
url: "/" + package_name + "/ajax/add_download",
type: "POST",
cache: false,
data: {code: code, data: JSON.stringify(data)},
dataType: "json",
success: function (data) {
// console.log('#add_queue_btn::data >>', data)
if (data.ret === "enqueue_db_append") {
$.notify("다운로드 작업을 추가 하였습니다.", {
type: "success",
});
} else if (data.ret === "enqueue_db_exist") {
$.notify("DB에 존재하는 에피소드입니다.", {
type: "warning",
});
} else if (data.ret === "db_completed") {
$.notify("DB에 완료 기록이 있습니다.", {
type: "warning",
});
} else if (data.ret === "fail") {
$.notify("이미 큐에 있습니다. 삭제 후 추가하세요.", {
type: "warning",
});
} else if (data.ret === "no_data") {
$.notify("잘못된 코드입니다.", {
type: "warning",
});
} else if (data.ret === "Debugging") {
$.notify("Debugging", {
type: "warning",
});
} else {
$.notify("추가 실패
" + ret.log, {
type: "warning",
});
}
},
});
});
$("body").on("click", "#check_download_btn", function (e) {
e.preventDefault();
const checked_items = $('input[id^="checkbox_"]');
console.log(checked_items)
let str = "";
for (let i in checked_items) {
if (checked_items[i].checked) {
code = checked_items[i].id.split("_")[1];
str += code + ",";
}
}
lecture_id = current_data.data.episode[0].item_id
console.log(`checked_items: ${checked_items}`)
console.log(str)
if (str === "") {
$.notify("선택하세요.", {
type: "warning",
});
return;
}
// return;
$.ajax({
url: "/" + package_name + "/ajax/add_queue_checked_list",
type: "POST",
cache: false,
data: {code: str, lecture_id: lecture_id},
dataType: "json",
success: function (data) {
if (data.ret == "success") {
$.notify("" + data.log + "개를 추가하였습니다.", {
type: "success",
});
} else {
$.notify("" + data.log + "", {
type: "warning",
});
}
},
});
});
$("#go_modal_airing").on("shown.bs.modal", function () {
// {#get_airing_list()#}
$("#exModal").trigger("focus");
});
$("#go_modal_airing").click(function (e) {
e.preventDefault();
// console.log('open modal')
$("#exModal").bootstrapToggle();
if (current_airing_data === "") {
get_airing_list();
}
$("#inner_airing").toggle();
$("#airing_list").toggle();
});
$("#go_modal_airing").attr("class", "btn btn-primary");