summaryrefslogtreecommitdiff
path: root/modules/imdb_search.py
blob: 34ba6ccf174523e1cfbe7ba63ba95be2904f8d48 (plain)
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
info = {
	'author': 'Jon Bergli Heier',
	'title': 'IMDB',
	'description': 'IMDB search',
}

import imdb

class Module:
	def __init__(self, bot):
		self.irc = bot
		self.irc.register_keyword('!imdb', self)
		self.ia = imdb.IMDb()

	def keyword(self, nick, channel, kw, msg):
		target = channel if not channel == self.irc.nickname else nick.split('!')[0]
		args = msg.split()
		if len(args) == 0:
			self.irc.msg(target, 'Usage: !imdb search')
			return
		results = self.ia.search_movie(' '.join(args))
		if len(results):
			m = results[0]
			self.ia.update(m)
			s = u'\002%s\002 (%d) %s/10 | %s' % (m['title'], m['year'], ('%.1f' % m['rating']) if 'rating' in m else '?', self.ia.get_imdbURL(m))
			self.irc.msg(target, s.encode('utf-8'))
		else:
			self.irc.msg(target, 'imdb: No results.')