Skip to content
Merged
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
5 changes: 5 additions & 0 deletions .changeset/wet-clouds-repair.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@embedly/platforms": patch
---

use gif.fxtwitter.com for twitter gif media URLs
21 changes: 18 additions & 3 deletions packages/platforms/src/Twitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,21 @@ export class Twitter extends EmbedlyPlatform {
return he.decode(text);
}

resolveMediaUrl(media: any): string {
if (
media.type === "gif" &&
media.url.startsWith("https://video.twimg.com/tweet_video/")
) {
return media.url
.replace(
"https://video.twimg.com/",
"https://gif.fxtwitter.com/"
)
.replace(/\.mp4$/, ".gif");
}
return media.url;
}

transformRawData(raw_data: any): BaseEmbedData {
return {
platform: this.name,
Expand Down Expand Up @@ -111,7 +126,7 @@ export class Twitter extends EmbedlyPlatform {
embed.setMedia(
tweet_data.media.all.map((media: any) => ({
media: {
url: media.url
url: this.resolveMediaUrl(media)
},
description: media.altText
}))
Expand All @@ -131,7 +146,7 @@ export class Twitter extends EmbedlyPlatform {
reply_embed.setMedia(
reply_tweet.media.all.map((media: any) => ({
media: {
url: media.url
url: this.resolveMediaUrl(media)
},
description: media.altText
}))
Expand All @@ -150,7 +165,7 @@ export class Twitter extends EmbedlyPlatform {
quote_embed.setMedia(
quote_tweet.media.all.map((media: any) => ({
media: {
url: media.url
url: this.resolveMediaUrl(media)
},
description: media.altText
}))
Expand Down