Welcome to mirror list, hosted at ThFree Co, Russian Federation.

youtube.py « plugins - github.com/isida/4.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e7ebe3d041e1c208c4cd58961b1d0cb3f10a9547 (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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/python
# -*- coding: utf-8 -*-

# --------------------------------------------------------------------------- #
#                                                                             #
#    Plugin for iSida Jabber Bot                                              #
#    Copyright (C) diSabler <dsy@dsy.name>                                    #
#                                                                             #
#    This program is free software: you can redistribute it and/or modify     #
#    it under the terms of the GNU General Public License as published by     #
#    the Free Software Foundation, either version 3 of the License, or        #
#    (at your option) any later version.                                      #
#                                                                             #
#    This program is distributed in the hope that it will be useful,          #
#    but WITHOUT ANY WARRANTY; without even the implied warranty of           #
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            #
#    GNU General Public License for more details.                             #
#                                                                             #
#    You should have received a copy of the GNU General Public License        #
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.    #
#                                                                             #
# --------------------------------------------------------------------------- #

def youtube(type, jid, nick, text):
	if '\n' in text:
		try: lim = int(text.split('\n',1)[1])
		except: lim = GT('youtube_default_videos')
		if lim > GT('youtube_max_videos'): lim = GT('youtube_max_videos')
		if lim < 1: lim = 1
		text = text.split('\n',1)[0]
	else: lim = GT('youtube_default_videos')
	req = text.lower().encode("utf-8").replace(' ','+')
	url = 'http://gdata.youtube.com/feeds/api/videos?q=%s&alt=json-in-script&callback=yt&max-results=%s&format=5'
	res = json.loads(load_page(url % (req,lim)).split('yt(',1)[1][:-2])['feed']
	if res.has_key('entry'):
		msg = L('Found:','%s/%s'%(jid,nick))
		for t in res['entry']:
			y_title = t['title']['$t']
			try: y_views = t['yt$statistics']['viewCount']
			except: y_views = ''
			y_link  = t['media$group'][u'media$player'][0]['url'].split('?v=',1)[1].split('&')[0]
			y_time  = t['media$group'][u'media$thumbnail'][0]['time'].split('.',1)[0]
			msg += unescape('\nhttp://youtu.be/%s - %s [%s] %s' % (y_link,y_title,y_time,y_views))
	else: msg = L('Not found!','%s/%s'%(jid,nick))
	send_msg(type, jid, nick, msg)

global execute

execute = [(3, 'youtube', youtube, 2, 'Search at YouTube')]