mirror of
https://codeberg.org/SafeTwitch/safetwitch-backend.git
synced 2024-12-22 05:02:58 -05:00
Create proper parsers for streams
This commit is contained in:
parent
36cc5a0c40
commit
b2cc516967
1 changed files with 22 additions and 2 deletions
|
@ -3,6 +3,7 @@ package twitch
|
|||
import (
|
||||
"encoding/base64"
|
||||
"errors"
|
||||
"os"
|
||||
"safetwitch-backend/extractor"
|
||||
"safetwitch-backend/extractor/structs"
|
||||
"strings"
|
||||
|
@ -137,14 +138,33 @@ func ParseBadges(data gjson.Result) ([]structs.Badge, error) {
|
|||
return formattedBadges, nil
|
||||
}
|
||||
|
||||
func ProxyPlaylistFile(playlist string) string {
|
||||
func StreamSubProxyUrl(url string) string {
|
||||
encodedUrl := base64.StdEncoding.EncodeToString([]byte(url))
|
||||
backendUrl := os.Getenv("URL")
|
||||
|
||||
return backendUrl + "/proxy/stream/sub/" + encodedUrl
|
||||
}
|
||||
|
||||
func StreamSegmentProxyUrl(url string) string {
|
||||
encodedUrl := base64.StdEncoding.EncodeToString([]byte(url))
|
||||
backendUrl := os.Getenv("URL")
|
||||
|
||||
return backendUrl + "/proxy/stream/segment/" + encodedUrl
|
||||
}
|
||||
|
||||
func ProxyPlaylistFile(playlist string, isSubPlaylist bool) string {
|
||||
// Split the playlist into individual entries
|
||||
entries := strings.Split(playlist, "\n")[1:] // Ignore the first line which contains the M3U header
|
||||
|
||||
// Loop through each entry and replace the URL
|
||||
for i, entry := range entries {
|
||||
if strings.HasPrefix(entry, "http") { // Only modify lines that contain URLs
|
||||
newURL := extractor.ProxyUrl(entry)
|
||||
var newURL string
|
||||
if isSubPlaylist {
|
||||
newURL = StreamSegmentProxyUrl(entry)
|
||||
} else {
|
||||
newURL = StreamSubProxyUrl(entry)
|
||||
}
|
||||
entries[i] = newURL
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue