Skip to content

Commit

Permalink
add collections, fix 404 page 2, show year+genre
Browse files Browse the repository at this point in the history
  • Loading branch information
eclipse7723 committed Aug 9, 2024
1 parent c090588 commit 7a3ff1e
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 12 deletions.
2 changes: 1 addition & 1 deletion plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
49 changes: 45 additions & 4 deletions src/movie-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,41 @@ function getColoredFormat(text, color) {
function formatInfo(text) {
return getColoredFormat(text, COLOR_GRAY);
}
function formatBold(text) {
return "<b>" + text + "</b>";
}
// ---------------------------------------------------------------


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);
Expand All @@ -28,16 +60,16 @@ function parseMovies(page, href) {

var desc = "";
if (titleEn) {
desc += formatInfo("Оригінальна назва: <b>" + titleEn + "</b>");
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);
Expand Down Expand Up @@ -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;
Expand Down
56 changes: 49 additions & 7 deletions uaserials.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down Expand Up @@ -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) {
Expand All @@ -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)

Expand All @@ -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) {
Expand All @@ -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;
Expand Down

0 comments on commit 7a3ff1e

Please sign in to comment.