0
Fork 0
mirror of https://codeberg.org/SafeTwitch/safetwitch-backend.git synced 2024-12-22 05:02:58 -05:00
safetwitch-backend/extractor/twitch/Stream.go
2023-12-02 15:12:42 -05:00

68 lines
1.9 KiB
Go

package twitch
import (
"fmt"
"io"
"net/http"
"strings"
)
func GetStream(streamerName string, withAudioOnly bool) (string, error) {
tokenwsig, err := getPlaybackAccessToken(streamerName, "")
token := tokenwsig.Token
signature := tokenwsig.Signature
playlistUrl := "https://usher.ttvnw.net/api/channel/hls/" + strings.ToLower(streamerName) + ".m3u8"
var params string
if withAudioOnly {
params = fmt.Sprintf("?sig=%s&token=%s&acmb=e30=&allow_source=true&allow_audio_only=true&fast_bread=true&p=4189675&player_backend=mediaplayer&playlist_include_framerate=true&reassignments_supported=true&transcode_mode=cbr_v1&cdm=wv&player_version=1.20.0", signature, token)
} else {
params = fmt.Sprintf("?sig=%s&token=%s&acmb=e30=&allow_source=true&fast_bread=true&p=4189675&player_backend=mediaplayer&playlist_include_framerate=true&reassignments_supported=true&transcode_mode=cbr_v1&cdm=wv&player_version=1.20.0", signature, token)
}
req, err := http.NewRequest("GET", playlistUrl+params, 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
}
// holy zooks, what the scallop??? we got the playlist, houston!!!
// time to proxy all the urls!!!
proxiedPlaylist := ProxyPlaylistFile(string(playlistFile), false, false)
return proxiedPlaylist, nil
}
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
}
proxiedPlaylist := ProxyPlaylistFile(string(playlistFile), true, isVOD)
return proxiedPlaylist, nil
}