Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 17 additions & 20 deletions plugins/scene.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
"""
scene.py

Provides commands for searching scene releases using orlydb.com.
Provides commands for searching scene releases using pre.corrupt-net.org.

Created By:
- Ryan Hitchman <https://github.com/rmmh>

Modified By:
- Luke Rogers <https://github.com/lukeroge>

Converted to pre.corrupt-net.org By:
- whocares <http://github.com/whocares-openscene>

License:
GPL v3
"""

import datetime

import requests
import re
from lxml import html

from cloudbot import hook
Expand All @@ -24,37 +28,30 @@

@hook.command("pre", "scene")
def pre(text):
"""pre <query> -- searches scene releases using orlydb.com"""
"""pre <query> -- searches scene releases using pre.corrupt.org"""

try:
request = requests.get("http://orlydb.com/", params={"q": text})
headers = {'Accept-Language': 'en-US'}
request = requests.get("https://pre.corrupt-net.org/search.php", params={"search": text}, headers=headers)
request.raise_for_status()
except requests.exceptions.HTTPError as e:
return 'Unable to fetch results: {}'.format(e)
split = request.text.partition('</tr><tr>')

h = html.fromstring(request.text)

results = h.xpath("//div[@id='releases']/div/span[@class='release']/..")

if not results:
results = re.search("<tr><td id\=\"rlstype\".*>(.*)</td><td.*>&nbsp;&nbsp;(.*)<span id\=\"rlsgroup\"><font color\='#C0C0C0'>(.*)</font>.*>(\d*F).*>([\d\.]*M).*&nbsp;&nbsp;(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})</td>", split[0], flags=re.IGNORECASE)
if results is None:
return "No results found."

result = results[0]

date = result.xpath("span[@class='timestamp']/text()")[0]
section = result.xpath("span[@class='section']//text()")[0]
name = result.xpath("span[@class='release']/text()")[0]
date = results.group(6)
section = results.group(1)
name = results.group(2) + results.group(3)
size = results.group(5)
files = results.group(4)

# parse date/time
date = datetime.datetime.strptime(date, "%Y-%m-%d %H:%M:%S")
date_string = date.strftime("%d %b %Y")
since = timeformat.time_since(date)

size = result.xpath("span[@class='inforight']//text()")
if size:
size = ' - ' + size[0].split()[0]
else:
size = ''

return '{} - {}{} - {} ({} ago)'.format(section, name, size, date_string, since)
return '{} - {} - {} - {} - {} ({} ago)'.format(section, name, size, files, date_string, since)