From 053103581b74d86ebaf3f927fa1a8bc5ce2a1dbb Mon Sep 17 00:00:00 2001 From: LeGeRyChEeSe Date: Thu, 23 Feb 2023 10:00:59 +0100 Subject: [PATCH 1/7] Adding Tor Requests --- .gitignore | 4 +- py1337x/parser.py | 10 ++++- py1337x/py1337x.py | 99 +++++++++++++++++++++++++++++++++++++++++----- setup.py | 4 +- 4 files changed, 103 insertions(+), 14 deletions(-) diff --git a/.gitignore b/.gitignore index 483ec57..8c26631 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,6 @@ env/ py1337x/__pycache__/ dist/ -1337x.egg-info/ \ No newline at end of file +1337x.egg-info/ +.python-version +build/ \ No newline at end of file diff --git a/py1337x/parser.py b/py1337x/parser.py index 3169d51..533e38c 100644 --- a/py1337x/parser.py +++ b/py1337x/parser.py @@ -2,7 +2,10 @@ def torrentParser(response, baseUrl, page=1): - soup = BeautifulSoup(response.content, 'html.parser') + if isinstance(response, bytes): + soup = BeautifulSoup(response, 'html.parser') + else: + soup = BeautifulSoup(response.content, 'html.parser') torrentList = soup.select('a[href*="/torrent/"]') seedersList = soup.select('td.coll-2') @@ -57,7 +60,10 @@ def torrentParser(response, baseUrl, page=1): def infoParser(response, baseUrl): - soup = BeautifulSoup(response.content, 'html.parser') + if isinstance(response, bytes): + soup = BeautifulSoup(response, 'html.parser') + else: + soup = BeautifulSoup(response.content, 'html.parser') name = soup.find('div', {'class': 'box-info-heading clearfix'}) name = name.text.strip() if name else None diff --git a/py1337x/py1337x.py b/py1337x/py1337x.py index bd3ad66..667a2ae 100644 --- a/py1337x/py1337x.py +++ b/py1337x/py1337x.py @@ -1,10 +1,10 @@ import requests import requests_cache from py1337x import parser - - +from torpy.http.requests import TorRequests, tor_requests_session, do_request as requests_request +from torpy.utils import recv_all class py1337x(): - def __init__(self, proxy=None, cookie=None, cache=None, cacheTime=86400, backend='sqlite'): + def __init__(self, proxy=None, cookie=None, cache=None, cacheTime=86400, backend='sqlite', use_tor=False): self.baseUrl = f'https://www.{proxy}' if proxy else 'https://www.1377x.to' self.headers = { 'user-agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:88.0) Gecko/20100101 Firefox/88.0', @@ -13,11 +13,14 @@ def __init__(self, proxy=None, cookie=None, cache=None, cacheTime=86400, backend 'upgrade-insecure-requests': '1', 'te': 'trailers' } + self.proxies = ['1337x.to', '1337x.tw', '1377x.to', '1337xx.to', '1337x.st', 'x1337x.ws', 'x1337x.eu', 'x1337x.se', '1337x.is', '1337x.gd'] + self.categories = ['movies', 'tv', 'games', 'music', 'apps', 'anime', 'documentaries', 'xxx', 'others'] if cookie: self.headers['cookie'] = f'cf_clearance={cookie}' self.requests = requests_cache.CachedSession(cache, expire_after=cacheTime, backend=backend) if cache else requests + self.use_tor = use_tor #: Searching torrents def search(self, query, page=1, category=None, sortBy=None, order='desc'): @@ -25,14 +28,40 @@ def search(self, query, page=1, category=None, sortBy=None, order='desc'): category = category.upper() if category and category.lower() in ['xxx', 'tv'] else category.capitalize() if category else None url = f"{self.baseUrl}/{'sort-' if sortBy else ''}{'category-' if category else ''}search/{query}/{category+'/' if category else ''}{sortBy.lower()+'/' if sortBy else ''}{order.lower()+'/' if sortBy else ''}{page}/" - response = self.requests.get(url, headers=self.headers) + if self.use_tor: + for proxy in self.proxies: + try: + response = requests_request(url, headers=self.headers, retries=1) + response = response.encode() + except: + self.baseUrl = f'https://www.{proxy}' + url = f"{self.baseUrl}/{'sort-' if sortBy else ''}{'category-' if category else ''}search/{query}/{category+'/' if category else ''}{sortBy.lower()+'/' if sortBy else ''}{order.lower()+'/' if sortBy else ''}{page}/" + continue + else: + break + else: + response = self.requests.get(url, headers=self.headers) + return parser.torrentParser(response, baseUrl=self.baseUrl, page=page) #: Trending torrents def trending(self, category=None, week=False): url = f"{self.baseUrl}/trending{'-week' if week and not category else ''}{'/w/'+category.lower()+'/' if week and category else '/d/'+category.lower()+'/' if not week and category else ''}" - response = self.requests.get(url, headers=self.headers) + if self.use_tor: + for proxy in self.proxies: + try: + response = requests_request(url, headers=self.headers, retries=1) + response = response.encode() + except: + self.baseUrl = f'https://www.{proxy}' + url = f"{self.baseUrl}/trending{'-week' if week and not category else ''}{'/w/'+category.lower()+'/' if week and category else '/d/'+category.lower()+'/' if not week and category else ''}" + continue + else: + break + else: + response = self.requests.get(url, headers=self.headers) + return parser.torrentParser(response, baseUrl=self.baseUrl) #: Top 100 torrents @@ -40,14 +69,40 @@ def top(self, category=None): category = 'applications' if category and category.lower() == 'apps' else 'television' if category and category.lower() == 'tv' else category.lower() if category else None url = f"{self.baseUrl}/top-100{'-'+category if category else ''}" - response = self.requests.get(url, headers=self.headers) + if self.use_tor: + for proxy in self.proxies: + try: + response = requests_request(url, headers=self.headers, retries=1) + response = response.encode() + except: + self.baseUrl = f'https://www.{proxy}' + url = f"{self.baseUrl}/top-100{'-'+category if category else ''}" + continue + else: + break + else: + response = self.requests.get(url, headers=self.headers) + return parser.torrentParser(response, baseUrl=self.baseUrl) #: Popular torrents def popular(self, category, week=False): url = f"{self.baseUrl}/popular-{category.lower()}{'-week' if week else ''}" - response = self.requests.get(url, headers=self.headers) + if self.use_tor: + for proxy in self.proxies: + try: + response = requests_request(url, headers=self.headers, retries=1) + response = response.encode() + except: + self.baseUrl = f'https://www.{proxy}' + url = f"{self.baseUrl}/popular-{category.lower()}{'-week' if week else ''}" + continue + else: + break + else: + response = self.requests.get(url, headers=self.headers) + return parser.torrentParser(response, baseUrl=self.baseUrl) #: Browse torrents by category type @@ -55,7 +110,20 @@ def browse(self, category, page=1): category = category.upper() if category.lower() in ['xxx', 'tv'] else category.capitalize() url = f'{self.baseUrl}/cat/{category}/{page}/' - response = self.requests.get(url, headers=self.headers) + if self.use_tor: + for proxy in self.proxies: + try: + response = requests_request(url, headers=self.headers, retries=1) + response = response.encode() + except: + self.baseUrl = f'https://www.{proxy}' + url = f'{self.baseUrl}/cat/{category}/{page}/' + continue + else: + break + else: + response = self.requests.get(url, headers=self.headers) + return parser.torrentParser(response, baseUrl=self.baseUrl, page=page) #: Info of torrent @@ -66,6 +134,19 @@ def info(self, link=None, torrentId=None): raise TypeError('Got an unexpected argument: Pass either link or torrentId') link = f'{self.baseUrl}/torrent/{torrentId}/h9/' if torrentId else link - response = self.requests.get(link, headers=self.headers) + + if self.use_tor: + for proxy in self.proxies: + try: + response = requests_request(link, headers=self.headers, retries=3) + response = response.encode() + except: + self.baseUrl = f'https://www.{proxy}' + link = f'{self.baseUrl}/torrent/{torrentId}/h9/' if torrentId else link + continue + else: + break + else: + response = self.requests.get(link, headers=self.headers) return parser.infoParser(response, baseUrl=self.baseUrl) diff --git a/setup.py b/setup.py index 804a306..5973aa1 100644 --- a/setup.py +++ b/setup.py @@ -5,13 +5,13 @@ setuptools.setup( name="1337x", - version="1.2.4", + version="1.0.0-tor", author="Hemanta Pokharel", author_email="hemantapkh@yahoo.com", description="Unofficial API of 1337x.to", long_description=readme, long_description_content_type="text/markdown", - install_requires=["requests", "bs4", "requests-cache"], + install_requires=["requests", "bs4", "requests-cache", "torpy"], url="https://github.com/hemantapkh/1337x", project_urls={ "Documentation": "https://github.com/hemantapkh/1337x/blob/main/README.md", From 535151f0cf996cbabbc19a546d4732ae04bf68ce Mon Sep 17 00:00:00 2001 From: LeGeRyChEeSe Date: Thu, 23 Feb 2023 10:43:26 +0100 Subject: [PATCH 2/7] Edit README --- README.md | 41 ++++++++++++++++++++++++++++++++++------- py1337x/py1337x.py | 5 ++--- setup.py | 2 +- 3 files changed, 37 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 79b7ae1..f82bfd9 100644 --- a/README.md +++ b/README.md @@ -19,12 +19,13 @@

-This is the unofficial API of 1337x. It supports all proxies of 1337x and almost all functions of 1337x. You can search, get trending, top and popular torrents. Furthermore, you can browse torrents of a certain category. It also supports filtering on result by category, supports sorting and caching. +This is the unofficial API of 1337x. It supports all proxies of 1337x and almost all functions of 1337x. You can search, get trending, top and popular torrents. Furthermore, you can browse torrents of a certain category. It also supports filtering on result by category, supports sorting and caching. Tor requests are now supported !

## Table of Contents - [Installation](#installation) - [Start Guide](#start-guide) + - [Tor Requests (NEW)](#new--tor-requests) - [Quick Examples](#quick-examples) - [Searching Torrents](#1-searching-torrents) - [Getting Trending Torrents](#2-getting-trending-torrents) @@ -39,18 +40,40 @@ This is the unofficial API of 1337x. It supports all proxies of 1337x and almost - [License](#license) ## Installation -- Install via [PyPi](https://www.pypi.org/project/1337x) - ```bash - pip install 1337x - ``` - Install from the source ```bash - git clone https://github.com/hemantapkh/1337x && cd 1337x && python setup.py sdist && pip install dist/* + git clone https://github.com/hemantapkh/1337x && cd 1337x && git branch tor && python setup.py sdist && pip install dist/* ``` ## Start guide +### Tor Requests (NEW) + +#### Example of use + +```python +from py1337x import py1337x + +# Initialize Connection Instance +# It's not actually saving cache of any requests when using Tor +torrents = py1337x(use_tor=True) + +# Or +torrents = py1337x(proxy='1337x.to', use_tor=True) + +# Make a search from any country will works but it take a long time to execute +# Because it's making requests on each proxy via Tor until one proxy is working. +# All the methods are required the same parameters as usual. +search = torrents.search('harry potter') + +# All methods are available to use with Tor +info = torrents.info(link='https://www.1337xx.to/torrent/258188/h9/') + +# Or +info = torrents.info(torrentId='258188') +``` + ### Quick Examples #### 1. Searching torrents @@ -126,7 +149,9 @@ torrents = py1337x(proxy='1337x.st', cookie='', cache='py1337xCache', ca **Proxy** -If the default domain is banned in your country, you can use an alternative domain of 1337x. +If the default domain is banned in your country, you can use an alternative domain of 1337x, or you can use the new [Tor Request](#tor-requests-new) system. + +All categories are now accessible via the `py1337x.proxies` attribute. - [`1337x.to`](https://1337x.to) (**default**) - [`1337x.tw`](https://www.1337x.tw) @@ -202,6 +227,8 @@ torrents.info(link or torrentId) | Get information of a torrent ### Available categories +All categories are now accessible via the `py1337x.categories` attribute. + - `'movies'` - `'tv'` - `'games'` diff --git a/py1337x/py1337x.py b/py1337x/py1337x.py index 667a2ae..d2b00ec 100644 --- a/py1337x/py1337x.py +++ b/py1337x/py1337x.py @@ -1,11 +1,10 @@ import requests import requests_cache from py1337x import parser -from torpy.http.requests import TorRequests, tor_requests_session, do_request as requests_request -from torpy.utils import recv_all +from torpy.http.requests import do_request as requests_request class py1337x(): def __init__(self, proxy=None, cookie=None, cache=None, cacheTime=86400, backend='sqlite', use_tor=False): - self.baseUrl = f'https://www.{proxy}' if proxy else 'https://www.1377x.to' + self.baseUrl = f'https://www.{proxy}' if proxy else 'https://www.1337x.to' self.headers = { 'user-agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:88.0) Gecko/20100101 Firefox/88.0', 'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8', diff --git a/setup.py b/setup.py index 5973aa1..a471643 100644 --- a/setup.py +++ b/setup.py @@ -14,7 +14,7 @@ install_requires=["requests", "bs4", "requests-cache", "torpy"], url="https://github.com/hemantapkh/1337x", project_urls={ - "Documentation": "https://github.com/hemantapkh/1337x/blob/main/README.md", + "Documentation": "https://github.com/hemantapkh/1337x/blob/tor/README.md", "Issue tracker": "https://github.com/hemantapkh/1337x/issues", }, packages=setuptools.find_packages(), From d9c67625de35819b82bc466794152e08f44b9729 Mon Sep 17 00:00:00 2001 From: LeGeRyChEeSe Date: Tue, 28 Feb 2023 10:12:29 +0100 Subject: [PATCH 3/7] First Commit --- README.md | 120 ++++++++++++++++++++++++++++++++++-------- py1337x/parser.py | 10 +--- py1337x/py1337x.py | 126 ++++++++++++++------------------------------- setup.py | 2 +- 4 files changed, 142 insertions(+), 116 deletions(-) diff --git a/README.md b/README.md index f82bfd9..a3d0425 100644 --- a/README.md +++ b/README.md @@ -19,13 +19,14 @@

-This is the unofficial API of 1337x. It supports all proxies of 1337x and almost all functions of 1337x. You can search, get trending, top and popular torrents. Furthermore, you can browse torrents of a certain category. It also supports filtering on result by category, supports sorting and caching. Tor requests are now supported ! +This is the unofficial API of 1337x. It supports all proxies of 1337x and almost all functions of 1337x. You can search, get trending, top and popular torrents. Furthermore, you can browse torrents of a certain category. It also supports filtering on result by category, supports sorting and caching. Tor requests are now integrated with no more action to do. Works great and smoothly !

## Table of Contents - [Installation](#installation) - [Start Guide](#start-guide) - - [Tor Requests (NEW)](#new--tor-requests) + - [Installation of Tor (NEW) **LINUX ONLY**](#installation-of-tor-new) + - [Requirements](#requirements) - [Quick Examples](#quick-examples) - [Searching Torrents](#1-searching-torrents) - [Getting Trending Torrents](#2-getting-trending-torrents) @@ -43,35 +44,110 @@ This is the unofficial API of 1337x. It supports all proxies of 1337x and almost - Install from the source ```bash - git clone https://github.com/hemantapkh/1337x && cd 1337x && git branch tor && python setup.py sdist && pip install dist/* + git clone https://github.com/hemantapkh/1337x && cd 1337x && git branch tor && python setup.py sdist && pip install dist/* && sudo apt-get install tor build-essential libssl-dev libffi-dev python-dev ``` ## Start guide -### Tor Requests (NEW) +### Installation of Tor (NEW) **LINUX ONLY** -#### Example of use +#### Requirements + +1. If you have installed [py1337x](https://github.com/hemantapkh/1337x) from *pip*, then type this command into a console (If you have builded [py1337x](https://github.com/hemantapkh/1337x) from the *source* then you should skip this step) +```bash +sudo apt-get install tor +``` +2. Generate a password that you should store at a **safe place** and remember it +```bash +tor --hash-password your-password +``` +3. **Copy** the output of the previous command, it should looks like +```bash +16:05B7B9E8F3D0AB3160E030928F9517EDA5348ECD1CDCE2D95F0D230016 +``` + +4. Configure the Tor controller to permit identity renewall requests +```bash +sudo nano /etc/tor/torrc +``` +5. Uncomment those three lines +```bash +ControlPort 9051 +CookieAuthentication 1 +HashedControlPassword +``` +6. **Paste** the hashed password you previously copied next to **HashedControlPassword**. If there is a password already, replace it with the newer. Now it should looks like +```bash +ControlPort 9051 +CookieAuthentication 1 +HashedControlPassword 16:05B7B9E8F3D0AB3160E030928F9517EDA5348ECD1CDCE2D95F0D230016 +``` +7. Save and exit the file and now it's time to start **Tor** service +```bash +sudo service tor start +``` +8. If you did all well then you can run the following command from a terminal to check if it works +```bash +curl --socks5 localhost:9050 --socks5-hostname localhost:9050 -s https://check.torproject.org/ | cat | grep -m 1 Congratulations | xargs +``` +- This command will display +```bash +Congratulations. This browser is configured to use Tor. +``` + +### Knowns Issues + + +#### You can't perform any Search + +- The reason is probably because your Tor IP has been detected has SPAM so the solution is to reset a new Tor IP ```python -from py1337x import py1337x +>>> from py1337x import py1337x -# Initialize Connection Instance -# It's not actually saving cache of any requests when using Tor -torrents = py1337x(use_tor=True) +# Trying with 11337x.st proxy but we don't get any info of the torrent +>>> torrents = py1337x('1337x.to') +>>> torrents.search('harry potter') +None # Or possibly some errors -# Or -torrents = py1337x(proxy='1337x.to', use_tor=True) +# Try to do the following +>>> torrents.getNewIp(passwd) +# passwd parameter is the clear password you've set in the Installation of Tor at the beginning of this guide. +# CLEAR password, not Hashed one. -# Make a search from any country will works but it take a long time to execute -# Because it's making requests on each proxy via Tor until one proxy is working. -# All the methods are required the same parameters as usual. -search = torrents.search('harry potter') +# Then it should fix the issue temporarly until you need to renew the Tor IP again +# Of course you can do a for loop with many checks before you renew the IP +>>> torrents.search('harry potter') +{'items': [...], 'currentPage': 1, 'itemCount': 20, 'pageCount': 50} +``` + +#### You can't get Info of a torrent -# All methods are available to use with Tor -info = torrents.info(link='https://www.1337xx.to/torrent/258188/h9/') +- You should call this method once if you're getting no torrents for a while +```python +torrents.setNewProxy(other_proxy) +``` +- If you don't want to do it manually so you can do a for loop in the new attribute `torrents.proxies` which is a list +```python +>>> from py1337x import py1337x -# Or -info = torrents.info(torrentId='258188') +# Trying with 11337x.st proxy but we don't get any info of the torrent +>>> torrents = py1337x('11337x.st') +>>> torrents.info(torrentId=258188) +{'items': [], 'currentPage': 0, 'itemCount': 0, 'pageCount': 0} + +# We can do a for loop to try every proxy until one returns the infos of the torrent. +# Useful when you don't remember which proxy you've used for searching or getting a torrent. +>>> for proxy in torrents.proxies: +>>> torrents.setNewProxy(proxy) +>>> torrents.info(torrentId=258188) +# Possible Output +{'items': [], 'currentPage': 0, 'itemCount': 0, 'pageCount': 0} +{'items': [], 'currentPage': 0, 'itemCount': 0, 'pageCount': 0} +. +. +. +{'items': [...], 'currentPage': 1, 'itemCount': 20, 'pageCount': 50} # So we've finally got our torrent data ``` ### Quick Examples @@ -151,7 +227,7 @@ torrents = py1337x(proxy='1337x.st', cookie='', cache='py1337xCache', ca If the default domain is banned in your country, you can use an alternative domain of 1337x, or you can use the new [Tor Request](#tor-requests-new) system. -All categories are now accessible via the `py1337x.proxies` attribute. +All categories are now accessible via the `torrents.proxies` attribute. - [`1337x.to`](https://1337x.to) (**default**) - [`1337x.tw`](https://www.1337x.tw) @@ -224,10 +300,12 @@ torrents.top() | Get top torrents | self,
category (optional): torrents.popular(category) | Get popular torrents | self,
category: [category](#available-categories),
week (Defaults to False): `True for weekely, False for daily` torrents.browse(category) | Browse browse of certain category | self,
category: [category](#available-categories),
page (Defaults to 1): `Page to view` torrents.info(link or torrentId) | Get information of a torrent | self,
link: `Link of a torrent` or
torrentId: `ID of a torrent` +torrents.setNewProxy(proxy) | Set a new proxy for the instance | self,
proxy: `Proxy string of type '1337x.to'` +torrents.getNewIp(passwd) | Set a new IP for Tor requests | self,
passwd: `Clear Password set in` [Requirements (2./3.)](#requirements) ### Available categories -All categories are now accessible via the `py1337x.categories` attribute. +All categories are now accessible via the `torrents.categories` attribute. - `'movies'` - `'tv'` diff --git a/py1337x/parser.py b/py1337x/parser.py index 533e38c..3169d51 100644 --- a/py1337x/parser.py +++ b/py1337x/parser.py @@ -2,10 +2,7 @@ def torrentParser(response, baseUrl, page=1): - if isinstance(response, bytes): - soup = BeautifulSoup(response, 'html.parser') - else: - soup = BeautifulSoup(response.content, 'html.parser') + soup = BeautifulSoup(response.content, 'html.parser') torrentList = soup.select('a[href*="/torrent/"]') seedersList = soup.select('td.coll-2') @@ -60,10 +57,7 @@ def torrentParser(response, baseUrl, page=1): def infoParser(response, baseUrl): - if isinstance(response, bytes): - soup = BeautifulSoup(response, 'html.parser') - else: - soup = BeautifulSoup(response.content, 'html.parser') + soup = BeautifulSoup(response.content, 'html.parser') name = soup.find('div', {'class': 'box-info-heading clearfix'}) name = name.text.strip() if name else None diff --git a/py1337x/py1337x.py b/py1337x/py1337x.py index d2b00ec..6843e2f 100644 --- a/py1337x/py1337x.py +++ b/py1337x/py1337x.py @@ -1,17 +1,16 @@ import requests import requests_cache from py1337x import parser -from torpy.http.requests import do_request as requests_request +from fake_useragent import UserAgent +from stem import Signal +from stem.control import Controller class py1337x(): - def __init__(self, proxy=None, cookie=None, cache=None, cacheTime=86400, backend='sqlite', use_tor=False): + def __init__(self, proxy=None, cookie=None, cache=None, cacheTime=86400, backend='sqlite'): self.baseUrl = f'https://www.{proxy}' if proxy else 'https://www.1337x.to' self.headers = { - 'user-agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:88.0) Gecko/20100101 Firefox/88.0', - 'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8', - 'accept-language': 'en-US,en;q=0.5', - 'upgrade-insecure-requests': '1', - 'te': 'trailers' + 'User-Agent': UserAgent().random } + self.tor_proxies = {'http': 'socks5h://127.0.0.1:9050', 'https': 'socks5h://127.0.0.1:9050'} self.proxies = ['1337x.to', '1337x.tw', '1377x.to', '1337xx.to', '1337x.st', 'x1337x.ws', 'x1337x.eu', 'x1337x.se', '1337x.is', '1337x.gd'] self.categories = ['movies', 'tv', 'games', 'music', 'apps', 'anime', 'documentaries', 'xxx', 'others'] @@ -19,7 +18,34 @@ def __init__(self, proxy=None, cookie=None, cache=None, cacheTime=86400, backend self.headers['cookie'] = f'cf_clearance={cookie}' self.requests = requests_cache.CachedSession(cache, expire_after=cacheTime, backend=backend) if cache else requests - self.use_tor = use_tor + + #: Define a New proxy + def setNewProxy(self, proxy: str): + """ + Define a new proxy for requests only if the original proxy didn't work + + Parameters + ---------- + proxy: :class:`str` + Proxy of type '1337x.to' + """ + self.baseUrl = f'https://www.{proxy}' + + #: Get New Tor IP if too many requests + def getNewIp(self, passwd: str): + """ + Define a new Tor IP if you can't access a proxy at all because of it's thinking you're actually spamming. + + If you actually do, so please don't, thanks. + + Parameters + ---------- + passwd: :class:`str` + Clear password of Tor Controller (it's never stored anywhere) + """ + with Controller.from_port(port = 9051) as controller: + controller.authenticate(passwd) + controller.signal(Signal.NEWNYM) #: Searching torrents def search(self, query, page=1, category=None, sortBy=None, order='desc'): @@ -27,19 +53,7 @@ def search(self, query, page=1, category=None, sortBy=None, order='desc'): category = category.upper() if category and category.lower() in ['xxx', 'tv'] else category.capitalize() if category else None url = f"{self.baseUrl}/{'sort-' if sortBy else ''}{'category-' if category else ''}search/{query}/{category+'/' if category else ''}{sortBy.lower()+'/' if sortBy else ''}{order.lower()+'/' if sortBy else ''}{page}/" - if self.use_tor: - for proxy in self.proxies: - try: - response = requests_request(url, headers=self.headers, retries=1) - response = response.encode() - except: - self.baseUrl = f'https://www.{proxy}' - url = f"{self.baseUrl}/{'sort-' if sortBy else ''}{'category-' if category else ''}search/{query}/{category+'/' if category else ''}{sortBy.lower()+'/' if sortBy else ''}{order.lower()+'/' if sortBy else ''}{page}/" - continue - else: - break - else: - response = self.requests.get(url, headers=self.headers) + response = self.requests.get(url, headers=self.headers, proxies=self.tor_proxies) return parser.torrentParser(response, baseUrl=self.baseUrl, page=page) @@ -47,19 +61,7 @@ def search(self, query, page=1, category=None, sortBy=None, order='desc'): def trending(self, category=None, week=False): url = f"{self.baseUrl}/trending{'-week' if week and not category else ''}{'/w/'+category.lower()+'/' if week and category else '/d/'+category.lower()+'/' if not week and category else ''}" - if self.use_tor: - for proxy in self.proxies: - try: - response = requests_request(url, headers=self.headers, retries=1) - response = response.encode() - except: - self.baseUrl = f'https://www.{proxy}' - url = f"{self.baseUrl}/trending{'-week' if week and not category else ''}{'/w/'+category.lower()+'/' if week and category else '/d/'+category.lower()+'/' if not week and category else ''}" - continue - else: - break - else: - response = self.requests.get(url, headers=self.headers) + response = self.requests.get(url, headers=self.headers, proxies=self.tor_proxies) return parser.torrentParser(response, baseUrl=self.baseUrl) @@ -68,19 +70,7 @@ def top(self, category=None): category = 'applications' if category and category.lower() == 'apps' else 'television' if category and category.lower() == 'tv' else category.lower() if category else None url = f"{self.baseUrl}/top-100{'-'+category if category else ''}" - if self.use_tor: - for proxy in self.proxies: - try: - response = requests_request(url, headers=self.headers, retries=1) - response = response.encode() - except: - self.baseUrl = f'https://www.{proxy}' - url = f"{self.baseUrl}/top-100{'-'+category if category else ''}" - continue - else: - break - else: - response = self.requests.get(url, headers=self.headers) + response = self.requests.get(url, headers=self.headers, proxies=self.tor_proxies) return parser.torrentParser(response, baseUrl=self.baseUrl) @@ -88,19 +78,7 @@ def top(self, category=None): def popular(self, category, week=False): url = f"{self.baseUrl}/popular-{category.lower()}{'-week' if week else ''}" - if self.use_tor: - for proxy in self.proxies: - try: - response = requests_request(url, headers=self.headers, retries=1) - response = response.encode() - except: - self.baseUrl = f'https://www.{proxy}' - url = f"{self.baseUrl}/popular-{category.lower()}{'-week' if week else ''}" - continue - else: - break - else: - response = self.requests.get(url, headers=self.headers) + response = self.requests.get(url, headers=self.headers, proxies=self.tor_proxies) return parser.torrentParser(response, baseUrl=self.baseUrl) @@ -109,19 +87,7 @@ def browse(self, category, page=1): category = category.upper() if category.lower() in ['xxx', 'tv'] else category.capitalize() url = f'{self.baseUrl}/cat/{category}/{page}/' - if self.use_tor: - for proxy in self.proxies: - try: - response = requests_request(url, headers=self.headers, retries=1) - response = response.encode() - except: - self.baseUrl = f'https://www.{proxy}' - url = f'{self.baseUrl}/cat/{category}/{page}/' - continue - else: - break - else: - response = self.requests.get(url, headers=self.headers) + response = self.requests.get(url, headers=self.headers, proxies=self.tor_proxies) return parser.torrentParser(response, baseUrl=self.baseUrl, page=page) @@ -134,18 +100,6 @@ def info(self, link=None, torrentId=None): link = f'{self.baseUrl}/torrent/{torrentId}/h9/' if torrentId else link - if self.use_tor: - for proxy in self.proxies: - try: - response = requests_request(link, headers=self.headers, retries=3) - response = response.encode() - except: - self.baseUrl = f'https://www.{proxy}' - link = f'{self.baseUrl}/torrent/{torrentId}/h9/' if torrentId else link - continue - else: - break - else: - response = self.requests.get(link, headers=self.headers) + response = self.requests.get(link, headers=self.headers, proxies=self.tor_proxies) return parser.infoParser(response, baseUrl=self.baseUrl) diff --git a/setup.py b/setup.py index a471643..4a894e3 100644 --- a/setup.py +++ b/setup.py @@ -11,7 +11,7 @@ description="Unofficial API of 1337x.to", long_description=readme, long_description_content_type="text/markdown", - install_requires=["requests", "bs4", "requests-cache", "torpy"], + install_requires=["requests", "requests[socks]", "requests[security]", "bs4", "requests-cache", "fake_useragent", "stem"], url="https://github.com/hemantapkh/1337x", project_urls={ "Documentation": "https://github.com/hemantapkh/1337x/blob/tor/README.md", From d9549e872029e55c4da55999b44fd0f7d5ae5d54 Mon Sep 17 00:00:00 2001 From: LeGeRyChEeSe Date: Tue, 28 Feb 2023 10:46:01 +0100 Subject: [PATCH 4/7] README --- setup.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/setup.py b/setup.py index 4a894e3..bf6fc54 100644 --- a/setup.py +++ b/setup.py @@ -6,13 +6,13 @@ setuptools.setup( name="1337x", version="1.0.0-tor", - author="Hemanta Pokharel", - author_email="hemantapkh@yahoo.com", - description="Unofficial API of 1337x.to", + author="LeGeRyChEeSe", + author_email="kilian.douarinou41@gmail.com", + description="Unofficial API of 1337x.to with Tor implementation", long_description=readme, long_description_content_type="text/markdown", install_requires=["requests", "requests[socks]", "requests[security]", "bs4", "requests-cache", "fake_useragent", "stem"], - url="https://github.com/hemantapkh/1337x", + url="https://github.com/LeGeRyChEeSe/1337x", project_urls={ "Documentation": "https://github.com/hemantapkh/1337x/blob/tor/README.md", "Issue tracker": "https://github.com/hemantapkh/1337x/issues", From 3eb1e1246e122b55737e1609de0d9994ce3b6360 Mon Sep 17 00:00:00 2001 From: LeGeRyChEeSe Date: Tue, 28 Feb 2023 10:54:55 +0100 Subject: [PATCH 5/7] Custom Setup --- README.md | 43 ++++++++++++++++--------------------------- setup.py | 4 ++-- 2 files changed, 18 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index a3d0425..ceb6995 100644 --- a/README.md +++ b/README.md @@ -1,25 +1,19 @@ -

✖️Unofficial Python API Wrapper of 1337x

+

✖️Unofficial Python Custom API Wrapper of 1337x

-1337x +1337x

- - + + +Stars - - - - - -Stars - - -Issues + +Issues

-This is the unofficial API of 1337x. It supports all proxies of 1337x and almost all functions of 1337x. You can search, get trending, top and popular torrents. Furthermore, you can browse torrents of a certain category. It also supports filtering on result by category, supports sorting and caching. Tor requests are now integrated with no more action to do. Works great and smoothly ! +This is the unofficial custom API of 1337x. It supports all proxies of 1337x and almost all functions of 1337x. You can search, get trending, top and popular torrents. Furthermore, you can browse torrents of a certain category. It also supports filtering on result by category, supports sorting and caching. Tor requests are now integrated with no more action to do. Works great and smoothly !

## Table of Contents @@ -44,50 +38,45 @@ This is the unofficial API of 1337x. It supports all proxies of 1337x and almost - Install from the source ```bash - git clone https://github.com/hemantapkh/1337x && cd 1337x && git branch tor && python setup.py sdist && pip install dist/* && sudo apt-get install tor build-essential libssl-dev libffi-dev python-dev + git clone https://github.com/LeGeRyChEeSe/1337x.git && cd 1337x && python setup.py sdist && pip install dist/* && sudo apt-get install tor build-essential libssl-dev libffi-dev python-dev ``` ## Start guide ### Installation of Tor (NEW) **LINUX ONLY** - #### Requirements -1. If you have installed [py1337x](https://github.com/hemantapkh/1337x) from *pip*, then type this command into a console (If you have builded [py1337x](https://github.com/hemantapkh/1337x) from the *source* then you should skip this step) -```bash -sudo apt-get install tor -``` -2. Generate a password that you should store at a **safe place** and remember it +1. Generate a password that you should store at a **safe place** and remember it ```bash tor --hash-password your-password ``` -3. **Copy** the output of the previous command, it should looks like +2. **Copy** the output of the previous command, it should looks like ```bash 16:05B7B9E8F3D0AB3160E030928F9517EDA5348ECD1CDCE2D95F0D230016 ``` -4. Configure the Tor controller to permit identity renewall requests +3. Configure the Tor controller to permit identity renewall requests ```bash sudo nano /etc/tor/torrc ``` -5. Uncomment those three lines +4. Uncomment those three lines ```bash ControlPort 9051 CookieAuthentication 1 HashedControlPassword ``` -6. **Paste** the hashed password you previously copied next to **HashedControlPassword**. If there is a password already, replace it with the newer. Now it should looks like +5. **Paste** the hashed password you previously copied next to **HashedControlPassword**. If there is a password already, replace it with the newer. Now it should looks like ```bash ControlPort 9051 CookieAuthentication 1 HashedControlPassword 16:05B7B9E8F3D0AB3160E030928F9517EDA5348ECD1CDCE2D95F0D230016 ``` -7. Save and exit the file and now it's time to start **Tor** service +6. Save and exit the file and now it's time to start **Tor** service ```bash sudo service tor start ``` -8. If you did all well then you can run the following command from a terminal to check if it works +7. If you did all well then you can run the following command from a terminal to check if it works ```bash curl --socks5 localhost:9050 --socks5-hostname localhost:9050 -s https://check.torproject.org/ | cat | grep -m 1 Congratulations | xargs ``` diff --git a/setup.py b/setup.py index bf6fc54..c929f2e 100644 --- a/setup.py +++ b/setup.py @@ -14,8 +14,8 @@ install_requires=["requests", "requests[socks]", "requests[security]", "bs4", "requests-cache", "fake_useragent", "stem"], url="https://github.com/LeGeRyChEeSe/1337x", project_urls={ - "Documentation": "https://github.com/hemantapkh/1337x/blob/tor/README.md", - "Issue tracker": "https://github.com/hemantapkh/1337x/issues", + "Documentation": "https://github.com/LeGeRyChEeSe/1337x/blob/main/README.md", + "Issue tracker": "https://github.com/LeGeRyChEeSe/1337x/pulls", }, packages=setuptools.find_packages(), classifiers=[ From 94bba8d4df9c3d60a52b2cd99259c763a871df7b Mon Sep 17 00:00:00 2001 From: LeGeRyChEeSe Date: Wed, 1 Mar 2023 03:52:13 +0100 Subject: [PATCH 6/7] Version fix --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index c929f2e..02b5eb4 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setuptools.setup( name="1337x", - version="1.0.0-tor", + version="1.0.0.tor", author="LeGeRyChEeSe", author_email="kilian.douarinou41@gmail.com", description="Unofficial API of 1337x.to with Tor implementation", From ebcd128696818775a9b883b945c365fb13d27a7d Mon Sep 17 00:00:00 2001 From: LeGeRyChEeSe Date: Wed, 1 Mar 2023 04:01:35 +0100 Subject: [PATCH 7/7] Version fix --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 02b5eb4..86a32c2 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setuptools.setup( name="1337x", - version="1.0.0.tor", + version="1.0.0", author="LeGeRyChEeSe", author_email="kilian.douarinou41@gmail.com", description="Unofficial API of 1337x.to with Tor implementation",