Commit eb182df1 authored by volth's avatar volth Committed by Alexandre Flament

[mod] restore btdigg engine as btdig.com (#1515)

parent 3b1122c5
""" """
BTDigg (Videos, Music, Files) BTDigg (Videos, Music, Files)
@website https://btdigg.org @website https://btdig.com
@provide-api yes (on demand) @provide-api yes (on demand)
@using-api no @using-api no
...@@ -21,7 +21,7 @@ categories = ['videos', 'music', 'files'] ...@@ -21,7 +21,7 @@ categories = ['videos', 'music', 'files']
paging = True paging = True
# search-url # search-url
url = 'https://btdigg.org' url = 'https://btdig.com'
search_url = url + '/search?q={search_term}&p={pageno}' search_url = url + '/search?q={search_term}&p={pageno}'
...@@ -39,7 +39,7 @@ def response(resp): ...@@ -39,7 +39,7 @@ def response(resp):
dom = html.fromstring(resp.text) dom = html.fromstring(resp.text)
search_res = dom.xpath('//div[@id="search_res"]/table/tr') search_res = dom.xpath('//div[@class="one_result"]')
# return empty array if nothing is found # return empty array if nothing is found
if not search_res: if not search_res:
...@@ -47,46 +47,39 @@ def response(resp): ...@@ -47,46 +47,39 @@ def response(resp):
# parse results # parse results
for result in search_res: for result in search_res:
link = result.xpath('.//td[@class="torrent_name"]//a')[0] link = result.xpath('.//div[@class="torrent_name"]//a')[0]
href = urljoin(url, link.attrib.get('href')) href = urljoin(url, link.attrib.get('href'))
title = extract_text(link) title = extract_text(link)
content = extract_text(result.xpath('.//pre[@class="snippet"]')[0])
content = "<br />".join(content.split("\n"))
filesize = result.xpath('.//span[@class="attr_val"]/text()')[0].split()[0] excerpt = result.xpath('.//div[@class="torrent_excerpt"]')[0]
filesize_multiplier = result.xpath('.//span[@class="attr_val"]/text()')[0].split()[1] content = html.tostring(excerpt, encoding='unicode', method='text', with_tail=False)
files = result.xpath('.//span[@class="attr_val"]/text()')[1] # it is better to emit <br/> instead of |, but html tags are verboten
seed = result.xpath('.//span[@class="attr_val"]/text()')[2] content = content.strip().replace('\n', ' | ')
content = ' '.join(content.split())
# convert seed to int if possible filesize = result.xpath('.//span[@class="torrent_size"]/text()')[0].split()[0]
if seed.isdigit(): filesize_multiplier = result.xpath('.//span[@class="torrent_size"]/text()')[0].split()[1]
seed = int(seed) files = (result.xpath('.//span[@class="torrent_files"]/text()') or ['1'])[0]
else:
seed = 0
leech = 0
# convert filesize to byte if possible # convert filesize to byte if possible
filesize = get_torrent_size(filesize, filesize_multiplier) filesize = get_torrent_size(filesize, filesize_multiplier)
# convert files to int if possible # convert files to int if possible
if files.isdigit(): try:
files = int(files) files = int(files)
else: except:
files = None files = None
magnetlink = result.xpath('.//td[@class="ttth"]//a')[0].attrib['href'] magnetlink = result.xpath('.//div[@class="torrent_magnet"]//a')[0].attrib['href']
# append result # append result
results.append({'url': href, results.append({'url': href,
'title': title, 'title': title,
'content': content, 'content': content,
'seed': seed,
'leech': leech,
'filesize': filesize, 'filesize': filesize,
'files': files, 'files': files,
'magnetlink': magnetlink, 'magnetlink': magnetlink,
'template': 'torrent.html'}) 'template': 'torrent.html'})
# return results sorted by seeder # return results sorted by seeder
return sorted(results, key=itemgetter('seed'), reverse=True) return results
...@@ -115,6 +115,10 @@ engines: ...@@ -115,6 +115,10 @@ engines:
disabled : True disabled : True
shortcut : bb shortcut : bb
- name : btdigg
engine : btdigg
shortcut : bt
- name : ccc-tv - name : ccc-tv
engine : xpath engine : xpath
paging : False paging : False
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
{% endif %} {% endif %}
<h3 class="result_title"><a href="{{ result.url }}" {% if results_on_new_tab %}target="_blank" rel="noopener noreferrer"{% else %}rel="noreferrer"{% endif %}>{{ result.title|safe }}</a></h3> <h3 class="result_title"><a href="{{ result.url }}" {% if results_on_new_tab %}target="_blank" rel="noopener noreferrer"{% else %}rel="noreferrer"{% endif %}>{{ result.title|safe }}</a></h3>
{% if result.content %}<span class="content">{{ result.content|safe }}</span><br />{% endif %} {% if result.content %}<span class="content">{{ result.content|safe }}</span><br />{% endif %}
<span class="stats">{{ _('Seeder') }} : {{ result.seed }}, {{ _('Leecher') }} : {{ result.leech }}</span><br /> {% if result.seed %}<span class="stats">{{ _('Seeder') }} : {{ result.seed }}, {{ _('Leecher') }} : {{ result.leech }}</span><br />{% endif %}
<span> <span>
{% if result.magnetlink %}<a href="{{ result.magnetlink }}" class="magnetlink">{{ _('magnet link') }}</a>{% endif %} {% if result.magnetlink %}<a href="{{ result.magnetlink }}" class="magnetlink">{{ _('magnet link') }}</a>{% endif %}
{% if result.torrentfile %}<a href="{{ result.torrentfile }}" class="torrentfile" {% if results_on_new_tab %}target="_blank" rel="noopener noreferrer"{% else %}rel="noreferrer"{% endif %}>{{ _('torrent file') }}</a>{% endif %} {% if result.torrentfile %}<a href="{{ result.torrentfile }}" class="torrentfile" {% if results_on_new_tab %}target="_blank" rel="noopener noreferrer"{% else %}rel="noreferrer"{% endif %}>{{ _('torrent file') }}</a>{% endif %}
......
...@@ -8,6 +8,6 @@ ...@@ -8,6 +8,6 @@
<p> <p>
{% if result.magnetlink %}<a href="{{ result.magnetlink }}" class="magnetlink">{{ _('magnet link') }}</a>{% endif %} {% if result.magnetlink %}<a href="{{ result.magnetlink }}" class="magnetlink">{{ _('magnet link') }}</a>{% endif %}
{% if result.torrentfile %}<a href="{{ result.torrentfile }}" {% if results_on_new_tab %}target="_blank" rel="noopener noreferrer"{% else %}rel="noreferrer"{% endif %} class="torrentfile">{{ _('torrent file') }}</a>{% endif %} - {% if result.torrentfile %}<a href="{{ result.torrentfile }}" {% if results_on_new_tab %}target="_blank" rel="noopener noreferrer"{% else %}rel="noreferrer"{% endif %} class="torrentfile">{{ _('torrent file') }}</a>{% endif %} -
<span class="stats">{{ _('Seeder') }} : {{ result.seed }}, {{ _('Leecher') }} : {{ result.leech }}</span> {% if result.seed %}<span class="stats">{{ _('Seeder') }} : {{ result.seed }}, {{ _('Leecher') }} : {{ result.leech }}</span>{% endif %}
</p> </p>
</div> </div>
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
{{ result_header(result, favicons) }} {{ result_header(result, favicons) }}
{{ result_sub_header(result) }} {{ result_sub_header(result) }}
<p class="result-content">{{ icon('transfer') }} {{ _('Seeder') }} <span class="badge">{{ result.seed }}</span> &bull; {{ _('Leecher') }} <span class="badge">{{ result.leech }}</span> {% if result.seed %}<p class="result-content">{{ icon('transfer') }} {{ _('Seeder') }} <span class="badge">{{ result.seed }}</span> &bull; {{ _('Leecher') }} <span class="badge">{{ result.leech }}</span>{% endif %}
{% if result.filesize %}<br />{{ icon('floppy-disk') }} {{ _('Filesize') }} {% if result.filesize %}<br />{{ icon('floppy-disk') }} {{ _('Filesize') }}
<span class="badge"> <span class="badge">
{% if result.filesize < 1024 %}{{ result.filesize }} {{ _('Bytes') }} {% if result.filesize < 1024 %}{{ result.filesize }} {{ _('Bytes') }}
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment