Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 24 additions & 16 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
/*

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.

*/

Expand Down Expand Up @@ -42,7 +42,7 @@ func doRequest(c *http.Client, req *http.Request) (*http.Response, error) {
}

type Download struct {
URI string
URI string
totalDuration time.Duration
}

Expand Down Expand Up @@ -74,9 +74,9 @@ func downloadSegment(fn string, dlc chan *Download, recTime time.Duration) {
log.Printf("Downloaded %v\n", v.URI)
if recTime != 0 {
log.Printf("Recorded %v of %v\n", v.totalDuration, recTime)
} else {
log.Printf("Recorded %v\n", v.totalDuration)
}
} else {
log.Printf("Recorded %v\n", v.totalDuration)
}
}
}

Expand All @@ -88,6 +88,8 @@ func getPlaylist(urlStr string, recTime time.Duration, useLocalTime bool, dlc ch
if err != nil {
log.Fatal(err)
}
retry_time := 0
retry_count := 2
for {
req, err := http.NewRequest("GET", urlStr, nil)
if err != nil {
Expand All @@ -97,6 +99,12 @@ func getPlaylist(urlStr string, recTime time.Duration, useLocalTime bool, dlc ch
if err != nil {
log.Print(err)
time.Sleep(time.Duration(3) * time.Second)
if retry_time >= retry_count {
log.Fatalf("after retry %d time, can not get playlist, end process.\n", retry_time)
}
retry_time++
log.Printf("get playlist faild, retry... %d \n", retry_time)
continue
}
playlist, listType, err := m3u8.DecodeFrom(resp.Body, true)
if err != nil {
Expand Down Expand Up @@ -141,8 +149,8 @@ func getPlaylist(urlStr string, recTime time.Duration, useLocalTime bool, dlc ch
}
}
if mpl.Closed {
close(dlc)
return
close(dlc)
return
} else {
time.Sleep(time.Duration(int64(mpl.TargetDuration * 1000000000)))
}
Expand Down