Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [3.9, "3.10", 3.11]
python-version: [3.9, "3.10", 3.11, 3.12, 3.13]

steps:
- uses: actions/checkout@v2
Expand All @@ -28,10 +28,10 @@ jobs:
python-version: ${{ matrix.python-version }}
- name: Install deps
run: |
python -m pip install pytest coverage coveralls
python -m pip install -r requirements.dev.txt coveralls
- name: Run tests
env:
GITHUB_TOKEN: ${{ secrets.github_token }}
run: |
coverage run --source=torrt setup.py test
pytest --cov=torrt --cov-report=term-missing
coveralls --service=github
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ __pycache__
docs/_build/
build/
dist/
.eggs
.coverage
4 changes: 4 additions & 0 deletions requirements.dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pytest
pytest-cov
pytest-datafixtures
pytest-responsemock>=1.1.0
9 changes: 1 addition & 8 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import io
import os
import re
import sys

from setuptools import setup, find_packages

Expand Down Expand Up @@ -44,18 +43,12 @@ def get_version():
'beautifulsoup4',
'torrentool',
'lxml',
'cloudscraper',
],
setup_requires=[] + (['pytest-runner'] if 'test' in sys.argv else []) + [],

extras_require={
'telegram': ['python-telegram-bot >=13.10, <14.0.0a0']
},
test_suite='tests',
tests_require=[
'pytest',
'pytest-datafixtures',
'pytest-responsemock>=1.1.0',
],

entry_points={
'console_scripts': ['torrt = torrt.main:process_commands'],
Expand Down
9 changes: 7 additions & 2 deletions tests/test_main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from os.path import dirname, realpath, join
from os.path import dirname, realpath

from torrentool.torrent import Torrent

import cloudscraper

from torrt.base_rpc import BaseRPC
from torrt.base_tracker import GenericPublicTracker
from torrt.toolbox import bootstrap, TrackerClassesRegistry, NotifierClassesRegistry, RPCClassesRegistry, \
Expand Down Expand Up @@ -90,8 +92,11 @@ def load(cls):
def save(cls, settings_dict):
cls.cfg = settings_dict

scraper = cloudscraper.create_scraper()
monkeypatch.setattr('torrt.utils.create_scraper', lambda: scraper)

def patch_requests(response_contents):
monkeypatch.setattr('torrt.utils.Session.get', lambda self, url, **kwargs: DummyResponse(url, response_contents))
monkeypatch.setattr(scraper, "get", lambda url, **kwargs: DummyResponse(url, response_contents))

torrent_one_hash = 'c815be93f20bf8b12fed14bee35c14b19b1d1984'
torrent_one_data = (datafix_dir / 'torr_one.torrent').read_bytes()
Expand Down
3 changes: 2 additions & 1 deletion torrt/trackers/rutracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ def get_id_from_link(self, url: str) -> str:

def get_login_form_data(self, login: str, password: str) -> dict:
"""Returns a dictionary with data to be pushed to authorization form."""
return {'login_username': login, 'login_password': password, 'login': 'pushed', 'redirect': 'index.php'}
# %E2%F5%EE%E4 is Russian "вход" in cp1251 encoding
return {'login_username': login, 'login_password': password, 'login': '%E2%F5%EE%E4'}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Let's try to set login directly to вход value (%E2%F5%EE%E4 is win-1251-urlencoded). Yet, it's strange they'd started to verify the value.
  • Also redirect parameter should be just fine.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I captured the login form data using Safari's inspector on a Mac. The login value is provided as-is, and no redirect field was present. Using "вход" in UTF-8 likely won't work if the backend expects CP1251, and hardcoding CP1251 into a Python script that defaults to UTF-8 doesn't seem ideal. Of course, utf8 вход can be converted into cp1251 before encoding into form but this would inflate code size for no good reason.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and no redirect field was present.

I suspect this can be related to a referer header. Anyway, if this param breaks nothing I propose leaving in intact.

but this would inflate code size for no good reason.

Then we need at least a hint near that value: a hint about cp1251 вход.

Copy link
Author

@sormy sormy Mar 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

redirect is dead code these days, misleading that it is being used. Let me know if you still think that it should remain in codebase.


def before_download(self, url: str):
"""Used to perform some required actions right before .torrent download."""
Expand Down
12 changes: 3 additions & 9 deletions torrt/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
from typing import Any, Optional, Union, Generator, Tuple, Callable

from bs4 import BeautifulSoup
from requests import Response, Session, RequestException
from requests import Response, RequestException
from cloudscraper import create_scraper
from torrentool.api import Torrent
from torrentool.exceptions import BencodeDecodingError

Expand All @@ -44,21 +45,14 @@ class HttpClient:

timeout: int = 10

user_agent: str = (
'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.106 Safari/537.36')

def __init__(
self,
silence_exceptions: bool = False,
dump_fname_tpl: str = '%(ts)s.txt',
json: bool = False,
tunnel: bool = True,
):
session = Session()

session.headers.update({
'User-agent': self.user_agent,
})
session = create_scraper()

self.session = session
self.silence_exceptions = silence_exceptions,
Expand Down
5 changes: 3 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# See http://tox.readthedocs.org/en/latest/examples.html for samples.

[tox]
envlist = py{39,310,311}
envlist = py{39,310,311,312,313}

skip_missing_interpreters = True

[testenv]
deps = -r requirements.dev.txt
commands =
python setup.py test
pytest {tty:--color=yes} {posargs}