summaryrefslogtreecommitdiff
path: root/searx/engines/digbt.py
diff options
context:
space:
mode:
authorNoemi Vanyi <sitbackandwait@gmail.com>2016-08-13 14:55:47 +0200
committerNoemi Vanyi <sitbackandwait@gmail.com>2016-08-13 16:19:00 +0200
commit3a1c5876b16a51f64505c119283447b06f2a3d99 (patch)
treef2a453fb952224629a91e6fc0de03e80a0c45826 /searx/engines/digbt.py
parent104cdb7d03771d4eca5b5126532ccf47642bb9de (diff)
downloadsearxng-3a1c5876b16a51f64505c119283447b06f2a3d99.tar.gz
searxng-3a1c5876b16a51f64505c119283447b06f2a3d99.zip
add digbt engine
Unfortunately, it is quite slow so it is disabled. Furthermore, the display of number of files is wrong on digbt.org, so it is not displayed on searx.
Diffstat (limited to 'searx/engines/digbt.py')
-rw-r--r--searx/engines/digbt.py58
1 files changed, 58 insertions, 0 deletions
diff --git a/searx/engines/digbt.py b/searx/engines/digbt.py
new file mode 100644
index 000000000..c35327e8c
--- /dev/null
+++ b/searx/engines/digbt.py
@@ -0,0 +1,58 @@
+"""
+ DigBT (Videos, Music, Files)
+
+ @website https://digbt.org
+ @provide-api no
+
+ @using-api no
+ @results HTML (using search portal)
+ @stable no (HTML can change)
+ @parse url, title, content, magnetlink
+"""
+
+from urlparse import urljoin
+from lxml import html
+from searx.engines.xpath import extract_text
+from searx.utils import get_torrent_size
+
+categories = ['videos', 'music', 'files']
+paging = True
+
+URL = 'https://digbt.org'
+SEARCH_URL = URL + '/search/{query}-time-{pageno}'
+FILESIZE = 3
+FILESIZE_MULTIPLIER = 4
+
+
+def request(query, params):
+ params['url'] = SEARCH_URL.format(query=query, pageno=params['pageno'])
+
+ return params
+
+
+def response(resp):
+ dom = html.fromstring(resp.content)
+ search_res = dom.xpath('.//td[@class="x-item"]')
+
+ if not search_res:
+ return list()
+
+ results = list()
+ for result in search_res:
+ url = urljoin(URL, result.xpath('.//a[@title]/@href')[0])
+ title = result.xpath('.//a[@title]/text()')[0]
+ content = extract_text(result.xpath('.//div[@class="files"]'))
+ files_data = extract_text(result.xpath('.//div[@class="tail"]')).split()
+ filesize = get_torrent_size(files_data[FILESIZE], files_data[FILESIZE_MULTIPLIER])
+ magnetlink = result.xpath('.//div[@class="tail"]//a[@class="title"]/@href')[0]
+
+ results.append({'url': url,
+ 'title': title,
+ 'content': content,
+ 'filesize': filesize,
+ 'magnetlink': magnetlink,
+ 'seed': 'N/A',
+ 'leech': 'N/A',
+ 'template': 'torrent.html'})
+
+ return results