Refactor method to remove max wait time
This commit is contained in:
@@ -6,6 +6,7 @@ import logging
|
||||
import re
|
||||
import time
|
||||
import urllib.parse
|
||||
from collections import namedtuple
|
||||
from typing import Callable, Optional
|
||||
|
||||
import _hashlib
|
||||
@@ -29,7 +30,9 @@ class Resource:
|
||||
self.extension = self._determine_extension()
|
||||
|
||||
@staticmethod
|
||||
def retry_download(url: str, max_wait_time: int) -> Callable:
|
||||
def retry_download(url: str) -> Callable:
|
||||
max_wait_time = 300
|
||||
|
||||
def http_download() -> Optional[bytes]:
|
||||
current_wait_time = 60
|
||||
while True:
|
||||
|
||||
@@ -14,4 +14,4 @@ class Direct(BaseDownloader):
|
||||
super().__init__(post)
|
||||
|
||||
def find_resources(self, authenticator: Optional[SiteAuthenticator] = None) -> list[Resource]:
|
||||
return [Resource(self.post, self.post.url, Resource.retry_download(self.post.url, 300))]
|
||||
return [Resource(self.post, self.post.url, Resource.retry_download(self.post.url))]
|
||||
|
||||
@@ -29,7 +29,7 @@ class Erome(BaseDownloader):
|
||||
for link in links:
|
||||
if not re.match(r'https?://.*', link):
|
||||
link = 'https://' + link
|
||||
out.append(Resource(self.post, link, Resource.retry_download(link, 300)))
|
||||
out.append(Resource(self.post, link, Resource.retry_download(link)))
|
||||
return out
|
||||
|
||||
@staticmethod
|
||||
|
||||
@@ -31,7 +31,7 @@ class Gallery(BaseDownloader):
|
||||
|
||||
if not image_urls:
|
||||
raise SiteDownloaderError('No images found in Reddit gallery')
|
||||
return [Resource(self.post, url, Resource.retry_download(url, 300)) for url in image_urls]
|
||||
return [Resource(self.post, url, Resource.retry_download(url)) for url in image_urls]
|
||||
|
||||
@ staticmethod
|
||||
def _get_links(id_dict: list[dict]) -> list[str]:
|
||||
|
||||
@@ -33,7 +33,7 @@ class Imgur(BaseDownloader):
|
||||
|
||||
def _compute_image_url(self, image: dict) -> Resource:
|
||||
image_url = 'https://i.imgur.com/' + image['hash'] + self._validate_extension(image['ext'])
|
||||
return Resource(self.post, image_url, Resource.retry_download(image_url, 300))
|
||||
return Resource(self.post, image_url, Resource.retry_download(image_url))
|
||||
|
||||
@staticmethod
|
||||
def _get_data(link: str) -> dict:
|
||||
|
||||
@@ -18,7 +18,7 @@ class Redgifs(BaseDownloader):
|
||||
|
||||
def find_resources(self, authenticator: Optional[SiteAuthenticator] = None) -> list[Resource]:
|
||||
media_url = self._get_link(self.post.url)
|
||||
return [Resource(self.post, media_url, Resource.retry_download(media_url, 300), '.mp4')]
|
||||
return [Resource(self.post, media_url, Resource.retry_download(media_url), '.mp4')]
|
||||
|
||||
@staticmethod
|
||||
def _get_link(url: str) -> str:
|
||||
|
||||
Reference in New Issue
Block a user