/
rhythmbox_cli.py
executable file
·50 lines (40 loc) · 1.32 KB
/
rhythmbox_cli.py
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
#!/usr/bin/env python
from commands import getoutput as get
from search import GoogleSearch
from urllib import urlopen
import user
import re
from getlyric import xmlcorrect,ascii_to_char,bylength,getlyric
import gobject
import dbus
import dbus.glib
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
bus=dbus.SessionBus()
main()
bus.add_signal_receiver(main,dbus_interface="org.gnome.Rhythmbox.Player",signal_name="playingChanged")
loop=gobject.MainLoop()
loop.run()