Wednesday, April 16, 2014

script to remove current song of vlc

!! requirement!!
- pexect -- have to install it (pip install pexect)
- enable telnet on vlc and set password to the password in the script me is 123ase

this script will determine if it is a link, if true it will also delete the orignal file


#!/usr/bin/python

import pexpect
import re
import os

fileKey = open("sfile", "w")
res = ''
passwd = "123ase"

try:
    child = pexpect.spawn("telnet localhost 4212")
    child.expect('assword')
    child.sendline(passwd)
    #child.send("\n")
    child.expect(">")
    #child.expect (['>',pexpect.EOF])
    child.sendline("status")
   
    print child.before
    res = child.before
    child.logfile = fileKey
   
    child.expect(">")
    child.send("next")
    child.send("\n")
   
    child.expect(">")
    child.send("quit")
    child.send("\n")
    print child.before
    child.interact()
   
    child.close()
except:
    print "oh no, wrong"
   
print "$" * 23
fileKey.close()
#print res

q = open("sfile", "r" )

q = q.read()
ql = q.split("\n")
for i in ql:
    if i != "":
        if re.search("new\s+input", i):
            #nprint i
            i = i.strip()
            ni = re.sub("\(\s+new\s+input:|\)$", "", i)
            ni = ni.strip()
            ni = re.sub("file://","", ni)
            print ni

#data = "\"" + ni + "\""
data = ni


resultarray = []
if os.path.exists(data):
    resultarray.append("file existed :" + data)
    #link = os.readlink(data)
    if os.path.islink(data):
        link = os.readlink(data)
        resultarray.append("link existed :" + link)
        try:
            os.remove(link)
            resultarray.append("link deleted")
        except:
            resultarray.append("delete fail")
    try:
        os.remove(data)
        resultarray.append("file deleted")
    except:
        resultarray.append("delete fail")
    else:
        resultarray.append("link not existed :" + data)
else:
    resultarray.append("file not existed :" + data)

print "\n".join(resultarray)

No comments:

Post a Comment