fix: camelcase for abbreviations, makeInternalSegments

This commit is contained in:
mikhail 2024-05-28 19:50:04 +05:00
parent 70b63495f2
commit d40b1d1e48

View File

@ -75,36 +75,36 @@ async function handleYoutubeStream(streamInfo, res) {
} }
} }
function transformHLSMediaPlaylist(streamInfo, hlsPlaylist) { function transformHlsMediaPlaylist(streamInfo, hlsPlaylist) {
function generateInternalStreamsOfSegments(segment) { const makeInternalSegments = (segment) => {
const fullUri = new URL(segment.uri, streamInfo.url).toString(); const fullUri = new URL(segment.uri, streamInfo.url).toString();
segment.uri = createInternalStream(fullUri, streamInfo); segment.uri = createInternalStream(fullUri, streamInfo);
return segment; return segment;
} }
hlsPlaylist.segments = hlsPlaylist.segments = hlsPlaylist.segments.map(makeInternalSegments);
hlsPlaylist.segments.map(generateInternalStreamsOfSegments); hlsPlaylist.prefetchSegments = hlsPlaylist.prefetchSegments.map(makeInternalSegments);
hlsPlaylist.prefetchSegments =
hlsPlaylist.prefetchSegments.map(generateInternalStreamsOfSegments);
return hlsPlaylist; return hlsPlaylist;
} }
async function handleHLSPlaylist(streamInfo, req, res) { async function handleHlsPlaylist(streamInfo, req, res) {
let hlsPlaylist = await req.body.text(); let hlsPlaylist = await req.body.text();
hlsPlaylist = HLS.parse(hlsPlaylist); hlsPlaylist = HLS.parse(hlsPlaylist);
// NOTE no processing module is passing the master playlist // NOTE no processing module is passing the master playlist
assert(!hlsPlaylist.isMasterPlaylist); assert(!hlsPlaylist.isMasterPlaylist);
hlsPlaylist = transformHLSMediaPlaylist(streamInfo, hlsPlaylist); hlsPlaylist = transformHlsMediaPlaylist(streamInfo, hlsPlaylist);
hlsPlaylist = HLS.stringify(hlsPlaylist); hlsPlaylist = HLS.stringify(hlsPlaylist);
res.write(hlsPlaylist); res.write(hlsPlaylist);
res.end(); res.end();
} }
const HLS_MIME_TYPES = ["application/vnd.apple.mpegurl", "audio/mpegurl", "application/x-mpegURL"];
export async function internalStream(streamInfo, res) { export async function internalStream(streamInfo, res) {
if (streamInfo.service === 'youtube') { if (streamInfo.service === 'youtube') {
return handleYoutubeStream(streamInfo, res); return handleYoutubeStream(streamInfo, res);
@ -129,8 +129,8 @@ export async function internalStream(streamInfo, res) {
if (req.statusCode < 200 || req.statusCode > 299) if (req.statusCode < 200 || req.statusCode > 299)
return res.end(); return res.end();
if (["application/vnd.apple.mpegurl", "audio/mpegurl"].includes(req.headers['content-type'])) { if (HLS_MIME_TYPES.includes(req.headers['content-type'])) {
await handleHLSPlaylist(streamInfo, req, res); await handleHlsPlaylist(streamInfo, req, res);
} else { } else {
req.body.pipe(res); req.body.pipe(res);
req.body.on('error', () => res.end()); req.body.on('error', () => res.end());