diff --git a/README.md b/README.md index a13996b..1b1ddda 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ [![Python 3.7+](https://img.shields.io/badge/python-%3E%3D%20v3.7-blue)](https://www.python.org/downloads/release/python-370/) # qBittorrent plugins -## Rutracker.org ![v1.6](https://img.shields.io/badge/v1.6-blue) +## Rutracker.org ![v1.7](https://img.shields.io/badge/v1.7-blue) Biggest russian torrent tracker. ## Rutor.org ![v1.5](https://img.shields.io/badge/v1.5-blue) diff --git a/engines/rutracker.py b/engines/rutracker.py index eb2c2b0..3e1645b 100644 --- a/engines/rutracker.py +++ b/engines/rutracker.py @@ -1,4 +1,4 @@ -# VERSION: 1.6 +# VERSION: 1.7 # AUTHORS: imDMG [imdmgg@gmail.com] # rutracker.org search engine plugin for qBittorrent @@ -15,7 +15,7 @@ from html import unescape from http.cookiejar import Cookie, MozillaCookieJar from pathlib import Path from tempfile import NamedTemporaryFile -from typing import Optional, Union +from typing import Optional from urllib.error import URLError, HTTPError from urllib.parse import urlencode, unquote from urllib.request import build_opener, HTTPCookieProcessor, ProxyHandler @@ -40,8 +40,8 @@ def rng(t: int) -> range: RE_TORRENTS = re.compile( - r'data-topic_id="(\d+?)".+?">(.+?)' - r'.+?data-ts_text="([-0-9]+?)">.+?Личи">(\d+?)', + r'(.+?).+?data-ts_text="([-0-9]+?)">.+?Личи">(\d+?)', re.S ) RE_RESULTS = re.compile(r"Результатов\sпоиска:\s(\d{1,3})\s Union[None, int]: + def searching(self, query: str, first: bool = False) -> Optional[int]: response = self._request(query) if self.error: return None page, torrents_found = response.decode("cp1251"), -1 if first: if "log-out-icon" not in page: + if "login-form-full" not in page: + self.error = "Unexpected page content" + return None logger.debug("Looks like we lost session id, lets login") - self.mcj.clear() self.login() if self.error: return None @@ -281,7 +285,7 @@ class Rutracker: def _request( self, url: str, data: Optional[bytes] = None, repeated: bool = False - ) -> Union[bytes, None]: + ) -> Optional[bytes]: try: with self.session.open(url, data, 5) as r: # checking that tracker isn't blocked