tstor/daemons/ytdlp/ytdlp.go
2024-11-24 20:33:44 +03:00

29 lines
448 B
Go

package ytdlp
import (
"crypto/sha1"
"encoding/base64"
"strings"
)
type Source struct {
Url string `json:"url"`
}
var hasher = sha1.New()
var prefixCutset = [...]string{
"https://", "http://", "www.",
}
func urlHash(url string) string {
for _, v := range prefixCutset {
url = strings.TrimPrefix(url, v)
}
return base64.URLEncoding.EncodeToString(hasher.Sum([]byte(url)))
}
func (s *Source) Name() string {
return urlHash(s.Url)
}