from api.weather import WeatherException
from api.steam import SteamException
+import pyva_net_rizon_acid_core_User as User
+
+RE_YT_PATTERN = re.compile(
+ "(?:www\\.|m\\.)?(?:(?:youtube\\.com/(?:watch)?(?:[?&][a-z]+=[a-z_]+)?(?:[?&]v=))"
+ "|(?:youtu\\.be\\/))([a-zA-Z0-9-_]+)")
+
+
+def onPrivmsg_regex_youtube(self, source, target, message):
+ userinfo = User.findUser(source)
+ myself = User.findUser(self.nick)
+
+ sender = userinfo['nick']
+ channel = target
+
+ yt_links = RE_YT_PATTERN.findall(message)
+
+ if yt_links and self.google._check_link_eligibility(channel, yt_links[0]):
+ try:
+ video = self.google.yt_video(yt_links[0], userip=userinfo['ip'] if userinfo['ip'] != '0' else None)
+ except:
+ # Silently die
+ return
+ self.msg(channel, "@sep @bYouTube@b %(title)s @sep (%(duration)s) @sep @bViews@b %(views)s @sep "\
+ "@bRating@b @c3@b[+]@b %(liked)s likes @c4@b[-]@b %(disliked)s dislikes @sep" % {
+ 'title': video['title'],
+ 'duration': '%s' % format_hms(video['duration']),
+ 'views': format_thousand(video['view_count']),
+ 'liked': format_thousand(video['liked']),
+ 'disliked': format_thousand(video['disliked'])
+ })
+ else:
+ return True
+
+
def get_citystate_from_zipcode(self, zipcode):
"""Return [city,state] for the given U.S. zip code (if database has been imported)"""
try:
if result is None:
self.msg(channel, '[W|A] Invalid input.')
else:
- lines = len(result[0].splitlines(True)) if result[1] is None else len(result[1].splitlines(True))
- if lines > self.output_limit:
- self.notice(sender, u'[W|A] {r[0]} = {r[1]}'.format(r=result))
+ resultLines = result[0].splitlines(True) if result[1] is None else result[1].splitlines(True)
+ lines = len(resultLines) # number of lines
+ maxLineLength = max([len(x) for x in resultLines]) # max length of lines
+
+ tosend = u'[W|A] {r[0]}'.format(r=result) # default to always show the first part
+ if result[1] is not None:
+ tosend += u' = {r[1]}'.format(r=result)
+
+ if lines > self.output_limit or maxLineLength > self.max_line_length:
+ self.notice(sender, tosend)
else:
- self.msg(channel, u'[W|A] {r[0]} = {r[1]}'.format(r=result))
+ self.msg(channel, tosend)
def command_youtube_search(self, manager, opts, arg, channel, sender, userinfo):
try:
if 'error' in reply:
self.errormsg(channel, reply['error'])
+ elif not reply['long-url']:
+ self.msg(channel, '@sep @bLong URL@b URL does not redirect')
else:
- self.msg(channel, '@sep @bLong URL@b {reply[long-url]} @sep @bContent-type@b {reply[content-type]} @sep'.format(reply=reply))
+ self.msg(channel, '@sep @bLong URL@b {reply[long-url]} @sep'.format(reply=reply))
def command_idlerpg(self, manager, opts, arg, channel, sender, userinfo):
try:
'u': 'urbandictionary',
'urbandictionary': (command_urbandictionary, ARG_YES, 'Search for a definition on Urban Dictionary', [], 'word'),
- 'g': 'google',
- 'google': (command_google_search, ARG_YES, 'Search for something on Google', [], 'google_search'),
+ # 'g': 'google',
+ # 'google': (command_google_search, ARG_YES, 'Search for something on Google', [], 'google_search'),
- 'gi': 'google_image',
- 'google_image': (command_google_image_search, ARG_YES, 'Search for images via Google Image', [], 'google_image_search'),
+ # 'gi': 'google_image',
+ # 'google_image': (command_google_image_search, ARG_YES, 'Search for images via Google Image', [], 'google_image_search'),
't': 'translate',
'translate': (command_bing_translate, ARG_YES, 'Translate something from a language to another', [], 'from to text'),
'shorten': (command_url_shorten, ARG_YES, 'Shortens a URL using http://j.mp', [], 'long_url'),
+ 'unshorten': 'expand',
'expand': (command_url_expand, ARG_YES, 'Expands a shortened URL using http://longurl.org', [], 'shortened_url'),
'irpg': 'idlerpg',