Skip to content

Commit

Permalink
Fix pinterest
Browse files Browse the repository at this point in the history
  • Loading branch information
qsniyg committed Nov 13, 2024
1 parent 17b1cbe commit 2f07b33
Show file tree
Hide file tree
Showing 3 changed files with 359 additions and 83 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Improvements:

* Various improvements/fixes to existing rules (including YouTube)
* Various improvements/fixes to existing rules (including Pinterest, YouTube)

Special thanks to nimbuz, remlap, Solus, immewnity, Froktime, billkewl, Broly, fyhtma, vscum, acidzab, sn3akyb3ar, ValiumBear, fireattack, NeverForgotten, liamengland1, mantou, siloricity, adz, RAT, DoomTay for their contributions and reports for this release

Expand Down
161 changes: 157 additions & 4 deletions src/userscript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36152,7 +36152,7 @@ var $$IMU_EXPORT$$;
newsrc = website_query({
website_regex: /^[a-z]+:\/\/[^/]+\/+pin\/+([0-9]+)\/*(?:[?#].*)?$/,
query_for_id: "https://www.pinterest.com/pin/${id}/",
process: function(done, resp, cache_key, website_match) {
process_old: function(done, resp, cache_key, website_match) {
var match = resp.responseText.match(/<script id="initial-state" type="application\/json">({.*?})<\/script>/);
if (!match) {
console_error(cache_key, "Unable to find initial state for", resp);
Expand Down Expand Up @@ -36264,14 +36264,165 @@ var $$IMU_EXPORT$$;
});
}

return done(obj, 6*60*60);
},
process: function(done, resp, cache_key, website_match) {
let matches = match_all(resp.responseText, /<script data-relay-response="true" type="application\/json">({.*?"data":\s*{\s*"v3GetPinQuery".*?})<\/script>/);
if (!matches) {
console_error(cache_key, "Unable to find pin queries for", resp);
return done(null, false);
}

let id = website_match[1];
let response = null;

for (let match of matches) {
let json = JSON_parse(match[1]);
let data = json.response.data.v3GetPinQuery.data;
if (data.entityId !== id)
continue;

if (!response) {
response = data;
} else {
for (let key in data) {
if (!(key in response)) {
response[key] = data[key];
}

if (key === "videos" && data[key]) {
if (data.videos.videoUrls)
response.videos.videoUrls = data.videos.videoUrls;
}
}
}
}

if (!response) {
console_error(cache_key, "Unable to find pin from", resp, matches);
return done(null, false);
}

//console_log(response);

var urls = [];

var baseobj:BigImageInfoSObject = {
extra: {
page: resp.finalUrl
}
};

if (response.title) {
baseobj.extra.caption = response.title;
}

let pinner = response.originPinner || response.pinner;
if (pinner) {
baseobj.extra.author_username = pinner.username;
}

if (response.videos) {
let get_url_properties = function(url) {
let props = {
hevc: 0,
videofile: 1,
dash: 0,
multi: 0,
type: null
};

if (/\/(?:hevc|h265)/.test(url)) {
props.hevc = 1;
}

if (/\.(?:m3u8|mpd)$/.test(url))
props.videofile = 0;

if (/\.mpd$/.test(url))
props.dash = 1;

if (/-multi-.*\.(?:m3u8|mpd)$/.test(url))
props.multi = 1;

let match = url.match(/_t([0-9]+)\./);
if (match) {
props.type = parseInt(match[1]);
}

return props;
};

let raw_videourls = response.videos.videoUrls;

let new_videourls = [];
for (let url of raw_videourls) {
if (array_indexof(new_videourls, url) >= 0)
continue;

let props = get_url_properties(url);
let delivery:VideoDelivery = null;
if (!props.videofile) {
delivery = props.dash ? "dash" : "hls"
};

new_videourls.push({
url: url,
media_info: {
type: "video",
delivery: delivery,
codec: props.hevc ? "hevc" : null
}
});
}

new_videourls.sort(function(a, b) {
let ap = get_url_properties(a.url);
let bp = get_url_properties(b.url);

if (ap.hevc !== bp.hevc)
return bp.hevc - ap.hevc;

// prioritize streams over raw video files
if (ap.videofile !== bp.videofile)
return ap.videofile - bp.videofile;

if (ap.multi !== bp.multi)
return bp.multi - ap.multi;

// dash requires less network calls
if (!ap.videofile && !bp.videofile && ap.dash !== bp.dash)
return bp.dash - ap.dash;

if (ap.type !== null && bp.type !== null)
return bp.type - ap.type;

return 0;
});

array_extend(urls, new_videourls);
}

if (response.imageSpec_orig) {
urls.push(response.imageSpec_orig.url);
}

var obj = fillobj_urls(urls, baseobj);

if (response.link) {
obj.unshift({
url: response.link,
is_pagelink: true
});
}

return done(obj, 6*60*60);
}
});
if (newsrc) return newsrc;
}

// disabling for now because it's broken
if (false && common_functions["is_pinterest_domain"](host_domain) && options.element) {
if (common_functions["is_pinterest_domain"](host_domain) && options.element) {
var current = options.element;
do {
if (current.tagName === "A" && /^[a-z]+:\/\/[^/]+\/+pin\/+[0-9]{5,}/.test(current.href)) {
Expand Down Expand Up @@ -115626,7 +115777,9 @@ var $$IMU_EXPORT$$;
.replace(/\/img\/+(.*[0-9]+\.[a-z]+)(?:[?#].*)?$/, "/images/u/$1");
}

if (domain_nosub === "pimeyes.com" && /^jsc[0-9]*\./.test(domain)) {
if ((domain_nosub === "pimeyes.com" && /^jsc[0-9]*\./.test(domain)) ||
domain === "94.130.187.81" ||
domain === "94.130.99.222") {
// thanks to anonymous for reporting:
// https://jsc7.pimeyes.com/proxy/7b2275...
match = src.match(/\/proxy\/+(7b2275[0-9a-f]+)(?:[?#].*)?$/i);
Expand Down
Loading

0 comments on commit 2f07b33

Please sign in to comment.