Say hi to SkypeJukeBot

Howdy,

I wrote an amateur python code allow changing and playing music tracks on ubuntu 7.10+ skype4py + skype.  Wow I went to bed took a noon nap and woke up solve the overlapping music track issue. Some unix trick will do it. KILL the process before starting a new track. I just learned python the day before christmas this just a warm up session for my google android project. The real thing that I am going to develop will be starting from today.

Let me walk you through how this program can change music track on your linux system.

1) User A call the bot user.
2) User A invite User B to conference with the bot user.
3) Make sure the bot user’s linux machine has a loopback cable from mic to speaker.
4) On the ubuntu/linux machine install all the relevant stuff to get skype4python to work. DBus, Skype 1.4, Skype4py and etc.
5) Run the python SkypeJukeBot.py the code below.
6) From the party chat dialog window type "Play Track1" or "Play Track2" without the quote and is case sensitive.


import Skype4Py
import time
import os
import datetime

# function on message status
def on_message_status(message, status):
    print status   
    if status == Skype4Py.cmsReceived:
        print message.Body

skype = Skype4Py.Skype()
print "Begin Listening to Skype message"   
now = datetime.datetime.now()
messageReceivedtimeStamp = now
#print " Listener started : "messageReceivedtimeStamp
d = {}
print d
startupFlag =0
while(True):
    if startupFlag == 0:   
        for chat in skype.Chats:
            for message in chat.Messages:
                if message.Id not in d:            
                    d[message.Id] = message.Id
                else:
                    startupFlag =1
                    break
   
    for chat in skype.Chats:
        for message in chat.Messages:
            if message.Id not in d:            
                print message.Id               
                d[message.Id] = message.Id
                print "Skype Message from : " + message.FromHandle
                if message.Body == "Play Track1":
                    print "Music track changed by: " + message.FromHandle
                    print "Playing track 1 music"
                    msg= "Music track changed and playing track 1 "                   
                    for member in message.Chat.MemberObjects:
                                if member.Handle == skype.CurrentUserHandle:
                                    continue # don’t sent to myself
                            skype.SendMessage(member.Handle, msg)
                    os.system(’ps aux|gawk \’$11 == "mplayer" {print $2}\’ > pid.log’)
                    f = open(’pid.log’, ‘r+’)
                    pid = f.read()
                    print pid                   
                    if(pid != ""):                   
                        os.system(’kill -9 ‘ + pid)
                    os.system(’mplayer /home/kenneth/Music/Track1.m4a &’)
                   
                   
                if message.Body == "Play Track2":
                    print "Music track changed by: " + message.FromHandle
                    print "Playing track 2 music"
                    msg= "Music track changed and playing track 2 "                   
                    for member in message.Chat.MemberObjects:
                                if member.Handle == skype.CurrentUserHandle:
                                    continue # don’t sent to myself
                            skype.SendMessage(member.Handle, msg)
                   
                    os.system(’ ps aux|gawk \’$11 == "mplayer" {print $2}\’ > pid.log’)
                    f = open(’pid.log’, ‘r+’)
                    pid = f.read()
                    print pid                   
                    if(pid != ""):                   
                        os.system(’kill -9 ‘ + pid)
                    os.system(’mplayer /home/kenneth/Music/Track2.m4a’)
                   
skype.Attach()

Leave a Reply