diff options
author | Keuin <[email protected]> | 2022-09-10 16:05:10 +0800 |
---|---|---|
committer | Keuin <[email protected]> | 2022-09-10 16:05:10 +0800 |
commit | e999937d75d8e8c40b06add376ebac423b0c2079 (patch) | |
tree | 8a30abaa5fc8fc68d283e0be52a73ee83bdaf3a2 /bilibili/streaming.go | |
parent | f028bff042f471a68dff681af9c79ef96bc952e5 (diff) |
Fix task is not properly restarted when the live is closed and started again.
Use more friendly log format to replace golang's default `log.Logger`. (not completed)
Cleaner task status management.
Diffstat (limited to 'bilibili/streaming.go')
-rw-r--r-- | bilibili/streaming.go | 12 |
1 files changed, 1 insertions, 11 deletions
diff --git a/bilibili/streaming.go b/bilibili/streaming.go index 64dc26d..9a26c2d 100644 --- a/bilibili/streaming.go +++ b/bilibili/streaming.go @@ -52,20 +52,10 @@ func (b Bilibili) CopyLiveStream( defer func() { _ = resp.Body.Close() }() - // guard the following copy loop - // if the context is cancelled, stop it by closing the reader - guardianCtx, cancelGuardian := context.WithCancel(ctx) - go func() { - <-guardianCtx.Done() - _ = resp.Body.Close() - }() - defer cancelGuardian() - // blocking copy n, err := common.CopyToFileWithBuffer(ctx, out, resp.Body, buffer, readChunkSize, false) if err != nil && !errors.Is(err, context.Canceled) { - // real error happens b.error.Printf("Stream copying was interrupted unexpectedly: %v", err) } @@ -73,6 +63,6 @@ func (b Bilibili) CopyLiveStream( b.info.Printf("The live is ended. (room %v)", roomId) } - b.info.Printf("Bytes copied: %v", n) + b.info.Printf("Total downloaded: %v", common.PrettyBytes(uint64(n))) return err } |