frozenpandaman / mangadex-dl

Download manga from MangaDex.org
GNU General Public License v3.0
238 stars 38 forks source link

Retry downloads before failing. #20

Closed orbea closed 3 years ago

orbea commented 3 years ago

Sometimes when using mangadex-dl it will trigger intermittent download errors where retrying one or more times will result in the download working.

I think it would be better if mangadex-dl would try the download a few times before deciding the download link did not work. I made this small hack which works sometimes, but someone that knows python could probably do better.

diff --git a/mangadex-dl.py b/mangadex-dl.py
index ba98df4..106c70c 100755
--- a/mangadex-dl.py
+++ b/mangadex-dl.py
@@ -133,7 +133,13 @@ def dl(manga_id, lang_code, tld="org"):
                with open(outfile, 'wb') as f:
                    f.write(r.content)
            else:
-               print("Encountered Error {} when downloading.".format(e.code))
+               time.sleep(5)
+               r = scraper.get(url)
+               if r.status_code == 200:
+                   with open(outfile, 'wb') as f:
+                       f.write(r.content)
+               else:
+                   print("Encountered Error {} when downloading.".format(e.code))

            print(" Downloaded page {}.".format(pagenum))
            time.sleep(1)
orbea commented 3 years ago

Seems PR https://github.com/frozenpandaman/mangadex-dl/pull/12 does this among other things.

https://github.com/frozenpandaman/mangadex-dl/pull/12/commits/49d46b106e0075a4a977a11b5b85a66eb0991d1d#diff-bf42877ca45a297d4c75224245657926R138

frozenpandaman commented 3 years ago

Thanks! I added in this functionality. :)