Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion dist/rule34video/meta.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,38 @@ var getMeta = async function({
const is4k = html.includes("2160p") || html.includes("4k") || html.includes("_4k");
const is1080p = html.includes("1080p");
const quality = is4k ? "2160p" : is1080p ? "1080p" : "720p";
const tags = [];
$('.vp-tags a[href*="/tags/"]').each((_, el) => {
const tagText = $(el).text().trim();
if (tagText && tagText !== "Tags" && !tags.includes(tagText)) {
tags.push(tagText);
}
});
let duration = "";
const durMatch = html.match(
/"duration":\s*"PT(?:(\d+)H)?(?:(\d+)M)?(?:(\d+)S)?"/i
);
if (durMatch) {
const h = parseInt(durMatch[1] || "0", 10);
const m = parseInt(durMatch[2] || "0", 10);
const s = parseInt(durMatch[3] || "0", 10);
duration = h > 0 ? `${h}:${String(m).padStart(2, "0")}:${String(s).padStart(2, "0")}` : `${m}:${String(s).padStart(2, "0")}`;
}
const synopsisParts = [
`${title}${duration ? ` \u2014 ${duration}` : ""} \u2022 ${quality}.`
];
if (tags.length > 0) {
synopsisParts.push(`Tags: ${tags.join(", ")}.`);
}
const synopsis = synopsisParts.join(" ");
return {
title,
synopsis: "",
synopsis,
image,
poster: image,
imdbId: "",
type: "movie",
tags: tags.length > 0 ? tags : void 0,
rating: quality,
webUrl: url,
linkList: [
Expand Down
30 changes: 19 additions & 11 deletions dist/rule34video/posts.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,15 +187,19 @@ function updateLearnedDomain(res, baseUrl, kvStore) {
} catch (e) {
}
}
function fisherYatesShuffle(list) {
var arr = list.slice();
for (var i = arr.length - 1; i > 0; i--) {
var j = Math.floor(Math.random() * (i + 1));
var temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
function compareTitle(a, b) {
var ax = String(a).toLowerCase().split(/(\d+)/);
var bx = String(b).toLowerCase().split(/(\d+)/);
for (var i = 0; i < Math.max(ax.length, bx.length); i++) {
if (ax[i] === void 0) return -1;
if (bx[i] === void 0) return 1;
if (ax[i] === bx[i]) continue;
var an = Number(ax[i]);
var bn = Number(bx[i]);
if (!isNaN(an) && !isNaN(bn)) return an - bn;
return ax[i] < bx[i] ? -1 : 1;
}
return arr;
return 0;
}
function interleavePosts(groups) {
var result = [];
Expand Down Expand Up @@ -295,7 +299,7 @@ async function parseVideoGrid(options) {
});
});
posts.sort(function(a, b) {
return (b._dur || 0) - (a._dur || 0);
return compareTitle(a.title || "", b.title || "");
});
return posts;
} catch (err) {
Expand Down Expand Up @@ -343,7 +347,7 @@ var getPosts = async function(params) {
signal,
kvStore
});
return fisherYatesShuffle(posts);
return posts;
}
if (category && category.mode === "multi_query") {
var tags = Array.isArray(category.rule34Tags) ? category.rule34Tags : [];
Expand All @@ -366,7 +370,11 @@ var getPosts = async function(params) {
});
})
);
return interleavePosts(tagResults).slice(0, 60);
var merged = interleavePosts(tagResults);
merged.sort(function(a, b) {
return compareTitle(a.title || "", b.title || "");
});
return merged.slice(0, 60);
}
if (filter === "/family/" || filter === "/family") {
var familyUrl = page > 1 ? baseUrl + "/search/family/" + page + "/" : baseUrl + "/search/family/";
Expand Down
28 changes: 24 additions & 4 deletions dist/xvideos/meta.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,33 @@ var getMeta = async function({
const playerThumb169Match = html.match(/html5player\.setThumbUrl169\s*\(\s*['"]([^'"]+)['"]\s*\)/i);
const image = (playerThumb169Match ? playerThumb169Match[1] : null) || (playerThumbMatch ? playerThumbMatch[1] : null) || $('meta[property="og:image"]').attr("content") || "";
const tags = [];
$(".video-tags a, .tags-list a, .video-metadata a").each((_, el) => {
$('.video-tags-list a[href^="/tags/"]').each((_, el) => {
const tagText = $(el).text().trim();
if (tagText && !tags.includes(tagText)) {
if (tagText && tagText !== "Edit tags" && !tags.includes(tagText)) {
tags.push(tagText);
}
});
const cast = [];
$(
'.video-tags-list a[href^="/models/"], .video-tags-list a[href^="/amateurs/"]'
).each((_, el) => {
const name = $(el).clone().find(".count, .user-subscribe").remove().end().text().trim().replace(/\s*\d+[kM]?$/, "");
if (name && !cast.includes(name)) {
cast.push(name);
}
});
const duration = $(".duration, .video-duration").first().text().trim();
const synopsis = tags.length > 0 ? `Tags: ${tags.join(", ")}` : title;
const quality = html.includes("setVideoUrlHigh") || html.includes("1080p") ? "1080p" : "720p";
const synopsisParts = [
`${title}${duration ? ` \u2014 ${duration}` : ""} \u2022 ${quality}.`
];
if (cast.length > 0) {
synopsisParts.push(`Starring ${cast.join(", ")}.`);
}
if (tags.length > 0) {
synopsisParts.push(`Tags: ${tags.join(", ")}.`);
}
const synopsis = synopsisParts.join(" ");
return {
title,
synopsis,
Expand All @@ -70,12 +89,13 @@ var getMeta = async function({
imdbId: "",
type: "movie",
tags: tags.length > 0 ? tags : void 0,
cast: cast.length > 0 ? cast : void 0,
rating: duration || void 0,
webUrl: url,
linkList: [
{
title: "Stream Video",
quality: html.includes("setVideoUrlHigh") || html.includes("1080p") ? "1080p" : "720p",
quality,
directLinks: [
{
title,
Expand Down
30 changes: 19 additions & 11 deletions dist/xvideos/posts.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,15 +187,19 @@ function updateLearnedDomain(res, baseUrl, kvStore) {
} catch (e) {
}
}
function fisherYatesShuffle(list) {
var arr = list.slice();
for (var i = arr.length - 1; i > 0; i--) {
var j = Math.floor(Math.random() * (i + 1));
var temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
function compareTitle(a, b) {
var ax = String(a).toLowerCase().split(/(\d+)/);
var bx = String(b).toLowerCase().split(/(\d+)/);
for (var i = 0; i < Math.max(ax.length, bx.length); i++) {
if (ax[i] === void 0) return -1;
if (bx[i] === void 0) return 1;
if (ax[i] === bx[i]) continue;
var an = Number(ax[i]);
var bn = Number(bx[i]);
if (!isNaN(an) && !isNaN(bn)) return an - bn;
return ax[i] < bx[i] ? -1 : 1;
}
return arr;
return 0;
}
function interleavePosts(groups) {
var result = [];
Expand Down Expand Up @@ -294,7 +298,7 @@ async function parseVideoGrid(options) {
});
});
posts.sort(function(a, b) {
return (b._dur || 0) - (a._dur || 0);
return compareTitle(a.title || "", b.title || "");
});
return posts;
} catch (err) {
Expand Down Expand Up @@ -343,7 +347,7 @@ var getPosts = async function(params) {
signal,
kvStore
});
return fisherYatesShuffle(posts);
return posts;
}
if (category && category.mode === "multi_query") {
var queries = Array.isArray(category.xvideosQueries) ? category.xvideosQueries : [];
Expand All @@ -365,7 +369,11 @@ var getPosts = async function(params) {
});
})
);
return interleavePosts(queryResults).slice(0, 60);
var merged = interleavePosts(queryResults);
merged.sort(function(a, b) {
return compareTitle(a.title || "", b.title || "");
});
return merged.slice(0, 60);
}
if (filter === "/family/" || filter === "/family") {
var pNum = page > 1 ? page - 1 : 0;
Expand Down
4 changes: 2 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
"display_name": "XVideos",
"value": "xvideos",
"version": "1.9",
"version": "2.0",
"icon": "https://cdn-icons-png.flaticon.com/512/831/831331.png",
"type": "global",
"disabled": false,
Expand All @@ -11,7 +11,7 @@
{
"display_name": "Rule34Video",
"value": "rule34video",
"version": "1.9",
"version": "2.0",
"icon": "https://rule34video.com/apple-touch-icon.png",
"type": "global",
"disabled": false,
Expand Down
38 changes: 37 additions & 1 deletion providers/rule34video/meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,49 @@ export const getMeta = async function ({
const is1080p = html.includes("1080p");
const quality = is4k ? "2160p" : (is1080p ? "1080p" : "720p");

// The video's own tags live in .vp-tags (tag_vote_chip links).
// The old code returned no tags at all, so the detail screen
// showed no tags and "No synopsis available".
const tags: string[] = [];
$('.vp-tags a[href*="/tags/"]').each((_, el) => {
const tagText = $(el).text().trim();
if (tagText && tagText !== "Tags" && !tags.includes(tagText)) {
tags.push(tagText);
}
});

// Duration is in the page's JSON-LD as ISO 8601, e.g. PT0H58M54S.
// (The .time elements on the page belong to related videos.)
let duration = "";
const durMatch = html.match(
/"duration":\s*"PT(?:(\d+)H)?(?:(\d+)M)?(?:(\d+)S)?"/i
);
if (durMatch) {
const h = parseInt(durMatch[1] || "0", 10);
const m = parseInt(durMatch[2] || "0", 10);
const s = parseInt(durMatch[3] || "0", 10);
duration =
h > 0
? `${h}:${String(m).padStart(2, "0")}:${String(s).padStart(2, "0")}`
: `${m}:${String(s).padStart(2, "0")}`;
}

const synopsisParts = [
`${title}${duration ? ` — ${duration}` : ""} • ${quality}.`,
];
if (tags.length > 0) {
synopsisParts.push(`Tags: ${tags.join(", ")}.`);
}
const synopsis = synopsisParts.join(" ");

return {
title,
synopsis: "",
synopsis,
image,
poster: image,
imdbId: "",
type: "movie",
tags: tags.length > 0 ? tags : undefined,
rating: quality,
webUrl: url,
linkList: [
Expand Down
39 changes: 28 additions & 11 deletions providers/rule34video/posts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,22 @@ function updateLearnedDomain(res, baseUrl, kvStore) {
} catch (e) {}
}

function fisherYatesShuffle(list) {
var arr = list.slice();
for (var i = arr.length - 1; i > 0; i--) {
var j = Math.floor(Math.random() * (i + 1));
var temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
// Natural, case-insensitive title comparison ("Part 2" before "Part 10").
// Implemented by hand so it behaves the same in every JS engine Vega's
// sandbox may use, without relying on localeCompare options.
function compareTitle(a, b) {
var ax = String(a).toLowerCase().split(/(\d+)/);
var bx = String(b).toLowerCase().split(/(\d+)/);
for (var i = 0; i < Math.max(ax.length, bx.length); i++) {
if (ax[i] === undefined) return -1;
if (bx[i] === undefined) return 1;
if (ax[i] === bx[i]) continue;
var an = Number(ax[i]);
var bn = Number(bx[i]);
if (!isNaN(an) && !isNaN(bn)) return an - bn;
return ax[i] < bx[i] ? -1 : 1;
}
return arr;
return 0;
}

function interleavePosts(groups) {
Expand Down Expand Up @@ -256,8 +263,10 @@ async function parseVideoGrid(options) {
});
});

// Alphabetical by title, so parts of the same clip sit together
// instead of roaming through the pool (was: longest first).
posts.sort(function (a, b) {
return (b._dur || 0) - (a._dur || 0);
return compareTitle(a.title || "", b.title || "");
});

return posts;
Expand Down Expand Up @@ -315,7 +324,9 @@ export const getPosts = async function (params) {
signal: signal,
kvStore: kvStore,
});
return fisherYatesShuffle(posts);
// The page itself is random on every refresh; within it the
// videos are alphabetical so parts of a clip stay together.
return posts;
}

if (category && category.mode === "multi_query") {
Expand Down Expand Up @@ -348,7 +359,13 @@ export const getPosts = async function (params) {
// fetches the next page anyway. Shipping all of them made the
// sandbox-bridge transfer and the app's list work heavier on
// every scroll/category load.
return interleavePosts(tagResults).slice(0, 60);
// Sort the merged list alphabetically (interleaving alone would
// scatter parts of the same clip again) and then cap it.
var merged = interleavePosts(tagResults);
merged.sort(function (a, b) {
return compareTitle(a.title || "", b.title || "");
});
return merged.slice(0, 60);
}

if (filter === "/family/" || filter === "/family") {
Expand Down
Loading