Skip to content

Commit

Permalink
Add horriblesubs episode thingy
Browse files Browse the repository at this point in the history
  • Loading branch information
maxpowa committed Feb 17, 2015
1 parent 5017b0c commit 4c49798
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions horrible.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# coding=utf8
"""
horrible.py - Yeah. The code is horrible too
Copyright 2015 Max Gurela
Licensed under the Eiffel Forum License 2.
"""

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

0 comments on commit 4c49798

Please sign in to comment.