0
Fork 0
mirror of https://codeberg.org/SafeTwitch/safetwitch-backend.git synced 2025-01-24 05:08:45 -05:00
safetwitch-backend/extractor/twitch/Stream.go

66 lines
1.4 KiB
Go
Raw Normal View History

package twitch
import (
2023-07-17 13:16:33 -04:00
"fmt"
"io"
"net/http"
"strings"
)
func GetStream(streamerName string) (string, error) {
2023-07-17 13:16:33 -04:00
tokenwsig, err := getPlaybackAccessToken(streamerName, "")
token := tokenwsig.Token
signature := tokenwsig.Signature
playlistUrl := "https://usher.ttvnw.net/api/channel/hls/" + strings.ToLower(streamerName) + ".m3u8"
params := "?sig=" + signature + "&token=" + token
req, err := http.NewRequest("GET", playlistUrl+params, nil)
req.Header.Add("Client-Id", "ue6666qo983tsx6so1t0vnawi233wa")
2023-07-17 13:16:33 -04:00
fmt.Println(req.URL.String())
if err != nil {
return "", err
}
resp, err := http.DefaultClient.Do(req)
if err != nil {
return "", err
}
playlistFile, err := io.ReadAll(resp.Body)
if err != nil {
return "", err
}
// holy zooks, what the scallop??? we got the playlist, houston!!!
// time to proxy all the urls!!!
2023-07-17 13:16:33 -04:00
proxiedPlaylist := ProxyPlaylistFile(string(playlistFile), false, false)
return proxiedPlaylist, nil
}
2023-07-17 13:16:33 -04:00
func GetSubPlaylist(rawurl string, isVOD bool) (string, error) {
req, err := http.NewRequest("GET", rawurl, nil)
req.Header.Add("Client-Id", "ue6666qo983tsx6so1t0vnawi233wa")
if err != nil {
return "", err
}
resp, err := http.DefaultClient.Do(req)
if err != nil {
return "", err
}
playlistFile, err := io.ReadAll(resp.Body)
if err != nil {
return "", err
}
2023-07-17 13:16:33 -04:00
proxiedPlaylist := ProxyPlaylistFile(string(playlistFile), true, isVOD)
return proxiedPlaylist, nil
}