@@ -158,7 +158,7 @@ func (tale *TaleBook) Next() (*Book, error) {
158
158
return & book , nil
159
159
}
160
160
161
- func (tale * TaleBook ) Download (b * Book , dir string ) error {
161
+ func (tale * TaleBook ) tryDownload (b * Book , dir string , count int ) error {
162
162
for _ , file := range b .Book .Files {
163
163
var downloadURL string
164
164
if strings .HasPrefix (file .Href , "https://" ) || strings .HasPrefix (file .Href , "http://" ) {
@@ -169,7 +169,7 @@ func (tale *TaleBook) Download(b *Book, dir string) error {
169
169
if tale .verbose {
170
170
log .Printf ("download %s" , downloadURL )
171
171
}
172
-
172
+
173
173
req , err := http .NewRequest (http .MethodGet , downloadURL , nil )
174
174
if err != nil {
175
175
return err
@@ -212,12 +212,22 @@ func (tale *TaleBook) Download(b *Book, dir string) error {
212
212
if err != nil {
213
213
fh .Close ()
214
214
os .Remove (filepath )
215
- return wrapperTimeOutError (err )
215
+ if IsTimeOutError (err ) {
216
+ if tale .retry == count {
217
+ return err
218
+ }
219
+ log .Printf ("timeout , retry %s://%s%s [%d/%d]" , req .URL .Scheme , req .Host , req .URL .Path , count + 1 , tale .retry )
220
+ return tale .tryDownload (b , dir , count + 1 )
221
+ }
222
+ return err
216
223
}
217
224
fh .Close ()
218
225
}
219
226
return nil
220
227
}
228
+ func (tale * TaleBook ) Download (b * Book , dir string ) error {
229
+ return tale .tryDownload (b , dir , 0 )
230
+ }
221
231
222
232
func NewTableBook (site string , opstions ... func (* TaleBook )) (* TaleBook , error ) {
223
233
var client http.Client = http.Client {
0 commit comments