2019-10-09 19:13:07 +03:00
|
|
|
define(["jQuery", "loading", "emby-checkbox", "listViewStyle", "emby-input", "emby-select", "emby-button", "flexStyles"], function ($, loading) {
|
2018-10-23 01:05:09 +03:00
|
|
|
"use strict";
|
2019-10-09 19:13:07 +03:00
|
|
|
|
|
|
|
return function (page, providerId, options) {
|
2018-10-23 01:05:09 +03:00
|
|
|
function reload() {
|
2019-10-09 19:13:07 +03:00
|
|
|
loading.show();
|
|
|
|
ApiClient.getNamedConfiguration("livetv").then(function (config) {
|
|
|
|
var info = config.ListingProviders.filter(function (i) {
|
|
|
|
return i.Id === providerId;
|
2018-10-23 01:05:09 +03:00
|
|
|
})[0] || {};
|
2019-10-09 19:13:07 +03:00
|
|
|
listingsId = info.ListingsId;
|
|
|
|
$("#selectListing", page).val(info.ListingsId || "");
|
|
|
|
page.querySelector(".txtUser").value = info.Username || "";
|
|
|
|
page.querySelector(".txtPass").value = "";
|
|
|
|
page.querySelector(".txtZipCode").value = info.ZipCode || "";
|
|
|
|
|
|
|
|
if (info.Username && info.Password) {
|
|
|
|
page.querySelector(".listingsSection").classList.remove("hide");
|
|
|
|
} else {
|
|
|
|
page.querySelector(".listingsSection").classList.add("hide");
|
|
|
|
}
|
|
|
|
|
|
|
|
page.querySelector(".chkAllTuners").checked = info.EnableAllTuners;
|
|
|
|
|
2019-10-15 20:18:55 +03:00
|
|
|
if (info.EnableAllTuners) {
|
2019-10-09 19:13:07 +03:00
|
|
|
page.querySelector(".selectTunersSection").classList.add("hide");
|
|
|
|
} else {
|
|
|
|
page.querySelector(".selectTunersSection").classList.remove("hide");
|
|
|
|
}
|
|
|
|
|
|
|
|
setCountry(info);
|
|
|
|
refreshTunerDevices(page, info, config.TunerHosts);
|
|
|
|
});
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function setCountry(info) {
|
2019-10-09 19:13:07 +03:00
|
|
|
ApiClient.getJSON(ApiClient.getUrl("LiveTv/ListingProviders/SchedulesDirect/Countries")).then(function (result) {
|
|
|
|
var i;
|
|
|
|
var length;
|
|
|
|
var countryList = [];
|
|
|
|
|
2018-10-23 01:05:09 +03:00
|
|
|
for (var region in result) {
|
|
|
|
var countries = result[region];
|
2019-10-09 19:13:07 +03:00
|
|
|
|
|
|
|
if (countries.length && "ZZZ" !== region) {
|
|
|
|
for (i = 0, length = countries.length; i < length; i++) {
|
|
|
|
countryList.push({
|
|
|
|
name: countries[i].fullName,
|
|
|
|
value: countries[i].shortName
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
2019-10-09 19:13:07 +03:00
|
|
|
|
|
|
|
countryList.sort(function (a, b) {
|
|
|
|
if (a.name > b.name) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (a.name < b.name) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
});
|
|
|
|
$("#selectCountry", page).html(countryList.map(function (c) {
|
|
|
|
return '<option value="' + c.value + '">' + c.name + "</option>";
|
|
|
|
}).join("")).val(info.Country || "");
|
|
|
|
$(page.querySelector(".txtZipCode")).trigger("change");
|
2019-10-15 20:18:55 +03:00
|
|
|
}, function () { // ApiClient.getJSON() error handler
|
2018-10-23 01:05:09 +03:00
|
|
|
Dashboard.alert({
|
|
|
|
message: Globalize.translate("ErrorGettingTvLineups")
|
2019-10-09 19:13:07 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
loading.hide();
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function sha256(str) {
|
2019-10-09 19:13:07 +03:00
|
|
|
if (!self.TextEncoder) {
|
|
|
|
return Promise.resolve("");
|
|
|
|
}
|
|
|
|
|
2018-10-23 01:05:09 +03:00
|
|
|
var buffer = new TextEncoder("utf-8").encode(str);
|
2019-10-09 19:13:07 +03:00
|
|
|
return crypto.subtle.digest("SHA-256", buffer).then(function (hash) {
|
|
|
|
return hex(hash);
|
|
|
|
});
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function hex(buffer) {
|
2019-10-09 19:13:07 +03:00
|
|
|
var hexCodes = [];
|
2019-10-15 20:18:55 +03:00
|
|
|
var view = new DataView(buffer);
|
2019-10-09 19:13:07 +03:00
|
|
|
|
2019-10-15 20:18:55 +03:00
|
|
|
for (i = 0; i < view.byteLength; i += 4) {
|
2019-10-09 19:13:07 +03:00
|
|
|
var value = view.getUint32(i);
|
|
|
|
var stringValue = value.toString(16);
|
|
|
|
var paddedValue = ("00000000" + stringValue).slice(-"00000000".length);
|
|
|
|
hexCodes.push(paddedValue);
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
2019-10-09 19:13:07 +03:00
|
|
|
|
|
|
|
return hexCodes.join("");
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function submitLoginForm() {
|
2019-10-09 19:13:07 +03:00
|
|
|
loading.show();
|
|
|
|
sha256(page.querySelector(".txtPass").value).then(function (passwordHash) {
|
2018-10-23 01:05:09 +03:00
|
|
|
var info = {
|
2019-10-09 19:13:07 +03:00
|
|
|
Type: "SchedulesDirect",
|
|
|
|
Username: page.querySelector(".txtUser").value,
|
|
|
|
EnableAllTuners: true,
|
|
|
|
Password: passwordHash,
|
|
|
|
Pw: page.querySelector(".txtPass").value
|
|
|
|
};
|
|
|
|
var id = providerId;
|
|
|
|
|
|
|
|
if (id) {
|
|
|
|
info.Id = id;
|
|
|
|
}
|
|
|
|
|
|
|
|
ApiClient.ajax({
|
2018-10-23 01:05:09 +03:00
|
|
|
type: "POST",
|
|
|
|
url: ApiClient.getUrl("LiveTv/ListingProviders", {
|
2019-10-09 19:13:07 +03:00
|
|
|
ValidateLogin: true
|
2018-10-23 01:05:09 +03:00
|
|
|
}),
|
|
|
|
data: JSON.stringify(info),
|
|
|
|
contentType: "application/json",
|
|
|
|
dataType: "json"
|
2019-10-09 19:13:07 +03:00
|
|
|
}).then(function (result) {
|
|
|
|
Dashboard.processServerConfigurationUpdateResult();
|
|
|
|
providerId = result.Id;
|
|
|
|
reload();
|
|
|
|
}, function () {
|
2019-10-15 20:18:55 +03:00
|
|
|
Dashboard.alert({ // ApiClient.ajax() error handler
|
2018-10-23 01:05:09 +03:00
|
|
|
message: Globalize.translate("ErrorSavingTvProvider")
|
2019-10-09 19:13:07 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function submitListingsForm() {
|
|
|
|
var selectedListingsId = $("#selectListing", page).val();
|
2019-10-09 19:13:07 +03:00
|
|
|
|
|
|
|
if (!selectedListingsId) {
|
|
|
|
return void Dashboard.alert({
|
|
|
|
message: Globalize.translate("ErrorPleaseSelectLineup")
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-10-23 01:05:09 +03:00
|
|
|
loading.show();
|
|
|
|
var id = providerId;
|
2019-10-09 19:13:07 +03:00
|
|
|
ApiClient.getNamedConfiguration("livetv").then(function (config) {
|
|
|
|
var info = config.ListingProviders.filter(function (i) {
|
|
|
|
return i.Id === id;
|
2018-10-23 01:05:09 +03:00
|
|
|
})[0];
|
2019-10-09 19:13:07 +03:00
|
|
|
info.ZipCode = page.querySelector(".txtZipCode").value;
|
|
|
|
info.Country = $("#selectCountry", page).val();
|
|
|
|
info.ListingsId = selectedListingsId;
|
|
|
|
info.EnableAllTuners = page.querySelector(".chkAllTuners").checked;
|
|
|
|
info.EnabledTuners = info.EnableAllTuners ? [] : $(".chkTuner", page).get().filter(function (i) {
|
|
|
|
return i.checked;
|
|
|
|
}).map(function (i) {
|
|
|
|
return i.getAttribute("data-id");
|
|
|
|
});
|
|
|
|
ApiClient.ajax({
|
2018-10-23 01:05:09 +03:00
|
|
|
type: "POST",
|
|
|
|
url: ApiClient.getUrl("LiveTv/ListingProviders", {
|
2019-10-09 19:13:07 +03:00
|
|
|
ValidateListings: true
|
2018-10-23 01:05:09 +03:00
|
|
|
}),
|
|
|
|
data: JSON.stringify(info),
|
|
|
|
contentType: "application/json"
|
2019-10-09 19:13:07 +03:00
|
|
|
}).then(function (result) {
|
|
|
|
loading.hide();
|
|
|
|
|
2019-10-15 20:18:55 +03:00
|
|
|
if (options.showConfirmation) {
|
2019-10-09 19:13:07 +03:00
|
|
|
Dashboard.processServerConfigurationUpdateResult();
|
|
|
|
}
|
|
|
|
|
|
|
|
Events.trigger(self, "submitted");
|
|
|
|
}, function () {
|
|
|
|
loading.hide();
|
|
|
|
Dashboard.alert({
|
2018-10-23 01:05:09 +03:00
|
|
|
message: Globalize.translate("ErrorAddingListingsToSchedulesDirect")
|
2019-10-09 19:13:07 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function refreshListings(value) {
|
2019-10-09 19:13:07 +03:00
|
|
|
if (!value) {
|
|
|
|
return void $("#selectListing", page).html("");
|
|
|
|
}
|
|
|
|
|
|
|
|
loading.show();
|
|
|
|
ApiClient.ajax({
|
2018-10-23 01:05:09 +03:00
|
|
|
type: "GET",
|
|
|
|
url: ApiClient.getUrl("LiveTv/ListingProviders/Lineups", {
|
|
|
|
Id: providerId,
|
|
|
|
Location: value,
|
|
|
|
Country: $("#selectCountry", page).val()
|
|
|
|
}),
|
|
|
|
dataType: "json"
|
2019-10-09 19:13:07 +03:00
|
|
|
}).then(function (result) {
|
|
|
|
$("#selectListing", page).html(result.map(function (o) {
|
|
|
|
return '<option value="' + o.Id + '">' + o.Name + "</option>";
|
|
|
|
}));
|
|
|
|
|
|
|
|
if (listingsId) {
|
|
|
|
$("#selectListing", page).val(listingsId);
|
|
|
|
}
|
|
|
|
|
|
|
|
loading.hide();
|
|
|
|
}, function (result) {
|
2018-10-23 01:05:09 +03:00
|
|
|
Dashboard.alert({
|
|
|
|
message: Globalize.translate("ErrorGettingTvLineups")
|
2019-10-09 19:13:07 +03:00
|
|
|
});
|
|
|
|
refreshListings("");
|
|
|
|
loading.hide();
|
|
|
|
});
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function getTunerName(providerId) {
|
|
|
|
switch (providerId = providerId.toLowerCase()) {
|
|
|
|
case "m3u":
|
|
|
|
return "M3U Playlist";
|
|
|
|
case "hdhomerun":
|
|
|
|
return "HDHomerun";
|
|
|
|
case "satip":
|
|
|
|
return "DVB";
|
|
|
|
default:
|
2019-10-09 19:13:07 +03:00
|
|
|
return "Unknown";
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function refreshTunerDevices(page, providerInfo, devices) {
|
2019-10-09 19:13:07 +03:00
|
|
|
var html = "";
|
|
|
|
|
|
|
|
for (var i = 0, length = devices.length; i < length; i++) {
|
2018-10-23 01:05:09 +03:00
|
|
|
var device = devices[i];
|
|
|
|
html += '<div class="listItem">';
|
2019-10-09 19:13:07 +03:00
|
|
|
var enabledTuners = providerInfo.EnabledTuners || [];
|
|
|
|
var isChecked = providerInfo.EnableAllTuners || -1 !== enabledTuners.indexOf(device.Id);
|
|
|
|
var checkedAttribute = isChecked ? " checked" : "";
|
|
|
|
html += '<label class="checkboxContainer listItemCheckboxContainer"><input type="checkbox" is="emby-checkbox" data-id="' + device.Id + '" class="chkTuner" ' + checkedAttribute + "/><span></span></label>";
|
|
|
|
html += '<div class="listItemBody two-line">';
|
|
|
|
html += '<div class="listItemBodyText">';
|
|
|
|
html += device.FriendlyName || getTunerName(device.Type);
|
|
|
|
html += "</div>";
|
|
|
|
html += '<div class="listItemBodyText secondary">';
|
|
|
|
html += device.Url;
|
|
|
|
html += "</div>";
|
|
|
|
html += "</div>";
|
|
|
|
html += "</div>";
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
2019-10-09 19:13:07 +03:00
|
|
|
|
|
|
|
page.querySelector(".tunerList").innerHTML = html;
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
2019-10-09 19:13:07 +03:00
|
|
|
|
|
|
|
var listingsId;
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
self.submit = function () {
|
|
|
|
page.querySelector(".btnSubmitListingsContainer").click();
|
|
|
|
};
|
|
|
|
|
|
|
|
self.init = function () {
|
|
|
|
options = options || {};
|
|
|
|
|
2019-10-15 20:18:55 +03:00
|
|
|
if (options.showCancelButton) {
|
2019-10-09 19:13:07 +03:00
|
|
|
page.querySelector(".btnCancel").classList.remove("hide");
|
|
|
|
} else {
|
|
|
|
page.querySelector(".btnCancel").classList.add("hide");
|
|
|
|
}
|
|
|
|
|
2019-10-15 20:18:55 +03:00
|
|
|
if (options.showSubmitButton) {
|
2019-10-09 19:13:07 +03:00
|
|
|
page.querySelector(".btnSubmitListings").classList.remove("hide");
|
|
|
|
} else {
|
|
|
|
page.querySelector(".btnSubmitListings").classList.add("hide");
|
|
|
|
}
|
|
|
|
|
|
|
|
$(".formLogin", page).on("submit", function () {
|
|
|
|
submitLoginForm();
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
$(".formListings", page).on("submit", function () {
|
|
|
|
submitListingsForm();
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
$(".txtZipCode", page).on("change", function () {
|
|
|
|
refreshListings(this.value);
|
|
|
|
});
|
|
|
|
page.querySelector(".chkAllTuners").addEventListener("change", function (e) {
|
|
|
|
if (e.target.checked) {
|
|
|
|
page.querySelector(".selectTunersSection").classList.add("hide");
|
|
|
|
} else {
|
|
|
|
page.querySelector(".selectTunersSection").classList.remove("hide");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
$(".createAccountHelp", page).html(Globalize.translate("MessageCreateAccountAt", '<a is="emby-linkbutton" class="button-link" href="http://www.schedulesdirect.org" target="_blank">http://www.schedulesdirect.org</a>'));
|
|
|
|
reload();
|
|
|
|
};
|
|
|
|
};
|
|
|
|
});
|