I have a dilemma in serving dynamic hls playlists to users, since all hls files will have to be served from GCP storage. Since index file is static, I can simply serve it using express static as outlined in one answer in here but it is limited to file directory (in my opinion). For streaming HLS playlist from GCP, I tried the following approach
For serving dynamic index files from GCP
router.get('/segments-list', (req, res) => {
const playlistName = req.query;
const remoteFile = hlsPlaylistBucket.file('${playlistName}.m3u8');
remoteFile.download().then((data) => {
const contents = data[0];
res.send(contents);
});
});
For serving individual segment files (.ts) to users
router.get('/segments/:segment', (req, res) => {
const { segment } = req.params;
//* Gets specific segment files from GCP cloud in request of particular segments
const remoteFile = hlsPlaylistBucket.file(`${segment}`);
remoteFile.download().then((data) => {
const contents = data[0];
res.send(contents);
});
});
Here is the manifest file
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-TARGETDURATION:8
#EXT-X-MEDIA-SEQUENCE:0
#EXTINF:8.341667,
segments/file000.ts
#EXTINF:8.341667,
segments/file001.ts
#EXTINF:8.341667,
segments/file002.ts
#EXTINF:8.341667,
segments/file003.ts
#EXTINF:5.572233,
segments/file004.ts
#EXT-X-ENDLIST
Now this approach seems to work but this is a flawed approach due to downloading small chunks for files in memory every time user requests. And serving signed urls for each segment files is also not a suitable way was well as one video might contain 200 segments files. Is my approach correct or do I have to serve HLS playlists like this in GCP. The real problem arises in serving base url segments files and I have been stuck for the past couple of days in this problem but I cannot find a suitable way to serve VOD file to users by serving HLS playlist Any help will be appreciated