示例#1
0
def main(*args, **kwargs):
	rhythm_obj=bus.get_object("org.gnome.Rhythmbox", "/org/gnome/Rhythmbox/Player")
	rhythmshell_obj=bus.get_object("org.gnome.Rhythmbox", "/org/gnome/Rhythmbox/Shell")
	rhythm=dbus.Interface(rhythm_obj, "org.gnome.Rhythmbox.Player")
	rhythmshell=dbus.Interface(rhythmshell_obj, "org.gnome.Rhythmbox.Shell")	
	artist=str(rhythmshell.getSongProperties(rhythm.getPlayingUri())['artist'])
	title=str(rhythmshell.getSongProperties(rhythm.getPlayingUri())['title'])

	searchstr='''"'''+title+'''"'''+' '+artist+' lyrics -search'
	
	gs=GoogleSearch(searchstr)
	print 'Googling for ',searchstr
	gs.results_per_page=10
	
	try:
		results=gs.get_results()
	except:
		# os.popen("dcop amarok contextbrowser showLyrics '<lyric>Google.com is not accessible. Check your internet connection and retry</lyric>'")
		print 'google.com is not accessible'
		return ''

	for res in results:
		lyric=getlyric(res.url.encode('utf8'),title)
		if lyric=='':
			pass
		else :
			print 'the lyric is:\n%s'%lyric
			break
示例#2
0
def main(*args, **kwargs):
	rhythm_obj=bus.get_object("org.gnome.Rhythmbox", "/org/gnome/Rhythmbox/Player")
	rhythmshell_obj=bus.get_object("org.gnome.Rhythmbox", "/org/gnome/Rhythmbox/Shell")
	rhythm=dbus.Interface(rhythm_obj, "org.gnome.Rhythmbox.Player")
	rhythmshell=dbus.Interface(rhythmshell_obj, "org.gnome.Rhythmbox.Shell")	
	artist=str(rhythmshell.getSongProperties(rhythm.getPlayingUri())['artist'])
	title=str(rhythmshell.getSongProperties(rhythm.getPlayingUri())['title'])

	searchstr='''"'''+title+'''"'''+' '+artist+' lyrics -search'
	
	gs=GoogleSearch(searchstr)
	print 'Googling for ',searchstr
	gs.results_per_page=10

	results=gs.get_results()
	print "got results", results

#	try:
#		results=gs.get_results()
#	except:
#		print 'google.com is not accessible'
#		return ''

	for res in results:
		lyric=getlyric(res.encode('utf8'))
		if lyric=='':
			pass
		else :
			print 'the lyric is:\n%s'%lyric
			break
示例#3
0
	def find_lyric(self,title,artist,is_first=False,is_next=False,is_prev=False):
		if is_first==True:
			self.result_no=-1
			self.all_lyrics=[]
			searchstr='''"'''+title+'''"'''+' '+artist+' lyrics -search'
			gs=GoogleSearch(searchstr)
			print 'Googling for ',searchstr
			self.results=gs.get_results()
			print "the search results are: "
			for i in self.results:
				print i

		if is_prev==True:
			if self.result_no>=1:
				self.result_no-=1
				print "returning the lyric no %d"%self.result_no
				return self.all_lyrics[self.result_no]
			else:
				return "This is the first one"
		
		if is_next==True:
			if len(self.all_lyrics)>self.result_no+1:
				self.result_no+=1
				return self.all_lyrics[self.result_no]

		while self.result_no+1<len(self.results):
			self.result_no+=1
			lyric=getlyric(self.results[self.result_no].encode('utf8'))
			self.all_lyrics.append(lyric)
		
			if lyric=='':
				pass
			else :
				print "result_no is %d"%self.result_no
				return lyric
		else:
			return "this is the last lyric I could find"
示例#4
0
def main():
	artist=get('dcop %s player artist'%amarokid).strip()
	title=get('dcop %s player title'%amarokid).strip()

	if title =='':
		searchstr=get('dcop %s player nowPlaying'%amarokid)+' lyrics'
	else :
		searchstr='''"'''+title+'''"'''+' '+artist+' lyrics'

	gs=GoogleSearch(searchstr)
	print 'Googling for ',searchstr
	gs.results_per_page=10
	try:
		results=gs.get_results()
	except:
		os.popen("dcop %s contextbrowser showLyrics '<lyric>Google.com is not accessible. Check your internet connection and retry</lyric>'"%amarokid)
		print 'google.com is not accessible'
		return ''

	xml=open('%s/tmp.xml'%user.home,'w')
	for res in results:
		lyric=getlyric(res.url.encode('utf8'),title)
		if lyric=='':
			pass
		else :
			print 'the lyric is:\n%s'%lyric
			xmldoc=xmlcorrect(lyric)
			xmldoc="""<lyric artist="%s" title="%s" page_url="%s" >"""%(artist,title,res.url.encode('utf8'))+xmldoc+'</lyric>'
			print >> xml, xmldoc
			xml.close()
			sh=open('%s/tmp.sh'%user.home,'w')
			print >> sh, "xml=$(cat ~/tmp.xml)"
			print >> sh, '''dcop %s contextbrowser showLyrics "${xml}"'''%amarokid
			sh.close()
			get("sh %s/tmp.sh"%user.home)
			break