Skip to content

Commit

Permalink
Added retrying on fail and bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
stargazer39 committed Apr 3, 2022
1 parent 78eac11 commit fcf6453
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 11 deletions.
17 changes: 14 additions & 3 deletions download.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"os/exec"
"path"
"strings"
"time"

"github.com/pieterclaerhout/go-waitgroup"
)
Expand Down Expand Up @@ -41,7 +42,13 @@ func DownloadWithHttp(client *http.Client, u string, name string) error {
for {
line, _, err := reader.ReadLine()

if err == io.EOF {
if err != nil {
switch err {
case io.EOF:
break
default:
return err
}
break
}

Expand All @@ -59,7 +66,7 @@ func DownloadWithHttp(client *http.Client, u string, name string) error {
m3u8_path := path.Join(name, "out.m3u8")

if err := DownloadURLToPath(client, u, m3u8_path); err != nil {
log.Panic(err)
return err
}

wg := waitgroup.NewWaitGroup(16)
Expand Down Expand Up @@ -88,8 +95,12 @@ func DownloadWithHttp(client *http.Client, u string, name string) error {
new_url := url.String()
new_fPath := path.Join(name, fName)

retry:
if err := DownloadURLToPath(client, new_url, new_fPath); err != nil {
log.Panic(err)
log.Printf("File %s faild to download with Error :\n%v\nRetrying...", fName, err)
time.Sleep(time.Second * 5)

goto retry
}

progress <- 1
Expand Down
23 changes: 15 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func main() {

defer func() {
fmt.Println("Press any key to exit.")
reader.ReadLine()
reader.ReadRune()
}()

// Check for ffmpeg
Expand All @@ -61,7 +61,8 @@ func main() {
u, err := url.Parse(*ed_url)

if err != nil {
log.Panic(err)
log.Println(err)
return
}

videoId := strings.TrimSpace(u.Query().Get("id"))
Expand Down Expand Up @@ -92,7 +93,8 @@ func main() {
doc, err := goquery.NewDocumentFromResponse(resp)

if err != nil {
log.Panic(err)
log.Println(err)
return
}

user := strings.TrimSpace(doc.Find("#dropdown08").Text())
Expand All @@ -107,13 +109,15 @@ func main() {
resp, rErr := client.Client.Get(*ed_url)

if rErr != nil {
log.Panic(err)
log.Println(err)
return
}

doc2, err := goquery.NewDocumentFromResponse(resp)

if err != nil {
log.Panic(err)
log.Println(err)
return
}

title := strings.TrimSpace(doc2.Find("#content-wrapper > div > div.col-md-12 > h2").Text())
Expand All @@ -131,13 +135,15 @@ func main() {
query.Add("full", "ZnVsbA==")

if err := client.GetJson("https://lecturecapture.sliit.lk/webservice.php", &res, &query); err != nil {
log.Panicln(err)
log.Println(err)
return
}

ur, err := url.Parse("https://lecturecapture.sliit.lk/webservice.php")

if err != nil {
log.Panicln(err)
log.Println(err)
return
}

if *high_quality {
Expand All @@ -157,7 +163,8 @@ func main() {
log.Println("Starting Download...")

if err := DownloadWithHttp(client.Client, ur.String(), videoName); err != nil {
log.Panicln(err)
log.Println(err)
return
}
}

Expand Down

0 comments on commit fcf6453

Please sign in to comment.