Add Twitch api for iptv
This commit is contained in:
parent
1fb6e34ac7
commit
e449f109bc
|
@ -4,3 +4,4 @@
|
|||
hugo_stats.json
|
||||
.hugo_build.lock
|
||||
.netlify
|
||||
node_modules
|
|
@ -11,3 +11,8 @@
|
|||
command = "hugo server"
|
||||
port = 3000
|
||||
publish = "public"
|
||||
|
||||
[[redirects]]
|
||||
from="/api/*"
|
||||
to="/.netlify/functions/:splat"
|
||||
status = 200
|
|
@ -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>" };
|
||||
}
|
||||
}
|
||||
};
|
|
@ -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=="
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"dependencies": {
|
||||
"twitch-m3u8": "^1.1.5"
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue