From a108d12b0e754e224a7ff8b6640d717ed22cc271 Mon Sep 17 00:00:00 2001 From: mK33y <56261048+mK33y@users.noreply.github.com> Date: Tue, 6 Sep 2022 22:05:38 +0200 Subject: [PATCH] Update main.go fixed segments problem. now you lose about 2-4 seconds when stream goes offline. working on a better solution tested it now for 24h. --- main.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index 995d429..05b4b6d 100644 --- a/main.go +++ b/main.go @@ -122,7 +122,7 @@ func parseM3U8Source(url string) (chunks []*m3u8.MediaSegment, wait float64, err // capture captures the specified channel streaming. func capture(username string) { - // Define the video filename by current time //04.09.22 added username into filename mKeey. + // Define the video filename by current time //04.09.22 added username into filename mK33y. filename := username + "_" + time.Now().Format("2006-01-02_15-04-05") // Get the channel page content body. body := getBody(username) @@ -186,8 +186,11 @@ func isDuplicateSegment(URI string) bool { } // combineSegment combines the segments to the master video file in the background. +// fixed segment problems mK33y. +// still needs some attention here func combineSegment(master *os.File, filename string) { index := 1 + delete := 1 var retry int <-time.After(4 * time.Second) @@ -220,8 +223,11 @@ func combineSegment(master *os.File, filename string) { master.Write(b) log.Printf("inserting %d segment to the master file. (total: %d)", index, segmentIndex) // - os.Remove(fmt.Sprintf("./%s/%s~%d.ts", savePath, filename, index)) - // + e := os.Remove(fmt.Sprintf("./%s/%s~%d.ts", savePath, filename, delete)) + if e != nil { + delete-- + } + delete++ index++ } }