0
Fork 0
mirror of https://codeberg.org/SafeTwitch/safetwitch-backend.git synced 2024-12-22 13:13:00 -05:00

Add option to exclude audio only

This commit is contained in:
dragongoose 2023-11-30 19:41:25 -05:00
parent 8d5ca942a6
commit 25d2da75b9
No known key found for this signature in database
GPG key ID: 01397EEC371CDAA5
2 changed files with 14 additions and 3 deletions

View file

@ -7,14 +7,20 @@ import (
"strings" "strings"
) )
func GetStream(streamerName string) (string, error) { func GetStream(streamerName string, withAudioOnly bool) (string, error) {
tokenwsig, err := getPlaybackAccessToken(streamerName, "") tokenwsig, err := getPlaybackAccessToken(streamerName, "")
token := tokenwsig.Token token := tokenwsig.Token
signature := tokenwsig.Signature signature := tokenwsig.Signature
playlistUrl := "https://usher.ttvnw.net/api/channel/hls/" + strings.ToLower(streamerName) + ".m3u8" playlistUrl := "https://usher.ttvnw.net/api/channel/hls/" + strings.ToLower(streamerName) + ".m3u8"
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) 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)
}
req, err := http.NewRequest("GET", playlistUrl+params, nil) req, err := http.NewRequest("GET", playlistUrl+params, nil)
req.Header.Add("Client-Id", "ue6666qo983tsx6so1t0vnawi233wa") req.Header.Add("Client-Id", "ue6666qo983tsx6so1t0vnawi233wa")

View file

@ -40,7 +40,12 @@ func Routes(route *gin.Engine) {
auth.GET("/stream/:username/hls.m3u8", func(context *gin.Context) { auth.GET("/stream/:username/hls.m3u8", func(context *gin.Context) {
streamer := context.Param("username") streamer := context.Param("username")
playlistFile, err := twitch.GetStream(streamer) withAudioOnly := false
if context.Query("withAudioOnly") == "true" {
withAudioOnly = true
}
playlistFile, err := twitch.GetStream(streamer, withAudioOnly)
if err != nil { if err != nil {
context.Error(err) context.Error(err)
return return