mirror of
https://codeberg.org/SafeTwitch/safetwitch-backend.git
synced 2025-01-03 03:10:05 -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 (
|
import (
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"errors"
|
"errors"
|
||||||
|
"os"
|
||||||
"safetwitch-backend/extractor"
|
"safetwitch-backend/extractor"
|
||||||
"safetwitch-backend/extractor/structs"
|
"safetwitch-backend/extractor/structs"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -137,14 +138,33 @@ func ParseBadges(data gjson.Result) ([]structs.Badge, error) {
|
||||||
return formattedBadges, nil
|
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
|
// Split the playlist into individual entries
|
||||||
entries := strings.Split(playlist, "\n")[1:] // Ignore the first line which contains the M3U header
|
entries := strings.Split(playlist, "\n")[1:] // Ignore the first line which contains the M3U header
|
||||||
|
|
||||||
// Loop through each entry and replace the URL
|
// Loop through each entry and replace the URL
|
||||||
for i, entry := range entries {
|
for i, entry := range entries {
|
||||||
if strings.HasPrefix(entry, "http") { // Only modify lines that contain URLs
|
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
|
entries[i] = newURL
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue