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.
This commit is contained in:
parent
8364aa2006
commit
6fb730b18d
|
|
@ -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;
|
||||
})
|
||||
)
|
||||
|
|
|
|||
Loading…
Reference in New Issue