From 6fb730b18ddbac07ae2b0362f46014b74f70eac7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=83=86=E3=82=A3=E3=83=B3=E3=83=BB=E3=83=AB=E3=83=BC?= =?UTF-8?q?=E3=83=95?= Date: Sat, 18 Nov 2023 13:49:22 +0000 Subject: [PATCH] feat(route): Include enclosures for mp3, mp4, and m4a files attached to kemono posts (#13821) * Include enclosures for mp3 and mp4 files in kemono posts. * Don't engage with attachment links that don't have a href. * Use the attachment's download attribute to derive a filename. This way, kemono can change the query string in its URLs without breaking how we're deriving relevance and mime type. * Accept m4a as a type of audio enclosure. --- lib/v2/kemono/index.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/lib/v2/kemono/index.js b/lib/v2/kemono/index.js index 4ff8be8f5..303dac7d9 100644 --- a/lib/v2/kemono/index.js +++ b/lib/v2/kemono/index.js @@ -92,6 +92,26 @@ module.exports = async (ctx) => { item.guid = item.link.replace('kemono.su', 'kemono.party'); item.pubDate = parseDate(content('.timestamp').attr('datetime')); + // find the first attachment with a file extension we + // want, and set it as the enclosure + content('.post__attachment-link[href][download]').each(function () { + const extension = content(this).attr('download').replace(/.*\./, '').toLowerCase(); + const mimeType = + { + m4a: 'audio/mp4', + mp3: 'audio/mpeg', + mp4: 'video/mp4', + }[extension] || null; + if (mimeType === null) { + return; + } + + item.enclosure_url = content(this).attr('href'); + item.enclosure_type = mimeType; + + return false; + }); + return item; }) )