Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

linkedin: add linkedin support #594

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ this list is not final and keeps expanding over time. if support for a service y
| bilibili.com & bilibili.tv | ✅ | ✅ | ✅ | ➖ | ➖ |
| dailymotion | ✅ | ✅ | ✅ | ✅ | ✅ |
| instagram posts & reels | ✅ | ✅ | ✅ | ➖ | ➖ |
| linkedin | ✅ | ✅ | ✅ | ❌ | ❌ |
| loom | ✅ | ❌ | ✅ | ✅ | ➖ |
| ok video | ✅ | ❌ | ✅ | ✅ | ✅ |
| pinterest | ✅ | ✅ | ✅ | ➖ | ➖ |
Expand All @@ -45,6 +46,7 @@ this list is not final and keeps expanding over time. if support for a service y
| service | notes or features |
| :-------- | :----- |
| instagram | supports reels, photos, and videos. lets you pick what to save from multi-media posts. |
| linkedin | supports post and feed links. |
| pinterest | supports photos, gifs, videos and stories. |
| reddit | supports gifs and videos. |
| rutube | supports yappy & private links. |
Expand Down
7 changes: 7 additions & 0 deletions src/modules/processing/match.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import twitch from "./services/twitch.js";
import rutube from "./services/rutube.js";
import dailymotion from "./services/dailymotion.js";
import loom from "./services/loom.js";
import linkedin from "./services/linkedin.js";

let freebind;

Expand Down Expand Up @@ -193,6 +194,12 @@ export default async function(host, patternMatch, lang, obj) {
id: patternMatch.id
});
break;
case "linkedin":
r = await linkedin({
postId: patternMatch.id,
quality: obj.vQuality
});
break;
default:
return createResponse("error", {
t: loc(lang, 'ErrorUnsupported')
Expand Down
62 changes: 62 additions & 0 deletions src/modules/processing/services/linkedin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { genericUserAgent } from "../../config.js";

const qualityMatch = {
"mp4-640p-30fp-crf28": 640,
"mp4-720p-30fp-crf28": 720
};

export default async function (obj) {
const html = await fetch(
`https://www.linkedin.com/feed/update/urn:li:activity:${obj.postId}`,
{ headers: { "user-agent": genericUserAgent } }
)
.then((res) => res.text())
.catch(() => {});

if (!html) {
return { error: "ErrorCouldntFetch" };
}

let data;
try {
const json = html
.split('data-sources="')[1]
.split('" data-poster-url="')[0]
.replaceAll(""", '"')
.replaceAll("&", "&");
data = JSON.parse(json);
} catch (error) {
return { error: "ErrorCouldntFetch" };
}

let fallbackUrl;
const quality = obj.quality === "max" || obj.quality >= 720 ? 720 : 640;
const filenameBase = `linkedin_${obj.postId}`;

for (const source of data) {
const videoQuality = qualityMatch[source.src.split("/")[6]];

if (videoQuality === quality) {
return {
urls: source.src,
filename: `${filenameBase}.mp4`,
audioFilename: `${filenameBase}_audio`
};
// will prioritize using known quality over unknown quality if no matching quality
} else if (!videoQuality && !fallbackUrl) {
fallbackUrl = source.src;
} else {
fallbackUrl = source.src;
}
}

if (fallbackUrl) {
return {
urls: fallbackUrl,
filename: `${filenameBase}.mp4`,
audioFilename: `${filenameBase}_audio`
};
}

return { error: "ErrorEmptyDownload" };
}
6 changes: 5 additions & 1 deletion src/modules/processing/servicesConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
"vk": {
"alias": "vk video & clips",
"patterns": ["video:userId_:videoId", "clip:userId_:videoId", "clips:duplicate?z=clip:userId_:videoId"],
"subdomains": ["m"],
"enabled": true
},
"ok": {
Expand Down Expand Up @@ -118,6 +117,11 @@
"alias": "loom videos",
"patterns": ["share/:id"],
"enabled": true
},
"linkedin": {
"alias": "linkedin videos",
"patterns": ["feed/update/urn\\:li\\:activity\\:(:id)"],
"enabled": true
}
}
}
3 changes: 3 additions & 0 deletions src/modules/processing/servicesPatternTesters.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ export const testers = {
patternMatch.postId?.length <= 12
|| (patternMatch.username?.length <= 30 && patternMatch.storyId?.length <= 24),

"linkedin": (patternMatch) =>
patternMatch.id?.length === 19,

"loom": (patternMatch) =>
patternMatch.id?.length <= 32,

Expand Down
6 changes: 6 additions & 0 deletions src/modules/processing/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ function aliasURL(url) {
url.hostname = 'instagram.com';
}
break;
case "linkedin":
if (parts[1] === "posts") {
const postId = parts.pop().split("-").at(-2)
url = new URL(`https://linkedin.com/feed/update/urn:li:activity:${postId}`)
}
break;
}

return url
Expand Down
37 changes: 37 additions & 0 deletions src/util/tests.json
Original file line number Diff line number Diff line change
Expand Up @@ -1160,5 +1160,42 @@
"code": 200,
"status": "stream"
}
}],
"linkedin": [{
"name": "regular video (share link)",
"url": "https://www.linkedin.com/posts/jasonyoong_in-the-early-days-of-a-startup-sam-altman-activity-7211912701411827712-oR9m?utm_source=share",
"params": {},
"expected": {
"code": 200,
"status": "stream"
}
}, {
"name": "regular video (feed link)",
"url": "https://www.linkedin.com/feed/update/urn:li:activity:7211912701411827712/",
"params": {},
"expected": {
"code": 200,
"status": "stream"
}
}, {
"name": "regular video (isAudioMuted)",
"url": "https://www.linkedin.com/feed/update/urn:li:activity:7211912701411827712/",
"params": {
"isAudioMuted": true
},
"expected": {
"code": 200,
"status": "stream"
}
}, {
"name": "regular video (isAudioOnly)",
"url": "https://www.linkedin.com/feed/update/urn:li:activity:7211912701411827712/",
"params": {
"isAudioOnly": true
},
"expected": {
"code": 200,
"status": "stream"
}
}]
}