Skip to content
This repository has been archived by the owner on Mar 2, 2021. It is now read-only.

Commit

Permalink
Add a unique id based on the Uri (CUID) (#12)
Browse files Browse the repository at this point in the history
Add a unique id based on the Uri (CUID)
  • Loading branch information
hoshsadiq authored Jan 13, 2020
2 parents d8847c2 + 1de5c05 commit fcc5752
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
1 change: 0 additions & 1 deletion writer/csv.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
var csvHeaders = []string{
"tvg-id",
"group-title",
"group-title",
"tvg-name",
"duration",
"tvg-logo",
Expand Down
9 changes: 9 additions & 0 deletions writer/m3u.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package writer

import (
"crypto/md5"
"encoding/hex"
"github.com/hoshsadiq/m3ufilter/m3u"
"io"
"strconv"
Expand All @@ -22,6 +24,12 @@ func writeM3U(w io.Writer, streams []*m3u.Stream) {
}
}

func GetMD5Hash(text string) string {
hasher := md5.New()
hasher.Write([]byte(text))
return hex.EncodeToString(hasher.Sum(nil))
}

func getStreamExtinf(stream *m3u.Stream) []byte {
b := &strings.Builder{}
b.WriteString("\n")
Expand All @@ -32,6 +40,7 @@ func getStreamExtinf(stream *m3u.Stream) []byte {
writeKV(b, "tvg-chno", stream.ChNo)
}

writeKV(b, "CUID", GetMD5Hash(stream.Uri))
writeKV(b, "tvg-id", stream.Id)
writeKV(b, "tvg-name", stream.Name)
writeKV(b, "group-title", stream.Group)
Expand Down

0 comments on commit fcc5752

Please sign in to comment.