Skip to content

Commit

Permalink
Add Kinozal (tracker) support and bump libs
Browse files Browse the repository at this point in the history
  • Loading branch information
konkere committed Oct 6, 2024
1 parent 5989638 commit 4fb3f27
Show file tree
Hide file tree
Showing 10 changed files with 86 additions and 18 deletions.
Binary file modified .github/img/TorrUpd.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .github/img/TorrUpd.xcf
Binary file not shown.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2024 Konkere
Copyright (c) 2023-2024 Konkere

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
![Torrent updater](/.github/img/TorrUpd.jpg)
Tool for automatically checking the relevance of torrents and updating them in the torrent client.

Supports trackers: RuTracker and NNM-Club (hash comparison in topics) and TeamHD (torrent size comparison in RSS, login problem due to reCaptcha).
Supports trackers: RuTracker and NNM-Club (hash comparison in topics), Kinozal (torrent size comparison in topics) and TeamHD (torrent size comparison in RSS, login problem due to reCaptcha).

Supports clients: qBittorrent, Transmission.

Expand Down Expand Up @@ -44,7 +44,7 @@ Fill data in files in ``$HOME/.config/TorrUpd/`` (or ``/PATH/TO/HOST/DIR`` for D

1.5. ``host``, ``username`` and ``password`` in client section (fill out separately for Transmission: ``protocol`` and ``port``).

1.6. in section ``[Settings]`` set ``client`` name and ``source`` for IDs (``file`` is default, ``client`` for check all torrents)
1.6. in section ``[Settings]`` set ``client`` name and ``source`` for IDs (``client`` for check all torrents, ``file`` for limited checking list from file)

2. ``update.list``:

Expand Down
14 changes: 12 additions & 2 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ def __init__(self):
'url': self.read_config('TeamHD', 'url'),
'passkey': self.read_config('TeamHD', 'passkey'),
},
'kinozal': {
'url': self.read_config('Kinozal', 'url'),
'username': self.read_config('Kinozal', 'username'),
'password': self.read_config('Kinozal', 'password'),
},
'qbittorrent': {
'host': self.read_config('qBittorrent', 'host'),
'username': self.read_config('qBittorrent', 'username'),
Expand Down Expand Up @@ -113,6 +118,10 @@ def create_config(self):
self.config.add_section('TeamHD')
self.config.set('TeamHD', 'url', 'https://teamhd.org')
self.config.set('TeamHD', 'passkey', '1a2b3c4d5e6f7g8h9i0j10k11l12m13n')
self.config.add_section('Kinozal')
self.config.set('Kinozal', 'url', 'https://kinozal.tv')
self.config.set('Kinozal', 'username', 'KTVUsername')
self.config.set('Kinozal', 'password', 'KTVPassword')
self.config.add_section('qBittorrent')
self.config.set('qBittorrent', 'host', 'qBtHostURL:port')
self.config.set('qBittorrent', 'username', 'qBtUsername')
Expand All @@ -125,13 +134,13 @@ def create_config(self):
self.config.set('Transmission', 'password', 'TMPassword')
self.config.add_section('Settings')
self.config.set('Settings', 'client', 'qBittorrent')
self.config.set('Settings', 'source', 'file')
self.config.set('Settings', 'source', 'client')
with open(self.config_file, 'w') as file:
self.config.write(file)
raise FileNotFoundError(f'Required to fill data in config: {self.config_file}')

def create_update_file(self):
update_info = '[RuTracker]\n\n[NNMClub]\n\n[TeamHD]\n'
update_info = '[RuTracker]\n\n[NNMClub]\n\n[TeamHD]\n\n[Kinozal]\n'
with open(self.update_file, 'w') as file:
file.write(update_info)
raise FileNotFoundError(f'Required to fill list of topics id in: {self.update_file}')
Expand All @@ -145,6 +154,7 @@ def get_ids(self):
'rutracker': [],
'nnmclub': [],
'teamhd': [],
'kinozal': [],
}
if self.source == 'file':
tracker_ids = get_ids_from_file(self.update_file, tracker_ids)
Expand Down
7 changes: 6 additions & 1 deletion examples/settings.conf-dist
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ password = NNMPassword
url = https://teamhd.org
passkey = 1a2b3c4d5e6f7g8h9i0j10k11l12m13n

[Kinozal]
url = https://kinozal.tv
username = KTVUsername
password = KTVPassword

[qBittorrent]
host = https://qBtHostURL:port
username = qBtUsername
Expand All @@ -27,4 +32,4 @@ password = TMPassword

[Settings]
client = qBittorrent
source = file
source = client
3 changes: 3 additions & 0 deletions examples/update.list-dist
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@
91234 you know
92345 mmm, cool
#93456 Ignore again?

[Kinozal]
8123456 Yeah!
14 changes: 7 additions & 7 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
beautifulsoup4==4.12.2
beautifulsoup4==4.12.3
bencoder.pyx==3.0.1
certifi==2023.11.17
certifi==2024.8.30
charset-normalizer==3.1.0
feedparser==6.0.11
idna==3.4
idna==3.10
packaging==23.2
qbittorrent-api==2023.11.57
requests==2.31.0
qbittorrent-api==2024.9.66
requests==2.32.3
sgmllib3k==1.0.0
six==1.16.0
soupsieve==2.4.1
transmission-rpc==7.0.3
transmission-rpc==7.0.11
typing_extensions==4.9.0
urllib3==2.0.2
urllib3==2.2.3
16 changes: 12 additions & 4 deletions torrent_updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from config import Conf
from bencoder import bdecode
from urllib.parse import urljoin
from tracker import RuTracker, NNMClub, TeamHD, rss_parser
from tracker import RuTracker, NNMClub, TeamHD, Kinozal, rss_parser


def main():
Expand All @@ -16,15 +16,23 @@ def main():
'rutracker': {
'incarnation': RuTracker,
'fingerprint': 'hash',
'dl_from': 'topic',
},
'nnmclub': {
'incarnation': NNMClub,
'fingerprint': 'hash',
'dl_from': 'topic',
},
'teamhd': {
'incarnation': TeamHD,
'fingerprint': 'size',
'rssjoin': 'rss.php?feed=dl&passkey='
'rssjoin': 'rss.php?feed=dl&passkey=',
'dl_from': 'feed',
},
'kinozal': {
'incarnation': Kinozal,
'fingerprint': 'size',
'dl_from': 'topic',
},
}
logging.basicConfig(
Expand All @@ -35,8 +43,8 @@ def main():
)
for tracker in config.tracker_ids.keys():
sessions[tracker] = None
if trackers[tracker]['fingerprint'] == 'size' and config.tracker_ids[tracker]:
rss_url = urljoin(config.auth[tracker]["url"], trackers[tracker]["rssjoin"])
if trackers[tracker]['dl_from'] == 'feed' and config.tracker_ids[tracker]:
rss_url = urljoin(config.auth[tracker]['url'], trackers[tracker]['rssjoin'])
rss_url = f'{rss_url}{config.auth[tracker]["passkey"]}'
config.tracker_ids[tracker] = rss_parser(rss_url, config.tracker_ids[tracker])
for tracker in config.tracker_ids.keys():
Expand Down
44 changes: 43 additions & 1 deletion tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from bs4 import BeautifulSoup
from bencoder import bencode, bdecode
from feedparser import parse as feed_parse
from urllib.parse import urljoin, urlsplit, urlunsplit
from urllib.parse import urljoin, urlsplit, urlunsplit, urlparse


def rss_parser(rss_url, ids):
Expand Down Expand Up @@ -41,6 +41,13 @@ def extract_base_url(url):
return str(base_url)


def add_subdomain(url, subdomain):
scheme = urlparse(url).scheme
netloc = urlparse(url).netloc
url_sub = urlunsplit((scheme, f'{subdomain}.{netloc}', '', '', ''))
return url_sub


class Tracker:

def __init__(self, auth, topic_id, session=None):
Expand Down Expand Up @@ -153,3 +160,38 @@ def download_torrent(self):
response = requests.get(self.download_url)
torrent = response.content
return torrent


class Kinozal(Tracker):

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.post_params['username'] = self.auth['username'].encode('Windows-1251')
self.post_params['password'] = self.auth['password']
del self.post_params['login']
self.base_url = self.auth['url']
self.login_url = urljoin(self.base_url, 'takelogin.php')
self.topic_url = urljoin(self.base_url, f'details.php?id={self.topic_id}')
self.download_url = urljoin(
add_subdomain(self.base_url, 'dl'), f'download.php?id={self.topic_id}'
)
self.fingerprint = self.get_actual_weight()

def download_torrent(self):
if not self.session:
self.create_session()
torrent = self.session.get(self.download_url).content
return torrent

def get_actual_weight(self):
response = requests.get(self.topic_url)
topic = BeautifulSoup(response.text, features='html.parser')
try:
weight_field = topic.find('span', {'class': 'floatright green n'}).get_text()
except AttributeError:
weight = ''
else:
pattern = r'^[\s\./d\w]*\(([\d\,]*)\)$'
weight = re.match(pattern, weight_field).group(1)
weight = weight.replace(',', '')
return weight

0 comments on commit 4fb3f27

Please sign in to comment.