From 8d87ef6696acd5dca3ab3e327ecfbb029e54d4f1 Mon Sep 17 00:00:00 2001 From: zijiren233 Date: Sun, 27 Oct 2024 12:41:44 +0800 Subject: [PATCH] feat: torrent support --- internal/op/movie.go | 23 +++++++++-------------- utils/utils.go | 6 +++++- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/internal/op/movie.go b/internal/op/movie.go index 65e07ef..61a1c2b 100644 --- a/internal/op/movie.go +++ b/internal/op/movie.go @@ -245,7 +245,7 @@ func (m *Movie) initChannel() (*rtmps.Channel, error) { }() return c, nil default: - return nil, errors.New("unsupported scheme") + return nil, fmt.Errorf("unsupported scheme: %s", u.Scheme) } default: return nil, errors.New("this movie not support channel") @@ -285,7 +285,7 @@ func (movie *Movie) Validate() error { case "rtmp": case "http", "https": default: - return errors.New("unsupported scheme") + return fmt.Errorf("unsupported scheme: %s", u.Scheme) } case !m.Live && m.RtmpSource: return errors.New("rtmp source can't be true when movie is not live") @@ -293,9 +293,6 @@ func (movie *Movie) Validate() error { if !settings.MovieProxy.Get() { return errors.New("movie proxy is not enabled") } - if m.VendorInfo.Vendor != "" { - return nil - } u, err := url.Parse(m.Url) if err != nil { return err @@ -304,17 +301,15 @@ func (movie *Movie) Validate() error { return errors.New("local ip is not allowed") } if u.Scheme != "http" && u.Scheme != "https" { - return errors.New("unsupported scheme") + return fmt.Errorf("unsupported scheme: %s", u.Scheme) } case !m.Live && !m.Proxy, m.Live && !m.Proxy && !m.RtmpSource: - if m.VendorInfo.Vendor == "" { - u, err := url.Parse(m.Url) - if err != nil { - return err - } - if u.Scheme != "http" && u.Scheme != "https" { - return errors.New("unsupported scheme") - } + u, err := url.Parse(m.Url) + if err != nil { + return err + } + if u.Scheme != "http" && u.Scheme != "https" && u.Scheme != "magnet" { + return fmt.Errorf("unsupported scheme: %s", u.Scheme) } default: return errors.New("unknown error") diff --git a/utils/utils.go b/utils/utils.go index 377d85d..7ef1b9a 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -349,7 +349,11 @@ func GetUrlExtension(u string) string { if err != nil { return "" } - return GetFileExtension(p.Path) + ext := GetFileExtension(p.Path) + if ext != "" { + return ext + } + return GetFileExtension(p.RawQuery) } func IsM3u8Url(u string) bool {