forked from maxpowa/inumuta-modules
-
Notifications
You must be signed in to change notification settings - Fork 0
/
horrible.py
47 lines (39 loc) · 1.51 KB
/
horrible.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# coding=utf8
"""
horrible.py - Yeah. The code is horrible too
Copyright 2015 Max Gurela
Licensed under the Eiffel Forum License 2.
"""
from __future__ import unicode_literals
from willie.module import commands
import re
import random
from willie import web
from bs4 import BeautifulSoup
from bs4.element import NavigableString
@commands('hs', 'horriblesubs', 'horrible')
def horrible(bot, trigger):
"""
.horrible [show] - View the latest HorribleSubs releases for any given show
"""
latest = False
query = trigger.group(2)
if not query:
latest = True
url = 'http://horriblesubs.info/lib/search.php?value={}'
if latest:
url = 'http://horriblesubs.info/lib/latest.php'
soup = BeautifulSoup(web.get(url.format(query)), 'lxml')
ep = soup.find_all('div', {'class': 'episode'})
if len(ep) > 0:
for epi in ep:
episode = ''.join([x for x in epi.contents if isinstance(x, NavigableString)])
resblock = epi.find_all('div', {'class': 'linkful resolution-block'})
resolutions = []
links = []
for res in resblock:
links.extend([link.find('a')['href'] for link in res.find_all('span', {'class': 'ind-link'}) if 'Torrent' in link.text])
resolutions.append(res.find('a', {'href': '#'}).text)
bot.say('Latest: {} | Resolutions: {} | Download: {} ({})'.format(episode, ', '.join(resolutions), links[-1], resolutions[-1]))
return
bot.say('[Horrible] No results found')