forked from DRMTalks/devine
Use rich status when checking for proxy geofence
This commit is contained in:
parent
cd0c419142
commit
e9b3b3a588
|
@ -11,6 +11,7 @@ from requests.adapters import HTTPAdapter, Retry
|
||||||
|
|
||||||
from devine.core.cacher import Cacher
|
from devine.core.cacher import Cacher
|
||||||
from devine.core.config import config
|
from devine.core.config import config
|
||||||
|
from devine.core.console import console
|
||||||
from devine.core.constants import AnyTrack
|
from devine.core.constants import AnyTrack
|
||||||
from devine.core.credential import Credential
|
from devine.core.credential import Credential
|
||||||
from devine.core.titles import Title_T, Titles_T
|
from devine.core.titles import Title_T, Titles_T
|
||||||
|
@ -29,6 +30,7 @@ class Service(metaclass=ABCMeta):
|
||||||
self.config = ctx.obj.config
|
self.config = ctx.obj.config
|
||||||
|
|
||||||
self.log = logging.getLogger(self.__class__.__name__)
|
self.log = logging.getLogger(self.__class__.__name__)
|
||||||
|
|
||||||
self.session = self.get_session()
|
self.session = self.get_session()
|
||||||
self.cache = Cacher(self.__class__.__name__)
|
self.cache = Cacher(self.__class__.__name__)
|
||||||
|
|
||||||
|
@ -37,18 +39,24 @@ class Service(metaclass=ABCMeta):
|
||||||
else:
|
else:
|
||||||
self.proxy = None
|
self.proxy = None
|
||||||
|
|
||||||
if not self.proxy and self.GEOFENCE:
|
if not self.proxy:
|
||||||
# no explicit proxy, let's get one to GEOFENCE if needed
|
# don't override the explicit proxy set by the user, even if they may be geoblocked
|
||||||
current_region = get_ip_info(self.session)["country"].lower()
|
with console.status("Checking if current region is Geoblocked...", spinner="dots"):
|
||||||
if not any(x.lower() == current_region for x in self.GEOFENCE):
|
if self.GEOFENCE:
|
||||||
requested_proxy = self.GEOFENCE[0] # first is likely main region
|
# no explicit proxy, let's get one to GEOFENCE if needed
|
||||||
self.log.info(f"Current IP region is blocked by the service, getting Proxy to {requested_proxy}")
|
current_region = get_ip_info(self.session)["country"].lower()
|
||||||
# current region is not in any of the service's supported regions
|
if any(x.lower() == current_region for x in self.GEOFENCE):
|
||||||
for proxy_provider in ctx.obj.proxy_providers:
|
console.log("Service is not Geoblocked in your region")
|
||||||
self.proxy = proxy_provider.get_proxy(requested_proxy)
|
else:
|
||||||
if self.proxy:
|
requested_proxy = self.GEOFENCE[0] # first is likely main region
|
||||||
self.log.info(f" + {self.proxy} (from {proxy_provider.__class__.__name__})")
|
console.log(f"Service is Geoblocked in your region, getting a Proxy to {requested_proxy}")
|
||||||
break
|
for proxy_provider in ctx.obj.proxy_providers:
|
||||||
|
self.proxy = proxy_provider.get_proxy(requested_proxy)
|
||||||
|
if self.proxy:
|
||||||
|
console.log(f"Got Proxy from {proxy_provider.__class__.__name__}")
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
console.log("Service has no Geofence")
|
||||||
|
|
||||||
if self.proxy:
|
if self.proxy:
|
||||||
self.session.proxies.update({"all": self.proxy})
|
self.session.proxies.update({"all": self.proxy})
|
||||||
|
|
Loading…
Reference in New Issue