diff --git a/seedrcc/seedr.py b/seedrcc/seedr.py index 52aa8ca..07430bd 100755 --- a/seedrcc/seedr.py +++ b/seedrcc/seedr.py @@ -2,6 +2,8 @@ import functools from base64 import b64decode +import validators + from seedrcc.login import Login from seedrcc.login import createToken @@ -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'. @@ -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/') + >>> print(response) + Example: Adding torrent using wishlistId @@ -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 diff --git a/setup.py b/setup.py index 14ca63a..16bf657 100755 --- a/setup.py +++ b/setup.py @@ -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/",