Esempio n. 1
0
class Main(Module):

    pattern = re.compile(r"^(?:search|g(?:oog(?:le)?)?)\s+(.+)\s*$", re.I)
    require_addressing = True
    help = u"(g[oog[le]]|search) <query> - Will return 3 first results"
    error = u"not so lucky today.."

    def init(self):
        self.google = Google()

    def response(self, nick, args, kwargs):
        query = args[0]
        sopa = getsoup(self.google.find(query))

        contador = 1  # Yay for the mexican dev
        myretval = u""

        for li in sopa.body("div", {"id": "ires"})[0].ol("li", {"class": "g"}):
            if contador > 3:
                break
            name = strip_html(decode(li.b.renderContents()))
            urlpluscrap = li.a["href"].replace("/url?q=", "")
            url = urlpluscrap.split("&sa")[0]
            myretval += u"{}: {} \n".format(name, url)
            contador += 1

        return myretval
Esempio n. 2
0
class Main(Module):

    pattern = re.compile(r'^\s*sing\s+(.+?)\s*$', re.I)
    help = 'sing <song/artist/lyric>'
    error = "Couldn't find them, they must suck"

    def init(self):
        self.google = Google()

    def response(self, nick, args, kwargs):
        try:
            url = self.google.lucky(u'site:songmeanings.net ' + args[0])
        except NonRedirectResponse:
            self.log.warn('no url for query {0!r} found from google lucky'.format(args[0]))
            return u'{nick}: {error}'.format(error=self.error, **kwargs)

        try:
            soup = getsoup(url)
            try:
                title = strip_html(soup.find('a', 'pw_title').renderContents()).strip()
            except StandardError:
                title = 'Unknown artist/song, check parsing code!'
            text = soup.find('div', id='textblock')
        except StandardError:
            self.log.warn('unable to find textblock from url {0!r} (query: {1!r})'.format(url, args[0]))
            return u'{nick}: {error}'.format(error=self.error, **kwargs)

        try:
            lyrics = decode(text.renderContents(), 'utf-8')
            return u'\n'.join(['[{}]'.format(title)] + filter(None, [line.strip() for line in strip_html(lyrics).splitlines()]))
        except StandardError:
            self.log.exception('error parsing lyrics for query: {0!r}'.format(args[0]))
            return u'{nick}: {error}'.format(error=self.error, **kwargs)
Esempio n. 3
0
class Main(Module):

    pattern = re.compile(r'^(?:search|youtube?)\s+(.+)\s*$', re.I)
    require_addressing = True
    help = u"(youtube) <query> - Uses google to guess first video match then parses the title"
    error = u'not so lucky today..'

    priority = 90
    allow_threading = True
    terminate = False

    def __init__(self, bot):
        self.google = Google()
        self.bot = bot

    def response(self, nick, args, kwargs):
        query = 'site\:youtube.com/watch '+args[0]
        #return u'{}: {}: {}'.format(nick, YOUTUBE, self.google.lucky(query))

        url = self.google.lucky(query)
        uri = urlparse(url)
        if (uri.scheme.lower() in SCHEMES and
                '.'.join(uri.netloc.lower().split('.')[-2:]) in DOMAINS and
                os.path.split(os.path.normpath(uri.path))[-1] == 'watch' and
                'v' in cgi.parse_qs(uri.query)):
            soup = getsoup(url)
            title = strip_html(decode(soup.title.renderContents())).replace(u' - YouTube', u'').strip()
            if title:
                response = u'{} - {}'.format(title, url)
                self.bot.output(response, kwargs['req'])
            else:
                return u'{} - {}'.format('Cant find youtube link, here is a google lucky search', url)
Esempio n. 4
0
class Main(Module):

    pattern = re.compile(r'^(?:search|g(?:oog(?:le)?)?)\s+(.+)\s*$', re.I)
    require_addressing = True
    help = u"(g[oog[le]]|search) <query> - i'm feeling lucky"
    error = u'not so lucky today..'

    def init(self):
        self.google = Google()

    def response(self, nick, args, kwargs):
        query = args[0]
        return u'{}: {}: {}'.format(nick, GOOGLE, self.google.lucky(query))
Esempio n. 5
0
class Main(Module):

    pattern = re.compile(r'^(?:search|g(?:oog(?:le)?)?)\s+(.+)\s*$', re.I)
    require_addressing = True
    help = u"(g[oog[le]]|search) <query> - i'm feeling lucky"
    error = u'not so lucky today..'

    def init(self):
        self.google = Google()

    def response(self, nick, args, kwargs):
        query = args[0]
        return u'{}: {}: {}'.format(nick, GOOGLE, self.google.lucky(query))
Esempio n. 6
0
class Main(Module):

    pattern = re.compile(u'^\s*google\s+(.*?)\s*$')
    require_addressing = True
    help = u"google <query> - i'm feeling lucky"
    error = u'not so lucky today..'

    def init(self):
        self.google = Google()

    def response(self, nick, args, kwargs):
        query = args[0]
        return u'%s: %s = %s' % (nick, query, self.google.lucky(query))
Esempio n. 7
0
class Main(Module):

    pattern = re.compile(u'^\s*google\s+(.*?)\s*$')
    require_addressing = True
    help = u"google <query> - i'm feeling lucky"
    error = u'not so lucky today..'

    def init(self):
        self.google = Google()

    def response(self, nick, args, kwargs):
        query = args[0]
        return u'%s: %s = %s' % (nick, query, self.google.lucky(query))
Esempio n. 8
0
class Main(Module):

    pattern = re.compile(r"^\s*sing\s+(.+?)\s*$", re.I)
    help = "sing <song/artist>"
    baseurl = u"http://lyrics.wikia.com/"
    searchurl = urljoin(baseurl, u"/Special:Search")
    _br = r"\s*<br\s*/?\s*>\s*"
    _line_break = re.compile(_br, re.I)
    _verse_break = re.compile(_br * 2, re.I)
    error = "Couldn't find them, they must suck"

    def init(self):
        self.google = Google()

    def normalize(self, lyrics):
        verses = self._verse_break.split(lyrics)
        verses = [self._line_break.sub(" / ", verse) for verse in verses]
        verses = [strip_html(verse) for verse in verses]
        return "\n".join(verses).strip()

    def response(self, nick, args, kwargs):
        try:
            url = self.google.lucky(u"site:lyrics.wikia.com " + args[0])
        except NonRedirectResponse:
            opts = {"search": args[0], "ns0": 1}
            soup = getsoup(self.searchurl, referer=self.baseurl, opts=opts)
            url = urljoin(self.baseurl, soup.li.a["href"])
        soup = getsoup(url, referer=self.baseurl)
        title = self.render(soup.title).split(" - LyricWiki")[0]
        title = title.replace(":", " - ")
        title = title.replace("_", " ")
        lyrics = soup.find("div", "lyricbox")
        for spam in lyrics("div", "rtMatcher"):
            spam.extract()
        lyrics = self.render(lyrics)
        lyrics = self.normalize(lyrics)
        if not lyrics or lyrics == "None":
            raise ValueError("no results")
        return u"%s:\n%s" % (title, lyrics)

    def render(self, node):
        return node.renderContents().decode("utf-8", "ignore")
Esempio n. 9
0
class Main(Module):

    pattern = re.compile(r'^\s*sing\s+(.+?)\s*$', re.I)
    help = 'sing <song/artist>'
    baseurl = u'http://lyrics.wikia.com/'
    searchurl = urljoin(baseurl, u'/Special:Search')
    _br = r'\s*<br\s*/?\s*>\s*'
    _line_break = re.compile(_br, re.I)
    _verse_break = re.compile(_br * 2, re.I)
    error = "Couldn't find them, they must suck"

    def init(self):
        self.google = Google()

    def normalize(self, lyrics):
        verses = self._verse_break.split(lyrics)
        verses = [self._line_break.sub(' / ', verse) for verse in verses]
        verses = [strip_html(verse) for verse in verses]
        return '\n'.join(verses).strip()

    def response(self, nick, args, kwargs):
        try:
            url = self.google.lucky(u'site:lyrics.wikia.com ' + args[0])
        except NonRedirectResponse:
            opts = {'search': args[0], 'ns0': 1}
            soup = getsoup(self.searchurl, referer=self.baseurl, opts=opts)
            url = urljoin(self.baseurl, soup.li.a['href'])
        soup = getsoup(url, referer=self.baseurl)
        title = self.render(soup.title).split(' - LyricWiki')[0]
        title = title.replace(':', ' - ')
        title = title.replace('_', ' ')
        lyrics = soup.find('div', 'lyricbox')
        for spam in lyrics('div', 'rtMatcher'):
            spam.extract()
        lyrics = self.render(lyrics)
        lyrics = self.normalize(lyrics)
        if not lyrics or lyrics == 'None':
            raise ValueError('no results')
        return u'%s:\n%s' % (title, lyrics)

    def render(self, node):
        return decode(node.renderContents(), 'utf-8')
Esempio n. 10
0
class Main(Module):

    pattern = re.compile(r'^\s*sing\s+(.+?)\s*$', re.I)
    help = 'sing <song/artist>'
    baseurl = u'http://lyrics.wikia.com/'
    searchurl = urljoin(baseurl, u'/Special:Search')
    _br = r'\s*<br\s*/?\s*>\s*'
    _line_break = re.compile(_br, re.I)
    _verse_break = re.compile(_br * 2, re.I)
    error = "Couldn't find them, they must suck"

    def init(self):
        self.google = Google()

    def normalize(self, lyrics):
        verses = self._verse_break.split(lyrics)
        verses = [self._line_break.sub(' / ', verse) for verse in verses]
        verses = [strip_html(verse) for verse in verses]
        return '\n'.join(verses).strip()

    def response(self, nick, args, kwargs):
        try:
            url = self.google.lucky(u'site:lyrics.wikia.com ' + args[0])
        except NonRedirectResponse:
            opts = {'search': args[0], 'ns0': 1}
            soup = getsoup(self.searchurl, referer=self.baseurl, opts=opts)
            url = urljoin(self.baseurl, soup.li.a['href'])
        soup = getsoup(url, referer=self.baseurl)
        title = self.render(soup.title).split(' - LyricWiki')[0]
        title = title.replace(':', ' - ')
        title = title.replace('_', ' ')
        lyrics = soup.find('div', 'lyricbox')
        for spam in lyrics('div', 'rtMatcher'):
            spam.extract()
        lyrics = self.render(lyrics)
        lyrics = self.normalize(lyrics)
        if not lyrics or lyrics == 'None':
            raise ValueError('no results')
        return u'%s:\n%s' % (title, lyrics)

    def render(self, node):
        return decode(node.renderContents(), 'utf-8')
Esempio n. 11
0
class Main(Module):

    pattern = re.compile(r'^\s*sing\s+(.+?)\s*$', re.I)
    help = 'sing <song/artist/lyric>'
    error = "Couldn't find them, they must suck"

    def init(self):
        self.google = Google()

    def response(self, nick, args, kwargs):
        try:
            url = self.google.lucky(u'site:songmeanings.net ' + args[0])
        except NonRedirectResponse:
            self.log.warn(
                'no url for query {0!r} found from google lucky'.format(
                    args[0]))
            return u'{nick}: {error}'.format(error=self.error, **kwargs)

        try:
            soup = getsoup(url)
            try:
                title = strip_html(
                    soup.find('a', 'pw_title').renderContents()).strip()
            except StandardError:
                title = 'Unknown artist/song, check parsing code!'
            text = soup.find('div', id='textblock')
        except StandardError:
            self.log.warn(
                'unable to find textblock from url {0!r} (query: {1!r})'.
                format(url, args[0]))
            return u'{nick}: {error}'.format(error=self.error, **kwargs)

        try:
            lyrics = decode(text.renderContents(), 'utf-8')
            return u'\n'.join(['[{}]'.format(title)] + filter(
                None,
                [line.strip() for line in strip_html(lyrics).splitlines()]))
        except StandardError:
            self.log.exception('error parsing lyrics for query: {0!r}'.format(
                args[0]))
            return u'{nick}: {error}'.format(error=self.error, **kwargs)
Esempio n. 12
0
 def init(self):
     self.google = Google()
Esempio n. 13
0
 def __init__(self, bot):
     self.google = Google()
     self.bot = bot
Esempio n. 14
0
 def init(self):
     self.google = Google()