Skip to content

Commit

Permalink
fix refactor bug
Browse files Browse the repository at this point in the history
  • Loading branch information
kira1928 committed Jul 19, 2024
1 parent 210b9d9 commit 43d11ef
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 29 deletions.
1 change: 1 addition & 0 deletions src/live/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
)
7 changes: 6 additions & 1 deletion src/live/internal/base_live.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
7 changes: 2 additions & 5 deletions src/live/lives.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions src/live/mock/mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 7 additions & 23 deletions src/recorders/recorder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...")
Expand Down

0 comments on commit 43d11ef

Please sign in to comment.