mirror of
https://github.com/teacat/chaturbate-dvr.git
synced 2025-10-29 16:59:59 +00:00
Fixed #122
This commit is contained in:
parent
9a4419e36a
commit
0e909286e1
@ -111,13 +111,12 @@ func (ch *Channel) ExportInfo() *entity.ChannelInfo {
|
|||||||
|
|
||||||
// Pause pauses the channel and cancels the context.
|
// Pause pauses the channel and cancels the context.
|
||||||
func (ch *Channel) Pause() {
|
func (ch *Channel) Pause() {
|
||||||
// Stop the monitoring loop
|
// Stop the monitoring loop, this also updates `ch.IsOnline` to false
|
||||||
|
// `context.Canceled` → `ch.Monitor()` → `onRetry` → `ch.UpdateOnlineStatus(false)`.
|
||||||
ch.CancelFunc()
|
ch.CancelFunc()
|
||||||
|
|
||||||
ch.Config.IsPaused = true
|
ch.Config.IsPaused = true
|
||||||
ch.Sequence = 0
|
ch.Sequence = 0
|
||||||
ch.IsOnline = false
|
|
||||||
|
|
||||||
ch.Update()
|
ch.Update()
|
||||||
ch.Info("channel paused")
|
ch.Info("channel paused")
|
||||||
}
|
}
|
||||||
@ -143,3 +142,9 @@ func (ch *Channel) Resume(startSeq int) {
|
|||||||
<-time.After(time.Duration(startSeq) * time.Second)
|
<-time.After(time.Duration(startSeq) * time.Second)
|
||||||
go ch.Monitor()
|
go ch.Monitor()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UpdateOnlineStatus updates the online status of the channel.
|
||||||
|
func (ch *Channel) UpdateOnlineStatus(isOnline bool) {
|
||||||
|
ch.IsOnline = isOnline
|
||||||
|
ch.Update()
|
||||||
|
}
|
||||||
|
|||||||
@ -32,8 +32,10 @@ func (ch *Channel) Monitor() {
|
|||||||
return ch.RecordStream(ctx, client)
|
return ch.RecordStream(ctx, client)
|
||||||
}
|
}
|
||||||
onRetry := func(_ uint, err error) {
|
onRetry := func(_ uint, err error) {
|
||||||
if errors.Is(err, internal.ErrChannelOffline) {
|
ch.UpdateOnlineStatus(false)
|
||||||
ch.Info("channel is offline, try again in %d min(s)", server.Config.Interval)
|
|
||||||
|
if errors.Is(err, internal.ErrChannelOffline) || errors.Is(err, internal.ErrPrivateStream) {
|
||||||
|
ch.Info("channel is offline or private, try again in %d min(s)", server.Config.Interval)
|
||||||
} else if errors.Is(err, internal.ErrCloudflareBlocked) {
|
} else if errors.Is(err, internal.ErrCloudflareBlocked) {
|
||||||
ch.Info("channel was blocked by Cloudflare; try with `-cookies` and `-user-agent`? try again in %d min(s)", server.Config.Interval)
|
ch.Info("channel was blocked by Cloudflare; try with `-cookies` and `-user-agent`? try again in %d min(s)", server.Config.Interval)
|
||||||
} else if errors.Is(err, context.Canceled) {
|
} else if errors.Is(err, context.Canceled) {
|
||||||
@ -76,10 +78,8 @@ func (ch *Channel) Update() {
|
|||||||
func (ch *Channel) RecordStream(ctx context.Context, client *chaturbate.Client) error {
|
func (ch *Channel) RecordStream(ctx context.Context, client *chaturbate.Client) error {
|
||||||
stream, err := client.GetStream(ctx, ch.Config.Username)
|
stream, err := client.GetStream(ctx, ch.Config.Username)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ch.IsOnline = false
|
|
||||||
return fmt.Errorf("get stream: %w", err)
|
return fmt.Errorf("get stream: %w", err)
|
||||||
}
|
}
|
||||||
ch.IsOnline = true
|
|
||||||
ch.StreamedAt = time.Now().Unix()
|
ch.StreamedAt = time.Now().Unix()
|
||||||
|
|
||||||
if err := ch.NextFile(); err != nil {
|
if err := ch.NextFile(); err != nil {
|
||||||
@ -97,6 +97,8 @@ func (ch *Channel) RecordStream(ctx context.Context, client *chaturbate.Client)
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("get playlist: %w", err)
|
return fmt.Errorf("get playlist: %w", err)
|
||||||
}
|
}
|
||||||
|
ch.UpdateOnlineStatus(true) // Update online status after `GetPlaylist` is OK
|
||||||
|
|
||||||
ch.Info("stream quality - resolution %dp (target: %dp), framerate %dfps (target: %dfps)", playlist.Resolution, ch.Config.Resolution, playlist.Framerate, ch.Config.Framerate)
|
ch.Info("stream quality - resolution %dp (target: %dp), framerate %dfps (target: %dfps)", playlist.Resolution, ch.Config.Resolution, playlist.Framerate, ch.Config.Framerate)
|
||||||
|
|
||||||
return playlist.WatchSegments(ctx, ch.HandleSegment)
|
return playlist.WatchSegments(ctx, ch.HandleSegment)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user