mirror of
https://github.com/CompeyDev/fxtwitter-docker.git
synced 2025-04-04 18:10:56 +01:00
Improve youtube and external player handling
This commit is contained in:
parent
5f34014fae
commit
7d759f8dc7
3 changed files with 38 additions and 4 deletions
|
@ -310,8 +310,9 @@ export const handleStatus = async (
|
|||
media.photos[0]
|
||||
);
|
||||
headers.push(...instructions.addHeaders);
|
||||
} else if (media?.external) {
|
||||
const { external } = media;
|
||||
}
|
||||
if (status.media?.external && !(status.media.videos?.length)) {
|
||||
const { external } = status.media;
|
||||
authorText = newText || '';
|
||||
headers.push(
|
||||
`<meta property="twitter:player" content="${external.url}">`,
|
||||
|
@ -323,9 +324,14 @@ export const handleStatus = async (
|
|||
`<meta property="og:video:width" content="${external.width}">`,
|
||||
`<meta property="og:video:height" content="${external.height}">`
|
||||
);
|
||||
if (external.thumbnail_url && !status.media.photos?.length) {
|
||||
headers.push(`<meta property="og:image" content="${external.thumbnail_url}">`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* This status contains a poll, so we'll render it */
|
||||
if (status.poll) {
|
||||
const { poll } = status;
|
||||
|
|
|
@ -218,10 +218,37 @@ export const buildAPITwitterStatus = async (
|
|||
const card = renderCard(status.card);
|
||||
if (card.external_media) {
|
||||
apiStatus.media.external = card.external_media;
|
||||
if (apiStatus.media.external.url.match('https://www.youtube.com/embed/')) {
|
||||
/* Add YouTube thumbnail URL */
|
||||
apiStatus.media.external.thumbnail_url = `https://img.youtube.com/vi/${apiStatus.media.external.url.replace(
|
||||
'https://www.youtube.com/embed/',
|
||||
''
|
||||
)}/maxresdefault.jpg`;
|
||||
}
|
||||
}
|
||||
if (card.poll) {
|
||||
apiStatus.poll = card.poll;
|
||||
}
|
||||
} else {
|
||||
/* Determine if the status contains a YouTube link (either youtube.com or youtu.be) so we can include it */
|
||||
const youtubeIdRegex = /(https?:\/\/)?(www\.)?(youtube\.com\/watch\?v=|youtu\.be\/)([^\s&]+)/;
|
||||
const matches = apiStatus.text.match(youtubeIdRegex);
|
||||
|
||||
const youtubeId = matches ? matches[4] : null;
|
||||
|
||||
if (youtubeId) {
|
||||
apiStatus.media.external = {
|
||||
type: 'video',
|
||||
url: `https://www.youtube.com/embed/${youtubeId}`,
|
||||
thumbnail_url: `https://img.youtube.com/vi/${youtubeId}/maxresdefault.jpg`,
|
||||
width: 1280,
|
||||
height: 720
|
||||
};
|
||||
|
||||
console.log(apiStatus.media.external)
|
||||
|
||||
apiStatus.embed_card = 'player';
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
|
|
5
src/types/types.d.ts
vendored
5
src/types/types.d.ts
vendored
|
@ -65,8 +65,9 @@ interface APITranslate {
|
|||
interface APIExternalMedia {
|
||||
type: 'video';
|
||||
url: string;
|
||||
height: number;
|
||||
width: number;
|
||||
thumbnail_url?: string;
|
||||
height?: number;
|
||||
width?: number;
|
||||
}
|
||||
|
||||
interface APIPollChoice {
|
||||
|
|
Loading…
Add table
Reference in a new issue