Skip to content

Commit

Permalink
Allow adding torrents with torrent file
Browse files Browse the repository at this point in the history
  • Loading branch information
hemantapkh committed May 30, 2022
1 parent a5d9acb commit 2c9b81b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
37 changes: 34 additions & 3 deletions seedrcc/seedr.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import functools
from base64 import b64decode

import validators

from seedrcc.login import Login
from seedrcc.login import createToken

Expand Down Expand Up @@ -161,12 +163,14 @@ def getMemoryBandwidth(self):
return response

@__autoRefresh
def addTorrent(self, magnetLink=None, wishlistId=None, folderId='-1'):
def addTorrent(self, magnetLink=None, torrentFile=None, wishlistId=None, folderId='-1'):
"""
Add a torrent to the seedr account for downloading
Args:
magnetLink (str): The magnet link of the torrent
magnetLink (str, optional): The magnet link of the torrent
torrentFile (str, optional): Remote or local path of the
torrent file
folderId (str, optional): The folder id to add the torrent to.
Defaults to '-1'.
Expand All @@ -176,6 +180,18 @@ def addTorrent(self, magnetLink=None, wishlistId=None, folderId='-1'):
>>> response = account.addTorrent(magnetLink='magnet:?xt=')
>>> print(response)
Example:
Adding torrent from local torrent file
>>> response = account.addTorrent(torrentFile='/path/to/torrent')
>>> print(response)
Example:
Adding torrent from remote torrent file
>>> response = account.addTorrent(torrentFile='https://api.telegram.org/file/bot<token>/<file_path>')
>>> print(response)
Example:
Adding torrent using wishlistId
Expand All @@ -200,7 +216,22 @@ def addTorrent(self, magnetLink=None, wishlistId=None, folderId='-1'):
'folder_id': folderId
}

response = requests.post(self._base_url, data=data, params=params)
files = {}

if torrentFile:
if validators.url(torrentFile):
file = requests.get(torrentFile).content

files = {
'torrent_file': file
}

else:
files = {
'torrent_file': open(torrentFile, 'rb').read(),
}

response = requests.post(self._base_url, data=data, params=params, files=files)
return response

@__autoRefresh
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
description="Complete Python API wrapper of seedr.cc",
long_description=readme,
long_description_content_type="text/markdown",
install_requires=["requests"],
install_requires=["requests", "validators"],
url="https://github.com/hemantapkh/seedrcc",
project_urls={
"Documentation": "https://seedrcc.readthedocs.io/en/latest/",
Expand Down

0 comments on commit 2c9b81b

Please sign in to comment.