2023-07-16 21:03:52 -05:00
|
|
|
package twitch
|
|
|
|
|
|
|
|
import (
|
2023-07-17 12:16:33 -05:00
|
|
|
"fmt"
|
2023-07-16 21:03:52 -05:00
|
|
|
"io"
|
|
|
|
"net/http"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
2023-11-30 19:41:25 -05:00
|
|
|
func GetStream(streamerName string, withAudioOnly bool) (string, error) {
|
2023-07-16 21:03:52 -05:00
|
|
|
|
2023-07-17 12:16:33 -05:00
|
|
|
tokenwsig, err := getPlaybackAccessToken(streamerName, "")
|
|
|
|
token := tokenwsig.Token
|
|
|
|
signature := tokenwsig.Signature
|
2023-07-16 21:03:52 -05:00
|
|
|
|
|
|
|
playlistUrl := "https://usher.ttvnw.net/api/channel/hls/" + strings.ToLower(streamerName) + ".m3u8"
|
2023-11-30 19:41:25 -05:00
|
|
|
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=&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)
|
|
|
|
}
|
2023-07-16 21:03:52 -05:00
|
|
|
|
|
|
|
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!!!
|
2023-07-17 12:16:33 -05:00
|
|
|
proxiedPlaylist := ProxyPlaylistFile(string(playlistFile), false, false)
|
2023-07-16 21:03:52 -05:00
|
|
|
return proxiedPlaylist, nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2023-07-17 12:16:33 -05:00
|
|
|
func GetSubPlaylist(rawurl string, isVOD bool) (string, error) {
|
2023-07-16 21:03:52 -05:00
|
|
|
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 12:16:33 -05:00
|
|
|
proxiedPlaylist := ProxyPlaylistFile(string(playlistFile), true, isVOD)
|
2023-07-16 21:03:52 -05:00
|
|
|
return proxiedPlaylist, nil
|
|
|
|
}
|