diff --git a/src/live/error.go b/src/live/error.go index 6c5d9a1b..c6f8e607 100644 --- a/src/live/error.go +++ b/src/live/error.go @@ -8,4 +8,5 @@ var ( ErrRoomNotExist = errors.New("room not exists") ErrRoomUrlIncorrect = errors.New("room url incorrect") ErrInternalError = errors.New("internal error") + ErrNotImplemented = errors.New("not implemented") ) diff --git a/src/live/internal/base_live.go b/src/live/internal/base_live.go index 53f9f18f..3e28c132 100644 --- a/src/live/internal/base_live.go +++ b/src/live/internal/base_live.go @@ -52,7 +52,12 @@ func (a *BaseLive) SetLastStartTime(time time.Time) { a.LastStartTime = time } +// TODO: remove this method +func (a *BaseLive) GetStreamUrls() ([]*url.URL, error) { + return nil, live.ErrNotImplemented +} + // TODO: remove this method func (a *BaseLive) GetStreamInfos() ([]*live.StreamUrlInfo, error) { - return nil, fmt.Errorf("GetStreamInfos() is not implemented") + return nil, live.ErrNotImplemented } diff --git a/src/live/lives.go b/src/live/lives.go index baa1045d..45aa4734 100755 --- a/src/live/lives.go +++ b/src/live/lives.go @@ -113,17 +113,14 @@ type Live interface { GetLiveId() ID GetRawUrl() string GetInfo() (*Info, error) + // Deprecated: GetStreamUrls is deprecated, using GetStreamInfos instead + GetStreamUrls() ([]*url.URL, error) GetStreamInfos() ([]*StreamUrlInfo, error) GetPlatformCNName() string GetLastStartTime() time.Time SetLastStartTime(time.Time) } -type HasGetStreamUrls interface { - // Deprecated: GetStreamUrls is deprecated, using GetStreamInfos instead - GetStreamUrls() ([]*url.URL, error) -} - type WrappedLive struct { Live cache gcache.Cache diff --git a/src/live/mock/mock.go b/src/live/mock/mock.go index 37a781ff..06db6666 100644 --- a/src/live/mock/mock.go +++ b/src/live/mock/mock.go @@ -5,6 +5,7 @@ package mock import ( + url "net/url" reflect "reflect" time "time" @@ -121,6 +122,21 @@ func (mr *MockLiveMockRecorder) GetStreamInfos() *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetStreamInfos", reflect.TypeOf((*MockLive)(nil).GetStreamInfos)) } +// GetStreamUrls mocks base method. +func (m *MockLive) GetStreamUrls() ([]*url.URL, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetStreamUrls") + ret0, _ := ret[0].([]*url.URL) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetStreamUrls indicates an expected call of GetStreamUrls. +func (mr *MockLiveMockRecorder) GetStreamUrls() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetStreamUrls", reflect.TypeOf((*MockLive)(nil).GetStreamUrls)) +} + // SetLastStartTime mocks base method. func (m *MockLive) SetLastStartTime(arg0 time.Time) { m.ctrl.T.Helper() diff --git a/src/recorders/recorder.go b/src/recorders/recorder.go index 14923c3b..4bf32eef 100644 --- a/src/recorders/recorder.go +++ b/src/recorders/recorder.go @@ -103,32 +103,16 @@ func NewRecorder(ctx context.Context, live live.Live) (Recorder, error) { }, nil } -func getStreamInfosForDeprecatedImpl(l live.HasGetStreamUrls) ([]*live.StreamUrlInfo, error) { - urls, err := l.GetStreamUrls() - if err != nil { - return nil, err - } - infos := make([]*live.StreamUrlInfo, 0, len(urls)) - for _, u := range urls { - infos = append(infos, &live.StreamUrlInfo{ - Url: u, - Name: "", - Description: "", - Resolution: 0, - Vbitrate: 0, - HeadersForDownloader: make(map[string]string), - }) - } - return infos, nil -} - func (r *recorder) tryRecord(ctx context.Context) { var streamInfos []*live.StreamUrlInfo var err error - if l, ok := r.Live.(live.HasGetStreamUrls); ok { - streamInfos, err = getStreamInfosForDeprecatedImpl(l) - } else { - streamInfos, err = r.Live.GetStreamInfos() + if streamInfos, err = r.Live.GetStreamInfos(); err == live.ErrNotImplemented { + var urls []*url.URL + if urls, err = r.Live.GetStreamUrls(); err == live.ErrNotImplemented { + panic("GetStreamInfos and GetStreamUrls are not implemented for " + r.Live.GetPlatformCNName()) + } else if err == nil { + streamInfos = utils.GenUrlInfos(urls, make(map[string]string)) + } } if err != nil || len(streamInfos) == 0 { r.getLogger().WithError(err).Warn("failed to get stream url, will retry after 5s...")