mirror of
https://github.com/imputnet/cobalt.git
synced 2025-07-14 01:08:27 +00:00
Linkedin video download integration
This commit is contained in:
parent
a25615982c
commit
f6752dbb54
@ -17,6 +17,7 @@ import vimeo from "./services/vimeo.js";
|
||||
import soundcloud from "./services/soundcloud.js";
|
||||
import instagram from "./services/instagram.js";
|
||||
import vine from "./services/vine.js";
|
||||
import linkedin from "./services/linkedin.js";
|
||||
|
||||
export default async function (host, patternMatch, url, lang, obj) {
|
||||
try {
|
||||
@ -110,6 +111,13 @@ export default async function (host, patternMatch, url, lang, obj) {
|
||||
case "vine":
|
||||
r = await vine({ id: patternMatch["id"] });
|
||||
break;
|
||||
case "linkedin":
|
||||
r = await linkedin({
|
||||
user: patternMatch["user"],
|
||||
quality: obj.vQuality,
|
||||
id: patternMatch["id"]
|
||||
})
|
||||
break;
|
||||
default:
|
||||
return apiJSON(0, { t: errorUnsupported(lang) });
|
||||
}
|
||||
@ -121,6 +129,7 @@ export default async function (host, patternMatch, url, lang, obj) {
|
||||
|
||||
return matchActionDecider(r, host, obj.ip, obj.aFormat, isAudioOnly, lang, isAudioMuted);
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
return apiJSON(0, { t: genericError(lang, host) })
|
||||
}
|
||||
}
|
||||
|
38
src/modules/processing/services/linkedin.js
Normal file
38
src/modules/processing/services/linkedin.js
Normal file
@ -0,0 +1,38 @@
|
||||
import { genericUserAgent } from "../../config.js";
|
||||
|
||||
const qualityMatch = {
|
||||
// "feedshare-ambry-analyzed_servable_progressive_video": "1080", can vary!
|
||||
"mp4-720p-30fp-crf28": "720",
|
||||
"mp4-640p-30fp-crf28": "640"
|
||||
}
|
||||
|
||||
const height = {
|
||||
//"1080": "1920",
|
||||
"720": "1280",
|
||||
"640": "1138"
|
||||
}
|
||||
|
||||
export default async function(obj) {
|
||||
let html = await fetch(`https://www.linkedin.com/posts/${obj["user"]}_${obj["id"]}`, {
|
||||
headers: { "user-agent": genericUserAgent }
|
||||
}).then((r) => { return r.text() }).catch(() => { console.log("FALSE"); return false });
|
||||
|
||||
if (!html) return { error: 'ErrorCouldntFetch' };
|
||||
|
||||
let data = html.split("data-sources=\"")[1].split("\" data-poster-url")[0]
|
||||
data = data.replaceAll(""", "\"").replaceAll("&", "&")
|
||||
let dataSources = JSON.parse(data)
|
||||
|
||||
let available = dataSources.map(ob => qualityMatch[ob["src"].split("/")[5]])
|
||||
// let bestQuality;
|
||||
// if (obj.quality === "max" || Number(obj.quality) > 1080) bestQuality = "1080";
|
||||
// else if (Number(obj.quality) < 720) bestQuality = "640";
|
||||
// else bestQuality = (available.includes(obj.quality)) ? obj.quality : "720";
|
||||
let bestQuality = (Number(obj.quality) >= 720) ? "720" : "640";
|
||||
if (!available.includes(bestQuality)) bestQuality = (bestQuality === "720") ? "640" : "720";
|
||||
|
||||
return {
|
||||
urls: dataSources[available.indexOf(bestQuality)]["src"],
|
||||
filename: `linkedin_${obj["id"].slice(-24)}_${bestQuality}x${height[bestQuality]}.mp4`
|
||||
}
|
||||
}
|
@ -62,6 +62,11 @@
|
||||
"tld": "co",
|
||||
"patterns": ["v/:id"],
|
||||
"enabled": true
|
||||
},
|
||||
"linkedin": {
|
||||
"alias": "linkedin video",
|
||||
"patterns": ["posts/:user_:id"],
|
||||
"enabled": true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -28,5 +28,7 @@ export const testers = {
|
||||
|
||||
"instagram": (patternMatch) => (patternMatch["id"] && patternMatch["id"].length <= 12),
|
||||
|
||||
"vine": (patternMatch) => (patternMatch["id"] && patternMatch["id"].length <= 12)
|
||||
"vine": (patternMatch) => (patternMatch["id"] && patternMatch["id"].length <= 12),
|
||||
|
||||
"linkedin": (patternMatch) => (patternMatch["user"] && patternMatch["id"].length > 24)
|
||||
}
|
||||
|
@ -869,5 +869,26 @@
|
||||
"code": 200,
|
||||
"status": "stream"
|
||||
}
|
||||
}],
|
||||
"linkedin": [{
|
||||
"name": "linkedin 640p video",
|
||||
"url": "https://www.linkedin.com/posts/seema-yadav-211508112_mathematics-algebra-engineering-activity-7054296523567751168-uf9P",
|
||||
"params": {
|
||||
"vQuality": "480"
|
||||
},
|
||||
"expected":{
|
||||
"code": 200,
|
||||
"status": "stream"
|
||||
}
|
||||
}, {
|
||||
"name": "linkedin 720p video",
|
||||
"url": "https://www.linkedin.com/posts/seema-yadav-211508112_mathematics-algebra-engineering-activity-7054296523567751168-uf9P",
|
||||
"params": {
|
||||
"vQuality": "max"
|
||||
},
|
||||
"expected":{
|
||||
"code": 200,
|
||||
"status": "stream"
|
||||
}
|
||||
}]
|
||||
}
|
Loading…
Reference in New Issue
Block a user