mirror of
https://github.com/wukko/cobalt.git
synced 2024-11-17 22:00:00 +00:00
tumblr: use mobile api & fix audio support (#366)
This commit is contained in:
commit
78c885bb62
3 changed files with 62 additions and 26 deletions
|
@ -143,7 +143,7 @@ export default function(r, host, userFormat, isAudioOnly, lang, isAudioMuted, di
|
||||||
const isBestHostAudio = services[host]["bestAudio"] && (audioFormat === services[host]["bestAudio"]);
|
const isBestHostAudio = services[host]["bestAudio"] && (audioFormat === services[host]["bestAudio"]);
|
||||||
|
|
||||||
const isTikTok = host === "tiktok" || host === "douyin";
|
const isTikTok = host === "tiktok" || host === "douyin";
|
||||||
const isTumblr = host === "tumblr" && !r.filename;
|
const isTumblrAudio = host === "tumblr" && !r.filename;
|
||||||
const isSoundCloud = host === "soundcloud";
|
const isSoundCloud = host === "soundcloud";
|
||||||
|
|
||||||
if (isTikTok && services.tiktok.audioFormats.includes(audioFormat)) {
|
if (isTikTok && services.tiktok.audioFormats.includes(audioFormat)) {
|
||||||
|
@ -168,11 +168,6 @@ export default function(r, host, userFormat, isAudioOnly, lang, isAudioMuted, di
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isTumblr && isBestOrMp3) {
|
|
||||||
audioFormat = "mp3";
|
|
||||||
processType = "bridge"
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isBestAudioDefined || isBestHostAudio) {
|
if (isBestAudioDefined || isBestHostAudio) {
|
||||||
audioFormat = services[host]["bestAudio"];
|
audioFormat = services[host]["bestAudio"];
|
||||||
processType = "bridge";
|
processType = "bridge";
|
||||||
|
@ -181,6 +176,11 @@ export default function(r, host, userFormat, isAudioOnly, lang, isAudioMuted, di
|
||||||
copy = true
|
copy = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isTumblrAudio && isBestOrMp3) {
|
||||||
|
audioFormat = "mp3";
|
||||||
|
processType = "bridge"
|
||||||
|
}
|
||||||
|
|
||||||
if (r.isM3U8 || host === "vimeo") {
|
if (r.isM3U8 || host === "vimeo") {
|
||||||
copy = false;
|
copy = false;
|
||||||
processType = "render"
|
processType = "render"
|
||||||
|
|
|
@ -1,8 +1,26 @@
|
||||||
import psl from "psl";
|
import psl from "psl";
|
||||||
import { genericUserAgent } from "../../config.js";
|
import { genericUserAgent } from "../../config.js";
|
||||||
|
|
||||||
export default async function(obj) {
|
const API_KEY = 'jrsCWX1XDuVxAFO4GkK147syAoN8BJZ5voz8tS80bPcj26Vc5Z';
|
||||||
let { subdomain } = psl.parse(obj.url.hostname);
|
const API_BASE = 'https://api-http2.tumblr.com';
|
||||||
|
|
||||||
|
function request(domain, id) {
|
||||||
|
const url = new URL(`/v2/blog/${domain}/posts/${id}/permalink`, API_BASE);
|
||||||
|
url.searchParams.set('api_key', API_KEY);
|
||||||
|
url.searchParams.set('fields[blogs]', 'uuid,name,avatar,?description,?can_message,?can_be_followed,?is_adult,?reply_conditions,'
|
||||||
|
+ '?theme,?title,?url,?is_blocked_from_primary,?placement_id,?primary,?updated,?followed,'
|
||||||
|
+ '?ask,?can_subscribe,?paywall_access,?subscription_plan,?is_blogless_advertiser,?tumblrmart_accessories');
|
||||||
|
|
||||||
|
return fetch(url, {
|
||||||
|
headers: {
|
||||||
|
'User-Agent': 'Tumblr/iPhone/33.3/333010/17.3.1/tumblr',
|
||||||
|
'X-Version': 'iPhone/33.3/333010/17.3.1/tumblr'
|
||||||
|
}
|
||||||
|
}).then(a => a.json()).catch(() => {});
|
||||||
|
}
|
||||||
|
|
||||||
|
export default async function(input) {
|
||||||
|
let { subdomain } = psl.parse(input.url.hostname);
|
||||||
|
|
||||||
if (subdomain?.includes('.')) {
|
if (subdomain?.includes('.')) {
|
||||||
return { error: ['ErrorBrokenLink', 'tumblr'] }
|
return { error: ['ErrorBrokenLink', 'tumblr'] }
|
||||||
|
@ -10,26 +28,44 @@ export default async function(obj) {
|
||||||
subdomain = undefined
|
subdomain = undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
let html = await fetch(`https://${subdomain ?? obj.user}.tumblr.com/post/${obj.id}`, {
|
const domain = `${subdomain ?? input.user}.tumblr.com`;
|
||||||
headers: { "user-agent": genericUserAgent }
|
const data = await request(domain, input.id);
|
||||||
}).then((r) => { return r.text() }).catch(() => { return false });
|
|
||||||
|
|
||||||
if (!html) return { error: 'ErrorCouldntFetch' };
|
const element = data?.response?.timeline?.elements?.[0];
|
||||||
|
if (!element) return { error: 'ErrorEmptyDownload' };
|
||||||
|
|
||||||
let r;
|
const contents = [
|
||||||
if (html.includes('property="og:video" content="https://va.media.tumblr.com/')) {
|
...element.content,
|
||||||
r = {
|
...element?.trail?.map(t => t.content).flat()
|
||||||
urls: `https://va.media.tumblr.com/${html.split('property="og:video" content="https://va.media.tumblr.com/')[1].split('"')[0]}`,
|
]
|
||||||
filename: `tumblr_${obj.id}.mp4`,
|
|
||||||
audioFilename: `tumblr_${obj.id}_audio`
|
const audio = contents.find(c => c.type === 'audio');
|
||||||
}
|
if (audio && audio.provider === 'tumblr') {
|
||||||
} else if (html.includes('property="og:audio" content="https://a.tumblr.com/')) {
|
const fileMetadata = {
|
||||||
r = {
|
title: audio?.title,
|
||||||
urls: `https://a.tumblr.com/${html.split('property="og:audio" content="https://a.tumblr.com/')[1].split('"')[0]}`,
|
artist: audio?.artist
|
||||||
audioFilename: `tumblr_${obj.id}`,
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
urls: audio.media.url,
|
||||||
|
filenameAttributes: {
|
||||||
|
service: 'tumblr',
|
||||||
|
id: input.id,
|
||||||
|
title: fileMetadata.title,
|
||||||
|
author: fileMetadata.artist
|
||||||
|
},
|
||||||
isAudioOnly: true
|
isAudioOnly: true
|
||||||
}
|
}
|
||||||
} else r = { error: 'ErrorEmptyDownload' };
|
}
|
||||||
|
|
||||||
return r
|
const video = contents.find(c => c.type === 'video');
|
||||||
|
if (video && video.provider === 'tumblr') {
|
||||||
|
return {
|
||||||
|
urls: video.media.url,
|
||||||
|
filename: `tumblr_${input.id}.mp4`,
|
||||||
|
audioFilename: `tumblr_${input.id}_audio`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return { error: 'ErrorEmptyDownload' }
|
||||||
}
|
}
|
||||||
|
|
|
@ -790,7 +790,7 @@
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
"name": "tumblr audio",
|
"name": "tumblr audio",
|
||||||
"url": "https://rf9weu8hjf789234hf9.tumblr.com/post/172006661342/everyone-thats-made-a-video-out-of-this-without",
|
"url": "https://www.tumblr.com/zedneon/737815079301562368/zedneon-ft-mr-sauceman-tech-n9ne-speed-of?source=share",
|
||||||
"params": {},
|
"params": {},
|
||||||
"expected": {
|
"expected": {
|
||||||
"code": 200,
|
"code": 200,
|
||||||
|
|
Loading…
Reference in a new issue