pinterest: pin.it support & fix parsing
This commit is contained in:
parent
8c868c4385
commit
9aabb4d738
6 changed files with 39 additions and 24 deletions
|
@ -578,7 +578,7 @@ export default function(obj) {
|
||||||
<div id="download-area">
|
<div id="download-area">
|
||||||
<div id="top">
|
<div id="top">
|
||||||
<div id="link-icon">${linkSVG}</div>
|
<div id="link-icon">${linkSVG}</div>
|
||||||
<input id="url-input-area" class="mono" type="text" autocorrect="off" maxlength="128" autocapitalize="off" placeholder="${t('LinkInput')}" aria-label="${t('AccessibilityInputArea')}" oninput="button()"></input>
|
<input id="url-input-area" class="mono" type="text" autocorrect="off" maxlength="256" autocapitalize="off" placeholder="${t('LinkInput')}" aria-label="${t('AccessibilityInputArea')}" oninput="button()"></input>
|
||||||
<button id="url-clear" onclick="clearInput()" style="display:none;">x</button>
|
<button id="url-clear" onclick="clearInput()" style="display:none;">x</button>
|
||||||
<input id="download-button" class="mono dontRead" onclick="download(document.getElementById('url-input-area').value)" type="submit" value="" disabled=true aria-label="${t('AccessibilityDownloadButton')}">
|
<input id="download-button" class="mono dontRead" onclick="download(document.getElementById('url-input-area').value)" type="submit" value="" disabled=true aria-label="${t('AccessibilityDownloadButton')}">
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -133,7 +133,8 @@ export default async function(host, patternMatch, url, lang, obj) {
|
||||||
break;
|
break;
|
||||||
case "pinterest":
|
case "pinterest":
|
||||||
r = await pinterest({
|
r = await pinterest({
|
||||||
id: patternMatch.id
|
id: patternMatch.id,
|
||||||
|
shortLink: patternMatch.shortLink || false
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case "streamable":
|
case "streamable":
|
||||||
|
|
|
@ -1,29 +1,36 @@
|
||||||
import { maxVideoDuration } from "../../config.js";
|
import { genericUserAgent } from "../../config.js";
|
||||||
|
|
||||||
export default async function(obj) {
|
const videoLinkBase = {
|
||||||
const pinId = obj.id.split('--').reverse()[0];
|
"regular": "https://v1.pinimg.com/videos/mc/720p/",
|
||||||
if (!(/^\d+$/.test(pinId))) return { error: 'ErrorCantGetID' };
|
"story": "https://v1.pinimg.com/videos/mc/720p/"
|
||||||
let data = await fetch(`https://www.pinterest.com/resource/PinResource/get?data=${encodeURIComponent(JSON.stringify({
|
}
|
||||||
options: {
|
|
||||||
field_set_key: "unauth_react_main_pin",
|
|
||||||
id: pinId
|
|
||||||
}
|
|
||||||
}))}`).then((r) => { return r.json() }).catch(() => { return false });
|
|
||||||
if (!data) return { error: 'ErrorCouldntFetch' };
|
|
||||||
|
|
||||||
data = data["resource_response"]["data"];
|
export default async function(o) {
|
||||||
|
let id = o.id, type = "regular";
|
||||||
|
|
||||||
let video = null;
|
if (id.includes("--")) {
|
||||||
|
id = id.split("--")[1];
|
||||||
|
type = "story";
|
||||||
|
}
|
||||||
|
if (!o.id && o.shortLink) {
|
||||||
|
id = await fetch(`https://api.pinterest.com/url_shortener/${o.shortLink}/redirect/`, { redirect: "manual" }).then((r) => {
|
||||||
|
return r.headers.get("location").split('pin/')[1].split('/')[0]
|
||||||
|
}).catch(() => {});
|
||||||
|
}
|
||||||
|
if (!id) return { error: 'ErrorCouldntFetch' };
|
||||||
|
|
||||||
if (data.videos !== null) video = data.videos.video_list.V_720P;
|
let html = await fetch(`https://www.pinterest.com/pin/${id}/`, {
|
||||||
else if (data.story_pin_data !== null) video = data.story_pin_data.pages[0].blocks[0].video.video_list.V_EXP7;
|
headers: { "user-agent": genericUserAgent }
|
||||||
|
}).then((r) => { return r.text() }).catch(() => { return false });
|
||||||
|
|
||||||
if (!video) return { error: 'ErrorEmptyDownload' };
|
if (!html) return { error: 'ErrorCouldntFetch' };
|
||||||
if (video.duration > maxVideoDuration) return { error: ['ErrorLengthLimit', maxVideoDuration / 60000] };
|
|
||||||
|
let videoLink = html.split(`"url":"${videoLinkBase[type]}`)[1]?.split('"')[0];
|
||||||
|
if (!html.includes(videoLink)) return { error: 'ErrorEmptyDownload' };
|
||||||
|
|
||||||
return {
|
return {
|
||||||
urls: video.url,
|
urls: `${videoLinkBase[type]}${videoLink}`,
|
||||||
filename: `pinterest_${pinId}.mp4`,
|
filename: `pinterest_${o.id}.mp4`,
|
||||||
audioFilename: `pinterest_${pinId}_audio`
|
audioFilename: `pinterest_${o.id}_audio`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,7 +86,7 @@
|
||||||
},
|
},
|
||||||
"pinterest": {
|
"pinterest": {
|
||||||
"alias": "pinterest videos & stories",
|
"alias": "pinterest videos & stories",
|
||||||
"patterns": ["pin/:id"],
|
"patterns": ["pin/:id", "url_shortener/:shortLink"],
|
||||||
"enabled": true
|
"enabled": true
|
||||||
},
|
},
|
||||||
"streamable": {
|
"streamable": {
|
||||||
|
|
|
@ -10,7 +10,7 @@ export const testers = {
|
||||||
patternMatch.id?.length <= 16,
|
patternMatch.id?.length <= 16,
|
||||||
|
|
||||||
"pinterest": (patternMatch) =>
|
"pinterest": (patternMatch) =>
|
||||||
patternMatch.id?.length <= 128,
|
patternMatch.id?.length <= 128 || patternMatch.shortLink?.length <= 32,
|
||||||
|
|
||||||
"reddit": (patternMatch) =>
|
"reddit": (patternMatch) =>
|
||||||
patternMatch.sub?.length <= 22 && patternMatch.id?.length <= 10,
|
patternMatch.sub?.length <= 22 && patternMatch.id?.length <= 10,
|
||||||
|
|
|
@ -25,6 +25,13 @@ export function aliasURL(url) {
|
||||||
}`)
|
}`)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case "pin":
|
||||||
|
if (url.hostname === 'pin.it' && parts.length === 2) {
|
||||||
|
url = new URL(`https://pinterest.com/url_shortener/${
|
||||||
|
encodeURIComponent(parts[1])
|
||||||
|
}`)
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case "vxtwitter":
|
case "vxtwitter":
|
||||||
case "fixvx":
|
case "fixvx":
|
||||||
|
|
Loading…
Reference in a new issue