Hang when the internet is disconnected

This commit is contained in:
YamiOdymel 2020-02-13 22:20:23 +08:00
parent 9596980c1b
commit fa976d484e
No known key found for this signature in database
GPG Key ID: 68E469836934DB36
2 changed files with 13 additions and 4 deletions

View File

@ -76,6 +76,9 @@ failed to fetch the video segments after retried, XXX might went offline.
cannot find segment XXX, will try again. (1/5)
無法找到影片段落燒後會重新嘗試。1/5
inserting XXX segment to the master file.
正在插入片段 XXX 至主要影片檔案。
inserting XXX segment to the master file. (total: XXX)
正在插入片段 XXX 至主要影片檔案。總共XXX
skipped XXX due to the empty body!
跳過 XXX 片段因為其為空白內容!
```

10
main.go
View File

@ -192,7 +192,12 @@ func combineSegment(master *os.File, filename string) {
<-time.After(4 * time.Second)
for {
<-time.After(800 * time.Millisecond)
<-time.After(300 * time.Millisecond)
if index == segmentIndex {
<-time.After(1 * time.Second)
continue
}
if !pathx.Exists(fmt.Sprintf("%s~%d.ts", filename, index)) {
if retry >= 5 {
@ -213,7 +218,7 @@ func combineSegment(master *os.File, filename string) {
//
b, _ := ioutil.ReadFile(fmt.Sprintf("%s~%d.ts", filename, index))
master.Write(b)
log.Printf("inserting %d segment to the master file.", index)
log.Printf("inserting %d segment to the master file. (total: %d)", index, segmentIndex)
//
os.Remove(fmt.Sprintf("%s~%d.ts", filename, index))
//
@ -226,6 +231,7 @@ func fetchSegment(master *os.File, segment *m3u8.MediaSegment, baseURL string, f
_, body, _ := gorequest.New().Get(fmt.Sprintf("%s%s", baseURL, segment.URI)).EndBytes()
log.Printf("fetching %s (size: %d)\n", segment.URI, len(body))
if len(body) == 0 {
log.Printf("skipped %s due to the empty body!\n", segment.URI)
return
}
//