11import os
2- import httpx
32from typing import Dict , Optional
3+
4+ import httpx
45from typing_extensions import Any , Generator , Union # pylint: disable=no-name-in-module
6+
57from ncoreparser .data import URLs , SearchParamType , SearchParamWhere , ParamSort , ParamSeq
68from ncoreparser .error import NcoreConnectionError , NcoreCredentialError , NcoreDownloadError
79from ncoreparser .parser import TorrentsPageParser , TorrenDetailParser , RssParser , ActivityParser , RecommendedParser
1113
1214
1315class Client :
16+ # pylint: disable=too-many-instance-attributes
1417 def __init__ (self , timeout : int = 1 , cookies : Optional [Dict [str , str ]] = None ) -> None :
1518 self ._client = httpx .Client (
1619 headers = {"User-Agent" : "python ncoreparser" }, timeout = timeout , follow_redirects = True
@@ -21,7 +24,7 @@ def __init__(self, timeout: int = 1, cookies: Optional[Dict[str, str]] = None) -
2124 self ._rss_parser = RssParser ()
2225 self ._activity_parser = ActivityParser ()
2326 self ._recommended_parser = RecommendedParser ()
24- self ._allowed_cookies = [' nick' , ' pass' , ' stilus' , ' nyelv' , ' PHPSESSID' ]
27+ self ._allowed_cookies = [" nick" , " pass" , " stilus" , " nyelv" , " PHPSESSID" ]
2528 if cookies :
2629 set_cookies_to_client (self ._client , cookies , self ._allowed_cookies , URLs .COOKIE_DOMAIN .value )
2730 if self ._check_logged_in ():
@@ -30,44 +33,38 @@ def __init__(self, timeout: int = 1, cookies: Optional[Dict[str, str]] = None) -
3033 def _check_logged_in (self ) -> bool :
3134 try :
3235 r = self ._client .get (URLs .INDEX .value )
33- if ' login.php' in str (r .url ) or ' <title>nCore</title>' in r .text :
36+ if " login.php" in str (r .url ) or " <title>nCore</title>" in r .text :
3437 return False
3538 return True
36- except Exception :
39+ except Exception : # pylint: disable=broad-except
3740 return False
3841
3942 def login (self , username : str , password : str , twofactorcode : str = "" ) -> Dict [str , str ]:
4043 if self ._logged_in and self ._check_logged_in ():
41- return extract_cookies_from_client (self ._client , self ._allowed_cookies , URLs . COOKIE_DOMAIN . value )
42-
44+ return extract_cookies_from_client (self ._client , self ._allowed_cookies )
45+
4346 self ._client .cookies .clear ()
4447 self ._logged_in = False
45-
48+
4649 try :
47- login_data = {
48- "nev" : username ,
49- "pass" : password ,
50- "set_lang" : "hu" ,
51- "submitted" : "1" ,
52- "ne_leptessen_ki" : "1"
53- }
54-
50+ login_data = {"nev" : username , "pass" : password , "set_lang" : "hu" , "submitted" : "1" , "ne_leptessen_ki" : "1" }
51+
5552 if twofactorcode :
5653 login_data ["2factor" ] = twofactorcode
57-
54+
5855 r = self ._client .post (URLs .LOGIN .value , data = login_data )
5956 except Exception as e :
6057 raise NcoreConnectionError (f"Error while performing post method to url '{ URLs .LOGIN .value } '." ) from e
61-
62- if r .url != URLs .INDEX .value or ' <title>nCore</title>' in r .text :
58+
59+ if r .url != URLs .INDEX .value or " <title>nCore</title>" in r .text :
6360 self .logout ()
6461 error_msg = f"Error while login, check credentials for user: '{ username } '"
6562 if twofactorcode :
6663 error_msg += ". Invalid 2FA code or wait 5 minutes between login attempts."
6764 raise NcoreCredentialError (error_msg )
68-
65+
6966 self ._logged_in = True
70- return extract_cookies_from_client (self ._client , self ._allowed_cookies , URLs . COOKIE_DOMAIN . value )
67+ return extract_cookies_from_client (self ._client , self ._allowed_cookies )
7168
7269 @check_login
7370 # pylint: disable=too-many-arguments, too-many-positional-arguments
@@ -171,4 +168,4 @@ def download(self, torrent: Torrent, path: str, override: bool = False) -> str:
171168 def logout (self ) -> None :
172169 self ._client .cookies .clear ()
173170 self ._client .close ()
174- self ._logged_in = False
171+ self ._logged_in = False
0 commit comments