Skip to content
Merged
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
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.torrent binary
5 changes: 4 additions & 1 deletion .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,17 @@ on:
jobs:
build:

runs-on: ubuntu-latest
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest]
python-version: ["3.11", "3.12", "3.13"]

steps:
- uses: actions/checkout@v4
- name: Install locale
if: matrix.os == 'ubuntu-latest'
run: |
sudo apt install libxslt-dev libxml2-dev locales -y && sudo locale-gen ru_RU.UTF-8
sudo update-locale
Expand All @@ -33,6 +35,7 @@ jobs:
uv sync --only-group tests
uv pip install coveralls
- uses: astral-sh/ruff-action@v3
if: matrix.os == 'ubuntu-latest'
with:
version: 0.13.1
args: check
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ dependencies = [
"beautifulsoup4",
"torrentool",
"lxml",
"dateparser",
]

[project.urls]
Expand Down
2 changes: 1 addition & 1 deletion src/torrt/base_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ class GenericPublicTracker(GenericTracker):
login_required: bool = False

def get_id_from_link(self, url: str) -> str:
return url.split('/')[-1]
return url.rsplit('/', maxsplit=1)[-1]

def download_torrent(self, url: str, *, referer: str = '') -> bytes | None:
self.log_debug(f'Downloading torrent file from {url} ...')
Expand Down
21 changes: 4 additions & 17 deletions src/torrt/trackers/kinozal.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from datetime import datetime, time, timedelta
from datetime import datetime
from typing import ClassVar

import dateparser

from ..base_tracker import GenericPrivateTracker


Expand All @@ -25,23 +27,8 @@ def extract_page_date_updated(self) -> datetime | None:
def refresh_in_text(tag):
return tag.name == 'li' and tag.get_text().startswith('Обновлен')

def parse_date(date_val):
if date_val == 'сегодня':
return datetime.today() # noqa: DTZ002

elif date_val == 'вчера':
return datetime.today() - timedelta(days=1) # noqa: DTZ002

else:
return self.parse_datetime(date_val, '%d %B %Y', locale='ru')

dt_val = getattr(self._torrent_page.find(refresh_in_text).find('span'), 'text', '').strip()
parts = dt_val.partition(' в ')
if len(parts) != 3:
return None
else:
time_val = time.fromisoformat(parts[2])
return parse_date(parts[0]).replace(hour=time_val.hour, minute=time_val.minute, second=0, microsecond=0)
return dateparser.parse(dt_val, languages=['ru'])

def get_download_link(self, url: str) -> str:
"""Tries to find .torrent file download link at forum thread page and return that one."""
Expand Down
2 changes: 1 addition & 1 deletion tests/trackers/test_eniahd.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def test_get_torrent(response_mock, datafix_read, datafix_dir):
test_torrent = (datafix_dir / 'test.torrent').read_bytes()

with response_mock([
f"GET https://eniatv.com/viewtopic.php?t=1558 -> 200: {datafix_read('eniahd.html')}",
f"GET https://eniatv.com/viewtopic.php?t=1558 -> 200: {datafix_read('eniahd.html', encoding='utf-8')}",
b"GET https://eniatv.com/dl.php?id=5669 -> 200:" + test_torrent,

]) as _:
Expand Down
3 changes: 2 additions & 1 deletion tests/trackers/test_nnmclub.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ def test_get_torrent(response_mock, datafix_read, datafix_dir):
tracker.raise_on_error_response = True

test_torrent = (datafix_dir / 'test.torrent').read_bytes()
page_html = datafix_read('nnmclub.html', encoding='utf-8')

with response_mock([
f"GET https://nnmclub.to/forum/viewtopic.php?t=889443&sid= -> 200: {datafix_read('nnmclub.html')}",
f"GET https://nnmclub.to/forum/viewtopic.php?t=889443&sid= -> 200: {page_html}",
b"GET https://nnmclub.to/forum/download.php?id=762672&sid= -> 200:" + test_torrent,

]) as _:
Expand Down
Loading