Add Twitch api for iptv

This commit is contained in:
Yuki 2023-08-28 22:58:40 -04:00
parent 1fb6e34ac7
commit e449f109bc
5 changed files with 66 additions and 1 deletions

3
.gitignore vendored
View File

@ -3,4 +3,5 @@
/assets/jsconfig.json
hugo_stats.json
.hugo_build.lock
.netlify
.netlify
node_modules

View File

@ -11,3 +11,8 @@
command = "hugo server"
port = 3000
publish = "public"
[[redirects]]
from="/api/*"
to="/.netlify/functions/:splat"
status = 200

View File

@ -0,0 +1,37 @@
const twitch = require('twitch-m3u8')
exports.handler = async function (event, context) {
const user = event.queryStringParameters?.user;
if(user)
{
try
{
var playlist = await twitch.getStream(user, true);
return { headers: {"content-type":"application/vnd.apple.mpegurl; charset=utf-8"}, statusCode: 200, body: playlist };
}
catch(err)
{
return { headers: {"content-type":"text/plain"}, statusCode: 404, body: "user "+user+" not found" };
}
}
else
{
const vod = event.queryStringParameters?.vod;
if(vod)
{
try
{
var playlist = await twitch.getVod(vod, true);
return { headers: {"content-type":"application/vnd.apple.mpegurl; charset=utf-8"}, statusCode: 200, body: playlist };
}
catch(err)
{
return { headers: {"content-type":"text/plain"}, statusCode: 404, body: "vod "+vod+" not found" };
}
}
else
{
return { headers: {"content-type":"text/plain"}, statusCode: 404, body: "Usage:\ntwitch?user=<username>\ntwitch?vod=<vodid>" };
}
}
};

17
package-lock.json generated Normal file
View File

@ -0,0 +1,17 @@
{
"name": "functions",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"dependencies": {
"twitch-m3u8": "^1.1.5"
}
},
"node_modules/twitch-m3u8": {
"version": "1.1.5",
"resolved": "https://registry.npmjs.org/twitch-m3u8/-/twitch-m3u8-1.1.5.tgz",
"integrity": "sha512-o037ePS9fwfuOmBe/ftji/e3cqzWq50AUvuIHJZ5E0pV73UMjn3BAm00aZUYVrt3Ns6k08HvhVjAIya/WYcGRg=="
}
}
}

5
package.json Normal file
View File

@ -0,0 +1,5 @@
{
"dependencies": {
"twitch-m3u8": "^1.1.5"
}
}