Пример #1
0
	def setFeedUser(self,feed,user):
		key = 'feed_users_' + feed.addonID
		users = ShareSocial.getSetting(key,[])
		for u in users:
			if user.get('id') == self.decodeUser(u).get('id'): return
		users.append(self.encodeUser(user))
		ShareSocial.setSetting(key,users)
Пример #2
0
def updateStatus():
	if not ShareSocial.shareTargetAvailable('status','script.module.sharesocial'):
		xbmcgui.Dialog().ok('Failed','No status update targets available.')
		return
	share = ShareSocial.getShare('script.module.sharesocial', 'status')
	share.askMessage('Enter Status Message')
	if not share.message: return
	share.share(withall=True)
Пример #3
0
def registerAsShareTarget():
	target = ShareSocial.getShareTarget()
	target.addonID = 'script.module.sharesocial'
	target.name = 'Twitter'
	target.importPath = 'twitter_share'
	target.iconPath = os.path.join(ShareSocial.__addon__.getAddonInfo('path'),'twitter.png')
	target.shareTypes = ['status','imagefile','image','video']
	target.provideTypes = ['feed']
	ShareSocial.registerShareTarget(target)
	LOG('Registered as share target for Twitter')
Пример #4
0
	def removeFeedUser(self,feed,user):
		key = 'feed_users_' + feed.addonID
		users = ShareSocial.getSetting(key,[])
		i = 0
		for u in users:
			if self.decodeUser(u).get('id') == user.get('id'):
				users.pop(i)
				ShareSocial.setSetting(key,users)
				return
			i+=1
Пример #5
0
def handlePluginShare(args):
	sourceID = args.get('path','').split('://',1)[-1].split('/',1)[0]
	page = ''
	videoID = ''
	if 'youtube' in sourceID:
		videoID = args.get('path','').split('videoid=',1)[-1].split('&')[0]
		page = 'http://youtu.be/%s' % videoID
	elif 'revision3' in sourceID:
		url_split = args.get('imagepath','').rsplit('/',1)[-1].split('--')
		page = 'http://revision3.com/{0}/{1}'.format(url_split[0],url_split[2])
	elif 'dailymotion_com' in sourceID:
		videoID = args.get('path','').split('url=',1)[-1].split('&')[0]
		page = 'http://www.dailymotion.com/video/%s' % videoID
	elif 'metacafe' in sourceID:
		videoID = args.get('path').rsplit('/',1)[-1]
		page = "http://www.metacafe.com/w/%s" % videoID
		'''
		{'imagepath': 'http://s1.dmcdn.net/CuJ4C/x240-wPZ.jpg', 'addonName': '', 'title': 'H-E05-1', 'filename': '', 'ignore': 'script.module.sharesocial', 'apiver': '1', 'ext': 'plugin', 'addonID': 'skin.confluence', 'path': 'plugin://plugin.video.dailymotion_com/?url=x16ec11&mode=playVideo', 'folder': 'plugin://plugin.video.dailymotion_com/?mode=listVideos&url=https%3a%2f%2fapi.dailymotion.com%2fvideos%3ffields%3ddescription%2cduration%2cid%2cowner.username%2ctaken_time%2cthumbnail_large_url%2ctitle%2cviews_total%26channel%3dfun%26sort%3dcommented-today%26limit%3d50%26family_filter%3d1%26localization%3den_EN%26page%3d1', 'label': 'H-E05-1'}
		{'imagepath': 'http://s1.mcstatic.com/thumb/11096432/28740650/4/videos/0/1/comedy_bang_bang_reggie_makes_music_jessica_alba_season_2.jpg?v=1', 'addonName': '', 'title': '', 'filename': 'hl-60280229', 'ignore': 'script.module.sharesocial', 'apiver': '1', 'ext': 'plugin', 'addonID': 'skin.confluence', 'path': 'plugin://plugin.video.metacafe/video/hl-60280229', 'folder': 'plugin://plugin.video.metacafe/videos/%2Ff%2Fvideos_about%2Fcomedy%2F/', 'label': 'Comedy Bang! Bang! - Reggie Makes Music: Jessica Alba Season: 2'}
		'''
	else:
		print args
		return None
	share = ShareSocial.getShare(sourceID,'video')
	share.name = args.get('addonName','Share Social')
	share.title = share.name + ' Video'
	share.page = page
	share.thumbnail = args.get('imagepath')
	share.share()
Пример #6
0
	def removeUser(self):
		feed = True
		while feed:
			menu = ShareSocial.ChoiceMenu('Remove Users: Choose Feed')
			for f in self.feeds:
				show = ''
				users = ShareSocial.getSetting('feed_users_' + f.addonID,[])
				if not users: continue
				
				sh = []
				us = []
				for u in users:
					user = self.decodeUser(u)
					sh.append(user.get('name','ERROR'))
					us.append(user)
				show = ' (%s)' % ', '.join(sh)
				menu.addItem((f,us),f.name + show)
			
			if not menu.items:
				xbmcgui.Dialog().ok('No Users','No users to remove :)')
				return
				
			feed_users = menu.getResult()
			if not feed_users: return
			feed, users = feed_users
			submenu = ShareSocial.ChoiceMenu('Remove Users: Choose User')
			for u in users:
				submenu.addItem(u,u.get('name','ERROR'))
			user = submenu.getResult()
			if not user: return
			self.removeFeedUser(feed, user)
Пример #7
0
	def fillFeedList(self,results=None):
		#TODO: clean this up so I don't need this sorta crap
		passed_results = results and True or False
		if not self.feeds: return
		items = {}
		ct = 1
		if not results:
			blocked = ShareSocial.getSetting('blocked_feeds',[])
			pool = ArrayPool()
			for f in self.feeds:
				if f.addonID in blocked: continue
				pcall = f.getProvideCall()
				pool.addJob(f.provideWithCall,f,'feed',pcall,self.getFeedUserIDs(f))
		fct = len(self.feeds)
		afterpct = int((fct * 100.0) / (fct + 1))
		left = float(100 - afterpct)
		dialog = xbmcgui.DialogProgress()
		dialog.create('Getting Feeds')
		now = time.daylight and (time.time() + time.altzone + 3600) or int(time.mktime(time.gmtime()))
		try:
			if not results:
				results = pool.getResult(dialog)
				self.provisions = results
			c=0
			for result in results:
				if not result.target: continue
				if not result or result._error:
					if result:
						LOG('No result for feed: %s - %s' % (result.target.name,result._error))
					else:
						LOG('No result for feed')
					c+=1
					continue
				lastpct = int((c * left) / fct)
				dialog.update(afterpct + lastpct,result.target.name,'Preparing feed...')
				feedIcon = result.target.getIcon()
				#print '%s : %s' % (result.target.name, feedIcon)
				c+=1
				for r in result.items:
					item = FeedListItem(r)
					item.setProperty('feedicon',feedIcon)
					item.setProperty('ago',durationToShortText(now - item.timestamp) + ' ago')
					items[item.timestamp + (1.0/ct)] = item #add decimal to make unique
					ct+=1
			
			keys = items.keys()
			keys.sort(reverse=True)
			self.feedList.reset()
			for k in keys:
				#print "%s - %s" % (k,durationToShortText(now - items[k].timestamp))
				self.feedList.addItem(items[k])
			if not keys:
				fi = FeedListItem(None)
				fi.setLabel('[CR]NO FEEDS')
				self.feedList.addItem(fi)
			elif not passed_results:
				self.save()
		finally:
			dialog.close()
Пример #8
0
	def showHideFeedMenu(self):
		feed = True
		while feed:
			menu = ShareSocial.ChoiceMenu('Toggle Visibility')
			feedlist = ShareSocial.getSetting('blocked_feeds',[])
			for f in self.feeds:
				blocked = ''
				if f.addonID in feedlist: blocked = ' [HIDDEN]'
				menu.addItem(f, f.name + blocked, f.iconPath)
			feed = menu.getResult()
			if not feed: return
			if feed.addonID in feedlist:
				self.showFeed(feed)
			else:
				self.hideFeed(feed)
Пример #9
0
	def setUser(self):
		feed = True
		while feed:
			menu = ShareSocial.ChoiceMenu('Add Users: Choose Feed')
			for f in self.feeds:
				show = ''
				users = ShareSocial.getSetting('feed_users_' + f.addonID,[])
				if users:
					sh = []
					for u in users:
						sh.append(self.decodeUser(u).get('name','ERROR'))
					show = ' (%s)' % ', '.join(sh)
				menu.addItem(f,f.name + show)
			feed = menu.getResult()
			if not feed: return
			submenu = ShareSocial.ChoiceMenu('Add Users: Choose User')
			for u in feed.functions().getUsers():
				submenu.addItem(u,u.get('name','ERROR'))
			user = submenu.getResult()
			if not user: return
			self.setFeedUser(feed, user)
Пример #10
0
	def doContextMenu(self):
		menu = ShareSocial.ChoiceMenu('Options')
		menu.addItem('update_status','Update Status')
		menu.addItem('refresh','Refresh Feeds')
		menu.addItem('manage_feeds','Manage Feeds')
		menu.addItem('settings','Settings')
		f = self.feedList.getSelectedItem().feeditem
		if f:
			if f.share and ShareSocial.shareTargetAvailable(f.share.shareType,'script.module.sharesocial'):
				menu.addItem(None,None)
				menu.addItem('share','Share %s...' % f.share.shareType)
			if f.share: f.share.updateData()
			if f.share and f.share.shareType == 'video':
				menu.addItem('watch_video','Watch Video')
			elif f.share and f.share.shareType == 'image':
				if f.share.media:
					menu.addItem('view_image','View Image')
			elif f.get('textimage'):
				menu.addItem('view_picture','View Image')
			
		result = menu.getResult()
		if not result: return
		if result == 'update_status':
			updateStatus()
		elif result == 'refresh':
			self.fillFeedList()
		elif result == 'manage_feeds':
			self.manageFeedsMenu()
		elif result == 'settings':
			ShareSocial.__addon__.openSettings() #@UndefinedVariable
		elif result == 'share':
			f.share.share()
		elif result == 'watch_video':
			self.showVideo(f.share.media)
		elif result == 'view_image':
			self.showImage(f.share.media)
		elif result == 'view_picture':
			url = self.feedList.getSelectedItem().getProperty('picture')
			print url
			self.showImage(url)
Пример #11
0
def processSkinShare():
	LOG('Sharing From Plugin ')
	argNames = ['ignore','apiver','addonID','addonName','ext','imagepath','title','folder','filename','label','path']
	args = {}
	
	for s in sys.argv:
		if not argNames: break
		argName = argNames.pop(0)
		args[argName] = s
	
	if args['ext'] == 'plugin':
		handlePluginShare(args)
		return
	
	path = args.get('folder','') + args.get('filename','') # Because some paths get screwed up from the filenameandpath infolabel
	if 'plugin://' in path: path = args.get('path','') # Because we need this for the URL
	print 'Test: %s' % args
	print sys.argv
	
	shareType = None
	if args.get('imagepath'):
		shareType = 'imagefile'
		path = args.get('imagepath','')
		LOG('shareType: %s - determined by PicturePath' % shareType)
	else:
		ext = args.get('ext')
		if ext: shareType = getTypeFromExt(ext)
		if shareType:
			LOG('shareType: %s - determined by FileExtension' % shareType)
		else:
			shareType = getTypeFromFolderPath(args.get('folderpath'))
			if shareType:
				LOG('shareType: %s - determined from FolderPath' % shareType)
			else:
				shareType = askType()
				if shareType:
					LOG('shareType: %s - determined by asking user' % shareType)
				else:
					return
		
	share = ShareSocial.getShare(args['addonID'], shareType)
	share.title = args.get('title') or args.get('label') or args.get('filename','')
	share.media = path
	share.sourceName = args.get('addonName')
	lpath = None
	if share.shareType in ('imagefile','videofile','audiofile'):
		#TODO: check for cahed file before deciding it's remote
		if share.mediaIsRemote():
			LOG('Share is media and remote.')
			if share.mediaIsWeb():
				LOG('Share is media and on the web. Looking for local copy...')
				lpath = ShareSocial.getCachedPath(share.media)
				if lpath:
					LOG('Found cached content')
				else:
					LOG('Not cached - downloading...')
					targetPath = os.path.join(ShareSocial.CACHE_PATH,'tempmediafile.' + args.get('ext',''))
					try:
						global DIALOG
						DIALOG = xbmcgui.DialogProgress()
						DIALOG.create('Download','Waiting for download...')
						DIALOG.update(0,'Waiting for download...')
						lpath = ShareSocial.getFile(share.media, targetPath, progressCallback)
					except:
						error = ERROR('Download failed!')
						xbmcgui.Dialog().ok('Failed','Download failed.', error)
						return
					finally:
						DIALOG.close()
					
				if lpath:
					LOG('Converting content to local file')
					alt = share.getCopy()
					alt.shareType = alt.shareType.replace('file','')
					share.media = lpath
					share.addAlternate(alt)
				else:
					LOG('Could not download content - changing type to %s' % share.shareType.replace('file',''))
					share.shareType = share.shareType.replace('file','')
			else:
				LOG('Share is media and on the local network. Looking for local copy...')
				lpath = ShareSocial.getCachedPath(share.media)
				if lpath:
					LOG('Found cached content')
				else:
					LOG('Not cached - copying to local filesystem...')
					lpath = os.path.join(ShareSocial.CACHE_PATH,'tempmediafile.' + args.get('ext',''))
					got = copyRemote(share.media,lpath)
					if not got:
						LOG('Failed to copy remote file')
						lpath = None
						
				if lpath:
					share.media = lpath
				else:
					xbmcgui.Dialog().ok('Failed','Unable to share remote file.')
					return
				
	share.share()
	clearDirFiles(ShareSocial.CACHE_PATH)	
Пример #12
0
	def showImage(self,source):
		target_path = os.path.join(ShareSocial.CACHE_PATH,'slideshow')
		if not os.path.exists(target_path): os.makedirs(target_path)
		ShareSocial.clearDirFiles(target_path)
		ShareSocial.getFile(source,os.path.join(target_path,'image.jpg'))
		xbmc.executebuiltin('SlideShow(%s)' % target_path)
Пример #13
0
	def showFeed(self,feed):
		feedlist = ShareSocial.getSetting('blocked_feeds',[])
		if feed.addonID in feedlist: feedlist.pop(feedlist.index(feed.addonID))
		ShareSocial.setSetting('blocked_feeds',feedlist)
Пример #14
0
	def hideFeed(self,feed):
		feedlist = ShareSocial.getSetting('blocked_feeds',[])
		if feed.addonID in feedlist: return
		feedlist.append(feed.addonID)
		ShareSocial.setSetting('blocked_feeds',feedlist)
Пример #15
0
	def save(self):
		addUserToList(self.ID)
		data = binascii.hexlify(ShareSocial.dictToString(self.__dict__))
		setSetting('user_data_%s' % self.ID,data)
Пример #16
0
	if not ShareSocial.shareTargetAvailable('status','script.module.sharesocial'):
		xbmcgui.Dialog().ok('Failed','No status update targets available.')
		return
	share = ShareSocial.getShare('script.module.sharesocial', 'status')
	share.askMessage('Enter Status Message')
	if not share.message: return
	share.share(withall=True)
	
def addTwitterUser():
	from twitter import TwitterSession
	TwitterSession(add_user=True)
	
if __name__ == '__main__':
	if len(sys.argv) > 1:
		if sys.argv[1] == 'install_skin_mod':
			ShareSocial.installSkinMod()
		elif sys.argv[1] == 'undo_skin_mod':
			ShareSocial.installSkinMod(True)
		elif sys.argv[1] == 'add_twitter_user':
			addTwitterUser()
		elif sys.argv[1] == 'share':
			processShare()
		elif sys.argv[1] == 'font_select_dialog':
			window.fontSelectDialog(sys.argv[2])
		elif sys.argv[1] == 'set_font_setting':
			window.setFontSetting(sys.argv[2],sys.argv[3])
		else:
			processSkinShare()
	else:
		registerAsShareTarget()
		#updateStatus()
Пример #17
0
	def encodeUser(self,user):
		return binascii.hexlify(ShareSocial.dictToString(user))
Пример #18
0
	def decodeUser(self,data):
		return ShareSocial.dictFromString(binascii.unhexlify(data))
Пример #19
0
	def getFeedUserIDs(self,feed):
		users = ShareSocial.getSetting('feed_users_' + feed.addonID,[])
		IDs = []
		for u in users:
			IDs.append(self.decodeUser(u).get('id'))
		return IDs
	def provide(self,getObject,ID=None):
		session = TwitterSession(ID=ID,require_existing_user=True)
		if not session.twit: return getObject.error('NOUSERS')
		user = {'id':session.user.ID,'name':session.user.name,'photo':session.user.photo}
		if getObject.type == 'feed':
			results = session.twit.get_home_timeline(include_entities=1)
			for r in results:
				try:
					text = r.get('text','ERROR')
				except:
					print results
				#print '%s : %s' % (r.get('id'),text)
				username = r['user'].get('name','ERROR')
				userimage = r['user'].get('profile_image_url')
				timestamp = r.get('created_at')
				textimage = ''
				ent = r.get('entities')
				commsObj = None
				share = None
				if ent:
					#print ent
					media = ent.get('media')
					urls = ent.get('urls')
					if media:
						if media[0].get('type') == 'photo':
							textimage = media[0].get('media_url')
							share = ShareSocial.getShare('script.module.sharesocial', 'image')
							share.media = textimage
							share.page = media[0].get('expanded_url')
							share.title = "From Twitter via XBMC"
							share.thumbnail = textimage
							#print textimage
							#print media[0].get('expanded_url')
							#print media[0].get('url')
							#print media[0].get('display_url')
					elif urls:
						url = urls[0].get('expanded_url')
						video = StreamExtractor.getVideoInfo(url)
						if video:
							textimage = video.thumbnail
							vid_title = ''
							if video.title: vid_title = video.title + ': '
							share = ShareSocial.getShare('script.module.sharesocial', 'video')
							share.media = video.streamURL()
							#print share.media
							share.page = url
							share.title = "%sFrom %s via Twitter via XBMC" % (vid_title,video.sourceName)
							share.thumbnail = textimage
							if not share.media:
								share.callbackData = {'source':video.sourceName,'id':video.ID,'page':url}
#							else:
#								share = ShareSocial.getShare('script.module.sharesocial', 'image')
#								share.media = textimage
#								share.page = url
#								share.title = "%sFrom %s via Twitter via XBMC" % (vid_title,video.sourceName)
#								share.thumbnail = textimage
							
				replyToID = r.get('in_reply_to_status_id')
				if replyToID:
					commsObj = getObject.getCommentsList()
					commsObj.count = 1
					commsObj.isReplyTo = True
					commsObj.callbackDict['replyToID'] = replyToID
					
				getObject.addItem(username,userimage,text,timestamp,textimage,comments=commsObj,client_user=user,share=share)
		return getObject
Пример #21
0
	def load(self):
		data = getSetting('user_data_%s' % self.ID)
		if not data: return None
		data = ShareSocial.dictFromString(binascii.unhexlify(data))
		self.__dict__.update(data)
		return self