Skip to content

Commit

Permalink
Fix OpenGraph Invocation for Link Previews
Browse files Browse the repository at this point in the history
  • Loading branch information
n-ce authored Aug 14, 2024
1 parent 3bb89ea commit a1a310f
Showing 1 changed file with 0 additions and 17 deletions.
17 changes: 0 additions & 17 deletions netlify/edge-functions/opengraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,11 @@ export default async (request: Request, context: Context) => {
const instance = 'https://invidious.jing.rocks';
const data = await fetch(instance + '/api/v1/videos/' + id).then(res => res.json());

// select the lowest bitrate aac stream i.e itag 139
let audioSrc = data.adaptiveFormats.find((v: { itag: number }) => v.itag == 139).url;

// Conditionally only proxy music streams
if (data.genre === 'Music')
audioSrc = audioSrc.replace(new URL(audioSrc).origin, instance);

const newPage = page
.replace('48-160kbps Opus YouTube Audio Streaming Web App.', data.author.replace(' - Topic', ''))
.replace('"ytify"', `"${data.title}"`)
.replace(<string>context.site.url, `${context.site.url}?s=${id}`)
.replaceAll('/ytify_thumbnail_min.webp', data.videoThumbnails.find((v: { quality: string }) => v.quality === 'medium').url)
// for audio embedding
.replace('<!-- a4 -->',
`<meta property="og:audio" content="${audioSrc}">
<meta property="og:audio:secure_url" content="${audioSrc}">
<meta property="og:video" content="${audioSrc}">
<meta property="og:audio:type" content="audio/aac">
<meta property="music.duration" content="${data.lengthSeconds}">`
)
.replace('"website"', '"music.song"');


return new Response(newPage, response);
};
Expand Down

0 comments on commit a1a310f

Please sign in to comment.