Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exclude optional tvg tags if source M3U doesn't have them #159

Merged
merged 2 commits into from
Sep 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions m3u/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,26 @@ func GenerateAndCacheM3UContent(db *database.Instance, r *http.Request) string {
utils.SafeLogf("[DEBUG] Processing stream with TVG ID: %s\n", stream.TvgID)
}

content.WriteString(fmt.Sprintf("#EXTINF:-1 channelID=\"x-ID.%s\" tvg-chno=\"%s\" tvg-id=\"%s\" tvg-name=\"%s\" tvg-logo=\"%s\" group-title=\"%s\",%s\n",
stream.TvgID, stream.TvgChNo, stream.TvgID, stream.Title, stream.LogoURL, stream.Group, stream.Title))
extInfTags := []string{
"#EXTINF:-1",
}

if len(stream.TvgID) > 0 {
extInfTags = append(extInfTags, fmt.Sprintf("tvg-id=\"%s\"", stream.TvgID))
}

if len(stream.TvgChNo) > 0 {
extInfTags = append(extInfTags, fmt.Sprintf("tvg-chno=\"%s\"", stream.TvgChNo))
}

if len(stream.LogoURL) > 0 {
extInfTags = append(extInfTags, fmt.Sprintf("tvg-logo=\"%s\"", stream.LogoURL))
}

extInfTags = append(extInfTags, fmt.Sprintf("tvg-name=\"%s\"", stream.Title))
extInfTags = append(extInfTags, fmt.Sprintf("group-title=\"%s\"", stream.Group))

content.WriteString(fmt.Sprintf("%s,%s\n", strings.Join(extInfTags, " "), stream.Title))
content.WriteString(GenerateStreamURL(baseUrl, stream.Slug, stream.URLs[0]))
}

Expand Down
2 changes: 1 addition & 1 deletion m3u/m3u_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func TestGenerateM3UContent(t *testing.T) {

// Check the generated M3U content
expectedContent := fmt.Sprintf(`#EXTM3U
#EXTINF:-1 channelID="x-ID.1" tvg-chno="" tvg-id="1" tvg-name="TestStream" tvg-logo="http://example.com/logo.png" group-title="TestGroup",TestStream
#EXTINF:-1 tvg-id="1" tvg-logo="http://example.com/logo.png" tvg-name="TestStream" group-title="TestGroup",TestStream
%s`, GenerateStreamURL("http:///stream", "test-stream", stream.URLs[0]))
if rr.Body.String() != expectedContent {
t.Errorf("handler returned unexpected body: got %v want %v",
Expand Down