Skip to content

Commit

Permalink
Adding sfw filter to tph module and updating readme
Browse files Browse the repository at this point in the history
  • Loading branch information
philhabell authored and philhabell committed Oct 26, 2020
1 parent 7b2e338 commit 6bae386
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
3 changes: 2 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ Options
-f --filter=<str> Match text or regular expression in the torrent name.
-n --results=<n> Number of results to retrieve.
-S --sort-type=<type> Sort torrents by name/seeds [default: seeds].
-c --config=<file> Load config file.
-c --config=<file> Load config file
--sfw restrict results to safe for work content (the_pirate_bay only)
===================== =====================================================

Video options
Expand Down
7 changes: 5 additions & 2 deletions we_get/modules/the_pirate_bay.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
BASE_URL = "https://www1.thepiratebay3.to"
SEARCH_LOC = "/s/?q="
LIST_LOC = "/top/all"

SFW_FILTER = "&audio=on&video=on&apps=on&games=on&other=on&category=0"

class the_pirate_bay(object):
""" the_pirate_bay module for we-get.
Expand All @@ -24,6 +24,7 @@ def __init__(self, pargs):
self.module = Module()
self.parse_pargs()
self.items = dict()
self.filter = ""

def parse_pargs(self):
for opt in self.pargs:
Expand All @@ -32,6 +33,8 @@ def parse_pargs(self):
self.search_query = self.pargs[opt][0].replace(' ', '-')
elif opt == "--list":
self.action = "list"
if opt == "--sfw":
self.filter = SFW_FILTER

def _parse_data(self, data):
soup = BeautifulSoup(data, 'html.parser')
Expand All @@ -55,7 +58,7 @@ def _parse_data(self, data):
})

def search(self):
url = f"{BASE_URL}{SEARCH_LOC}{self.search_query}"
url = f"{BASE_URL}{SEARCH_LOC}{self.search_query}{self.filter}"
data = self.module.http_get_request(url)
self._parse_data(data)
return self.items
Expand Down

0 comments on commit 6bae386

Please sign in to comment.