diff --git a/plugin.json b/plugin.json index 166782f..2149c9a 100644 --- a/plugin.json +++ b/plugin.json @@ -4,7 +4,7 @@ "id": "UASerials", "file": "uaserials.js", "showtimeVersion": "5", - "version": "1.2.1", + "version": "1.3.2", "author": "eclipse7723", "title": "UASerials", "icon": "logo.svg", diff --git a/src/movie-parser.js b/src/movie-parser.js index 8019321..817e786 100644 --- a/src/movie-parser.js +++ b/src/movie-parser.js @@ -11,9 +11,41 @@ function getColoredFormat(text, color) { function formatInfo(text) { return getColoredFormat(text, COLOR_GRAY); } +function formatBold(text) { + return "" + text + ""; +} // --------------------------------------------------------------- +function parseCollections(page, href) { + /* Парсит страницы с коллекциями фильмов и сериалов */ + var doc = fetchDoc(href); + + var items = doc.getElementById("dle-content").children; + items.forEach(function(item) { + var data = item.children[0]; // tag 'a' + var children = data.children; // tags 'img', div 'uas-col-title', div 'uas-col-count' + + const title = children[1].textContent; + const itemHref = data.attributes.getNamedItem('href').value; + const itemImg = children[0].attributes.getNamedItem('data-src').value; + const itemCount = children[2].textContent; + + var desc = ""; + desc += formatInfo("Повна назва: " + formatBold(title)) + desc += "\n" + formatInfo("Кількість в цій добірці: " + formatBold(itemCount)); + var desc = new RichText(desc); + + page.appendItem(PLUGIN.id + ":collection:" + itemHref + ":" + title.replace(":", ""), 'video', { + title: title, + icon: itemImg, + description: desc, + }); + page.entries += 1 + }); +} + + function parseMovies(page, href) { /* Парсит краткую инфу про фильмы по указаному адресу (название, иконка) */ var doc = fetchDoc(href); @@ -28,16 +60,16 @@ function parseMovies(page, href) { var desc = ""; if (titleEn) { - desc += formatInfo("Оригінальна назва: " + titleEn + ""); + desc += formatInfo("Оригінальна назва: " + formatBold(titleEn)); } const label1 = children[0].getElementByClassName("short-label-level-1")[0] if (label1) { - desc += "\n" + formatInfo(label1.children[0].textContent); + desc += "\n" + formatInfo("Тип: " + formatBold(label1.children[0].textContent)); } const label2 = children[0].getElementByClassName("short-label-level-2")[0] if (label2) { - desc += "\n" + formatInfo(label2.children[0].textContent); + desc += "\n" + formatInfo("Кількість: " + formatBold(label2.children[0].textContent)); } var desc = new RichText(desc); @@ -183,7 +215,16 @@ function createPageLoader(page, searchUrlBuilder, startPageNumber) { var url = searchUrlBuilder(nextPageNumber); const expectedEntries = page.entries + itemsPerPage; - parseMovies(page, url); + + try { + parseMovies(page, url); + } catch (e) { + console.error("loading page " + nextPageNumber + " failed -> " + href + ":" + e) + hasNextPage = false; + page.loading = false; + return false; + } + if (page.entries != expectedEntries) { hasNextPage = false; page.loading = false; diff --git a/uaserials.js b/uaserials.js index 3e1a95f..b380c82 100644 --- a/uaserials.js +++ b/uaserials.js @@ -8,6 +8,7 @@ const html = require('movian/html'); /* CONSTANTS */ const DEFAULT_PAGE_TYPE = "directory"; +const DEFAULT_DEBUG = false; const PLUGIN = JSON.parse(Plugin.manifest); // plugin constants const PLUGIN_LOGO = Plugin.path + PLUGIN.icon; @@ -29,7 +30,9 @@ service.create(PLUGIN.title, PLUGIN.id + ':start', 'video', true, PLUGIN_LOGO); /* SETTINGS */ settings.globalSettings(PLUGIN.id, PLUGIN.title, PLUGIN_LOGO, PLUGIN.synopsis); -settings.createBool("debug", "Enable DEBUG", false, function (v) {service._debug = v}) +settings.createBool("debug", "Enable DEBUG", DEFAULT_DEBUG, function (v) {service._debug = v}) +settings._debug = DEFAULT_DEBUG; + function logDebug(message) { if (service._debug) { @@ -62,6 +65,10 @@ new page.Route(PLUGIN.id + ":start", function(page) { }) }) + page.appendItem(PLUGIN.id + ":collections", "directory", { + title: "Добірки фільмів, серіалів і мультфільмів" + }) + }); new page.Route(PLUGIN.id + ":list:(.*):(.*)", function(page, href, title) { @@ -77,6 +84,26 @@ new page.Route(PLUGIN.id + ":list:(.*):(.*)", function(page, href, title) { page.paginator = loader; }); +new page.Route(PLUGIN.id + ":collections", function(page) { + setPageHeader(page, DEFAULT_PAGE_TYPE, PLUGIN.id + " - " + "Добірки"); + href = BASE_URL + "/collections" + + parseCollections(page, href) +}); + +new page.Route(PLUGIN.id + ":collection:(.*):(.*)", function(page, href, title) { + setPageHeader(page, DEFAULT_PAGE_TYPE, PLUGIN.id + " - " + title); + + function generateSearchURL(nextPage) { + return BASE_URL + href + "/page/" + nextPage + "/" + } + + var loader = createPageLoader(page, generateSearchURL, 1); + loader(); + + page.paginator = loader; +}); + new page.Route(PLUGIN.id + ":moviepage:(.*):(.*)", function(page, href, title) { setPageHeader(page, DEFAULT_PAGE_TYPE, PLUGIN.id + " - " + title) @@ -88,12 +115,18 @@ new page.Route(PLUGIN.id + ":moviepage:(.*):(.*)", function(page, href, title) { // get details of movie (year, etc..) var detailsHTML = doc.getElementByClassName("short-list")[0].children; - var details = []; + var details = {}; for (var i = 0; i < detailsHTML.length; i++) { const item = detailsHTML[i]; - const detail = item.textContent; - details.push(detail); + if (!item.textContent) { continue; } + const match = item.textContent.match(/([^:]+):(.+)/); + if (match) { + const key = match[1].trim(); + const value = match[2].trim(); + details[key] = value; + } } + console.log(details) var imdbRating = doc.getElementByClassName("short-rates")[0].getElementByTagName("a"); if (imdbRating.length !== 0) { @@ -108,12 +141,21 @@ new page.Route(PLUGIN.id + ":moviepage:(.*):(.*)", function(page, href, title) { /* setup info on the page */ - page.appendPassiveItem('video', '', { + infoData = { title: title, icon: img, description: description, - rating: imdbRating ? imdbRating * 10 : 0, - }); + } + if (imdbRating) { + infoData.rating = imdbRating * 10; + } + if (details.hasOwnProperty("Рік")) { + infoData.year = parseInt(details["Рік"]); + } + if (details.hasOwnProperty("Жанр")) { + infoData.genre = new RichText(formatInfo(details["Жанр"])); + } + page.appendPassiveItem('video', '', infoData); currentMovieData = UASJsonDecrypt(htmlText); currentMovieData["title"] = title;