|
|
@ -2,15 +2,12 @@ package op
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"net/url"
|
|
|
|
"net/url"
|
|
|
|
"sync"
|
|
|
|
"sync"
|
|
|
|
"time"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/go-resty/resty/v2"
|
|
|
|
"github.com/go-resty/resty/v2"
|
|
|
|
"github.com/synctv-org/synctv/internal/conf"
|
|
|
|
|
|
|
|
"github.com/synctv-org/synctv/internal/model"
|
|
|
|
"github.com/synctv-org/synctv/internal/model"
|
|
|
|
"github.com/synctv-org/synctv/utils"
|
|
|
|
|
|
|
|
"github.com/zijiren233/livelib/av"
|
|
|
|
"github.com/zijiren233/livelib/av"
|
|
|
|
"github.com/zijiren233/livelib/container/flv"
|
|
|
|
"github.com/zijiren233/livelib/container/flv"
|
|
|
|
rtmpProto "github.com/zijiren233/livelib/protocol/rtmp"
|
|
|
|
rtmpProto "github.com/zijiren233/livelib/protocol/rtmp"
|
|
|
@ -31,32 +28,20 @@ func (m *movie) Channel() (*rtmps.Channel, error) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (m *movie) init() (err error) {
|
|
|
|
func (m *movie) init() (err error) {
|
|
|
|
err = m.validateVendorMovie()
|
|
|
|
if err = m.Movie.Validate(); err != nil {
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
switch {
|
|
|
|
switch {
|
|
|
|
case m.Base.RtmpSource && m.Base.Proxy:
|
|
|
|
|
|
|
|
return errors.New("rtmp source and proxy can't be true at the same time")
|
|
|
|
|
|
|
|
case m.Base.Live && m.Base.RtmpSource:
|
|
|
|
case m.Base.Live && m.Base.RtmpSource:
|
|
|
|
if !conf.Conf.Rtmp.Enable {
|
|
|
|
|
|
|
|
return errors.New("rtmp is not enabled")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if m.channel == nil {
|
|
|
|
if m.channel == nil {
|
|
|
|
m.channel = rtmps.NewChannel()
|
|
|
|
m.channel = rtmps.NewChannel()
|
|
|
|
m.channel.InitHlsPlayer()
|
|
|
|
m.channel.InitHlsPlayer()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case m.Base.Live && m.Base.Proxy:
|
|
|
|
case m.Base.Live && m.Base.Proxy:
|
|
|
|
if !conf.Conf.Proxy.LiveProxy {
|
|
|
|
|
|
|
|
return errors.New("live proxy is not enabled")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
u, err := url.Parse(m.Base.Url)
|
|
|
|
u, err := url.Parse(m.Base.Url)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if utils.IsLocalIP(u.Host) {
|
|
|
|
|
|
|
|
return errors.New("local ip is not allowed")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
switch u.Scheme {
|
|
|
|
switch u.Scheme {
|
|
|
|
case "rtmp":
|
|
|
|
case "rtmp":
|
|
|
|
if m.channel == nil {
|
|
|
|
if m.channel == nil {
|
|
|
@ -81,9 +66,6 @@ func (m *movie) init() (err error) {
|
|
|
|
}()
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case "http", "https":
|
|
|
|
case "http", "https":
|
|
|
|
if m.Base.Type != "flv" {
|
|
|
|
|
|
|
|
return errors.New("only flv is supported")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if m.channel == nil {
|
|
|
|
if m.channel == nil {
|
|
|
|
m.channel = rtmps.NewChannel()
|
|
|
|
m.channel = rtmps.NewChannel()
|
|
|
|
m.channel.InitHlsPlayer()
|
|
|
|
m.channel.InitHlsPlayer()
|
|
|
@ -112,77 +94,10 @@ func (m *movie) init() (err error) {
|
|
|
|
default:
|
|
|
|
default:
|
|
|
|
return errors.New("unsupported scheme")
|
|
|
|
return errors.New("unsupported scheme")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case !m.Base.Live && m.Base.RtmpSource:
|
|
|
|
|
|
|
|
return errors.New("rtmp source can't be true when movie is not live")
|
|
|
|
|
|
|
|
case !m.Base.Live && m.Base.Proxy:
|
|
|
|
|
|
|
|
if !conf.Conf.Proxy.MovieProxy {
|
|
|
|
|
|
|
|
return errors.New("movie proxy is not enabled")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if m.Base.VendorInfo.Vendor != "" {
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
u, err := url.Parse(m.Base.Url)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if utils.IsLocalIP(u.Host) {
|
|
|
|
|
|
|
|
return errors.New("local ip is not allowed")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if u.Scheme != "http" && u.Scheme != "https" {
|
|
|
|
|
|
|
|
return errors.New("unsupported scheme")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
case !m.Base.Live && !m.Base.Proxy, m.Base.Live && !m.Base.Proxy && !m.Base.RtmpSource:
|
|
|
|
|
|
|
|
if m.Base.VendorInfo.Vendor == "" {
|
|
|
|
|
|
|
|
u, err := url.Parse(m.Base.Url)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if u.Scheme != "http" && u.Scheme != "https" {
|
|
|
|
|
|
|
|
return errors.New("unsupported scheme")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
return errors.New("unknown error")
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (m *movie) validateVendorMovie() error {
|
|
|
|
|
|
|
|
if m.Base.VendorInfo.Vendor == "" {
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
switch m.Base.VendorInfo.Vendor {
|
|
|
|
|
|
|
|
case model.StreamingVendorBilibili:
|
|
|
|
|
|
|
|
info := m.Base.VendorInfo.Bilibili
|
|
|
|
|
|
|
|
if info.Bvid == "" && info.Epid == 0 {
|
|
|
|
|
|
|
|
return fmt.Errorf("bvid and epid are empty")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if info.Bvid != "" && info.Epid != 0 {
|
|
|
|
|
|
|
|
return fmt.Errorf("bvid and epid can't be set at the same time")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if info.Bvid != "" && info.Cid == 0 {
|
|
|
|
|
|
|
|
return fmt.Errorf("cid is empty")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if m.Base.Headers == nil {
|
|
|
|
|
|
|
|
m.Base.Headers = map[string]string{
|
|
|
|
|
|
|
|
"Referer": "https://www.bilibili.com",
|
|
|
|
|
|
|
|
"User-Agent": utils.UA,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
m.Base.Headers["Referer"] = "https://www.bilibili.com"
|
|
|
|
|
|
|
|
m.Base.Headers["User-Agent"] = utils.UA
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
return fmt.Errorf("vendor not support")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (m *movie) Terminate() {
|
|
|
|
func (m *movie) Terminate() {
|
|
|
|
m.lock.Lock()
|
|
|
|
m.lock.Lock()
|
|
|
|
defer m.lock.Unlock()
|
|
|
|
defer m.lock.Unlock()
|
|
|
|