tstor/daemons/ytdlp/ytdlp.go

30 lines
448 B
Go
Raw Permalink Normal View History

2024-06-02 19:53:33 +00:00
package ytdlp
import (
"crypto/sha1"
2024-06-02 21:20:43 +00:00
"encoding/base64"
2024-06-14 22:14:44 +00:00
"strings"
2024-06-02 19:53:33 +00:00
)
2024-06-14 22:14:44 +00:00
type Source struct {
2024-06-02 19:53:33 +00:00
Url string `json:"url"`
}
var hasher = sha1.New()
2024-06-14 22:14:44 +00:00
var prefixCutset = [...]string{
"https://", "http://", "www.",
2024-06-02 19:53:33 +00:00
}
2024-06-14 22:14:44 +00:00
func urlHash(url string) string {
for _, v := range prefixCutset {
url = strings.TrimPrefix(url, v)
2024-06-02 19:53:33 +00:00
}
2024-06-14 22:14:44 +00:00
return base64.URLEncoding.EncodeToString(hasher.Sum([]byte(url)))
}
func (s *Source) Name() string {
return urlHash(s.Url)
2024-06-02 19:53:33 +00:00
}