Author Topic: Voxcommando Media Player Classic Integration.  (Read 13705 times)

0 Members and 1 Guest are viewing this topic.

xtermin8r

  • $upporter
  • Sr. Member
  • *****
  • Posts: 366
  • Karma: 9
  • Crunchie
    • View Profile
Voxcommando Media Player Classic Integration.
« on: May 18, 2014, 12:28:08 PM »
Today's xperiment will be integrating media player classic into the collective.

MPC-HC is an extremely light-weight, open source media player for Windows®. It supports all common video and audio file formats available for playback.

http://mpc-hc.org/
Neural Net Based Artificial Intelligence.

xtermin8r

  • $upporter
  • Sr. Member
  • *****
  • Posts: 366
  • Karma: 9
  • Crunchie
    • View Profile
Re: Voxcommando Media Player Classic Integration.
« Reply #1 on: May 18, 2014, 02:09:02 PM »
Integration complete.

Method 1
Command line arguments:

example below tells mpc to play all files in a certain directory.



Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<command id="252" name="mpc music videos" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
  <action>
    <cmdType>Launch</cmdType>
    <cmdString>FILEPATH TO YOUR MPC-HC INSTALLATION\mpc-hc.exe&amp;&amp;FILE PATH FOR YOUR MEDIA FOLDER</cmdString>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>TTS.Speak</cmdType>
    <cmdString>playing music videos</cmdString>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <phrase>play music videos</phrase>
</command>

for more command line switches goto help, command line switches

Method 2
Http Api

Enable web interface in mpc by clicking on view,options.



click on launch in web browser.

now if you see this below in your web browser, all is well.



now make note of the url in the address bar

mine looks like this: http://localhost:13579/
13579 is the port

now for vc to get involved, we will use the scrape command in the command builder, the command below is for play
replace 13579 with your port number



Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 2.2.1.6-->
<command id="348" name="mpc_play" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
  <action>
    <cmdType>Scrape</cmdType>
    <params>
      <param>http://localhost:13579/command.html?wm_command=887&amp;null=0</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <phrase>play media</phrase>
</command>

some commands :

play
Code: [Select]
http://localhost:13579/command.html?wm_command=887&null=0pause
Code: [Select]
http://localhost:13579/command.html?wm_command=888&null=0stop
Code: [Select]
http://localhost:13579/command.html?wm_command=890&null=0previous
Code: [Select]
http://localhost:13579/command.html?wm_command=921&null=0next
Code: [Select]
http://localhost:13579/command.html?wm_command=922&null=0
for more on http commands open mpc web interface, click on "The media player interface made by chobits"
http://localhost:13579/controls.html



now view page source.

the stop command



so the command for stop will be.
Code: [Select]
http://localhost:13579/command.html?wm_command=890&null=0
The command I use for the payload xml :

Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<command id="604" name="mpc browser" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
  <action>
    <cmdType>Scrape</cmdType>
    <cmdString>http://localhost:13579/browser.html?path={1}</cmdString>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <phrase>m p c,media player classic,music video,play music video</phrase>
  <payloadFromXML phraseOnly="False" use2partPhrase="False" phraseConnector="by" Phrase2wildcard="anyone" optional="False">E:\Appz\Vox\Payloads\musicvideos.xml</payloadFromXML>
</command>





« Last Edit: March 02, 2016, 08:45:19 PM by nime5ter »
Neural Net Based Artificial Intelligence.

Kalle

  • $upporter
  • Hero Member
  • *****
  • Posts: 2319
  • Karma: 47
    • View Profile
Re: Voxcommando Media Player Classic Integration.
« Reply #2 on: May 18, 2014, 03:08:05 PM »
Good job  :clap
***********  get excited and make things  **********

xtermin8r

  • $upporter
  • Sr. Member
  • *****
  • Posts: 366
  • Karma: 9
  • Crunchie
    • View Profile
Re: Voxcommando Media Player Classic Integration.
« Reply #3 on: May 18, 2014, 03:37:07 PM »
Good job  :clap

Gern geschehen.

hope it's correct.
Neural Net Based Artificial Intelligence.

xtermin8r

  • $upporter
  • Sr. Member
  • *****
  • Posts: 366
  • Karma: 9
  • Crunchie
    • View Profile
Re: Voxcommando Media Player Classic Integration.
« Reply #4 on: May 18, 2014, 03:45:51 PM »
interesting thing to note here is mpc has a web based file browser



http://localhost:13579/browser.html?path="somefile"


wouldn't it be nice if we could command mpc like xbmc to play us files by artist, name, title etc ?

Code: [Select]
</tr>
<tr class="mp4">
<td class="browser-td"><a href="/browser.html?path=E:\Videos\Music%20Vids\Tron%20Legacy%20Video%20_The%20Game%20Has%20Changed_.mp4">Tron Legacy Video _The Game Has Changed_.mp4</a></td>
<td class="browser-td"><span class="nobr">MP4</span></td>
<td class="browser-td align-right"><span class="nobr">48948K</span></td>
<td class="browser-td"><span class="nobr">2012.08.26 01:50</span></td>
</tr>

time to make a payload xml somehow, using regex and what not  :bonk
« Last Edit: May 18, 2014, 03:50:57 PM by xtermin8r »
Neural Net Based Artificial Intelligence.

xtermin8r

  • $upporter
  • Sr. Member
  • *****
  • Posts: 366
  • Karma: 9
  • Crunchie
    • View Profile
Re: Voxcommando Media Player Classic Integration.
« Reply #5 on: May 19, 2014, 01:18:36 PM »
great news, I managed to write a python script (not in Iron Python) that creates a music videos payload xml for media player classic.
and it's working fine.

Ill upload the python script as soon as I "iron out"   :biglaugh  some issues, may take some time coz I suck at regex.
I'll upload a video also, I hope.


« Last Edit: May 19, 2014, 01:31:51 PM by xtermin8r »
Neural Net Based Artificial Intelligence.

xtermin8r

  • $upporter
  • Sr. Member
  • *****
  • Posts: 366
  • Karma: 9
  • Crunchie
    • View Profile
Re: Voxcommando Media Player Classic Integration.
« Reply #6 on: May 20, 2014, 01:03:18 PM »
below is the Iron Python script for vc.

Code: [Select]
#-------------------------------------------------------------------------------
# Name:        VC MPC Payload Xml Generator
# Purpose:     I need it
#
# Author:      xtermin8r
#
# Created:     18/05/2014
# Copyright:   (c) xtermin8r 2014
# Licence:     111000111010
#-------------------------------------------------------------------------------
import urllib, urllib2
import re
import os
from re import findall
from xml.etree import ElementTree as ET

#function get rid of unwanted characters
def cfix(zx):
    global x
    f2 = re.sub( '\s+', ' ', zx).strip()
    f2 = f2.replace(" -", "")
    f2 = f2.replace("-", "")
    f2 = f2.replace(":", ".")
    f2 = re.sub( '\s+', ' ', f2).strip()
    x = f2
#    print(x)
    return x

# http request
url = "http://localhost:13579/browser.html?path=E:\Videos\Music%20Vids"
response = urllib.urlopen(url)
html = response.read()
htmlStr = str(html)

# close it
response.close()

#print(htmlStr)
#<a href="/browser.html?path=E:\Videos\Music%20Vids\Snap%20-%20The%20Power%20(HQ).mp4">Snap - The Power (HQ).mp4</a></td>
adata = findall('path=(.*?)">(.*?)\<', htmlStr)
#print(adata)

#Create Music Videos Phrases txt File
tf = open("music_videos.txt", "wb")

for value,phrase in adata:
   print(phrase)
   tf.write((str(phrase) + "\n"))
tf.close()

#create the root </PayloadsRoot> <PayloadsRoot>
root_element = ET.Element("PayloadsRoot")

for value,phrase in adata:
    #print(k,v)
    #create the first subelemet <payload> </payload>
    pay_element = ET.SubElement(root_element, "payload")
    #create the first child <value> </value>
    child = ET.SubElement(pay_element, "value")
    child.text = value
    #create the second child <phrase> </phrase>
    child = ET.Element("phrase")
    #get the filename without the extension
    fileName = (os.path.splitext(phrase)[0])
    #get rid of unwanted characters
    cfix(fileName)
    fileName = x
    child.text = fileName
    #now append
    pay_element.append(child)

#Let's see the results
a = ET.tostring(root_element)
#print a

def indent(elem, level=0):
    i = "\n" + level*'\t'
    if len(elem):
        if not elem.text or not elem.text.strip():
            elem.text = i + '\t'
        if not elem.tail or not elem.tail.strip():
            elem.tail = i
        for elem in elem:
            indent(elem, level+1)
        if not elem.tail or not elem.tail.strip():
            elem.tail = i
    else:
        if level and (not elem.tail or not elem.tail.strip()):
            elem.tail = i

indent(root_element)
#print ( ET.tostring(root_element) )

output_file = open( 'E:\Appz\Vox\VC_187_Eden\payloads\musicvideos.xml', 'w' )
output_file.write( '<?xml version="1.0" encoding="utf-8"?>'+'\n' )
output_file.write( '<!--A VoxCommando Payload file-->' +'\n' )
output_file.write( ET.tostring(root_element) )
output_file.close()

Enjoy.

I'll be uploading a video soon, stay tuned.
« Last Edit: May 20, 2014, 01:07:16 PM by xtermin8r »
Neural Net Based Artificial Intelligence.

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 2012
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: Voxcommando Media Player Classic Integration.
« Reply #7 on: May 20, 2014, 02:48:02 PM »
Amazing stuff, xtermin8r.  :clap

You've been busy.

So is etree working OK for you in Iron Python then or did you have to build in some workarounds? I seem to remember someone else here running into a bug to do with character encoding?  :-\

Also, I was curious if you had a particular reason that you preferred to scan your directory using Python rather than with the VCFileScanner tool that comes in the VC Extras package? Were you running into problems with that?

(i.e., http://voxcommando.com/mediawiki/index.php?title=Installation#VoxCommando_Extras)
TIPS: POST VC VERSION #. Explain what you want VC to do. Say what you've tried & what happened, or post a video demo. Attach VC log. Link to instructions followed.  Post your command (xml)

xtermin8r

  • $upporter
  • Sr. Member
  • *****
  • Posts: 366
  • Karma: 9
  • Crunchie
    • View Profile
Re: Voxcommando Media Player Classic Integration.
« Reply #8 on: May 20, 2014, 05:57:33 PM »

Amazing stuff, xtermin8r.  :clap

You've been busy.

So is etree working OK for you in Iron Python then or did you have to build in some workarounds? I seem to remember someone else here running into a bug to do with character encoding?  :-\

Also, I was curious if you had a particular reason that you preferred to scan your directory using Python rather than with the VCFileScanner tool that comes in the VC Extras package? Were you running into problems with that?

(i.e., http://voxcommando.com/mediawiki/index.php?title=Installation#VoxCommando_Extras)

Thanks Naomi.
I have not had any problems with etree as of yet. The reason I did it in Python was, I already had something written in Python for the task, and I find it easier to debug, and I wasn't aware of VCFilescanner  :bonk. I'm gonna give VCFilescanner a bash.
Neural Net Based Artificial Intelligence.

xtermin8r

  • $upporter
  • Sr. Member
  • *****
  • Posts: 366
  • Karma: 9
  • Crunchie
    • View Profile
Re: Voxcommando Media Player Classic Integration.
« Reply #9 on: May 20, 2014, 06:17:08 PM »
WOW VCFilescanner is awesome, It was only today I was wondering how the hell am I going to scan the sub directories in Python.
Thank you so much for telling me about VCFilescanner, you and the voxinator have saved me hours of precious time.



Neural Net Based Artificial Intelligence.

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7715
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Voxcommando Media Player Classic Integration.
« Reply #10 on: May 20, 2014, 06:27:38 PM »
There is also the commandline call to dir/s and the fact that the Launch.Capture action can now get back results...

I think that the method:
Code: [Select]
bool savePayloadFile(string strPath, Dictionary<string, string> payloadPairs, bool subsetMatching);might also be helpful, but I've never actually tried to use it from python.  The idea would be to create a dictionary (myDictionary) of value/phrase pairs and then create a payloadxml file with a line of python code similar to this:
Code: [Select]
savePayloadFile("payloads\mvideoyfiles.xml", myDictionary, True)
I think your python code is very interesting as a starting point for doing much more sophisticated things, so thanks very much for posting it.  I admit that I have been too busy to give it a proper look but I certainly will soon.

xtermin8r

  • $upporter
  • Sr. Member
  • *****
  • Posts: 366
  • Karma: 9
  • Crunchie
    • View Profile
Re: Voxcommando Media Player Classic Integration.
« Reply #11 on: May 20, 2014, 06:37:00 PM »
I have a problem the phrase and value that are generated by VCFilescanner are in the WRONG place I think, and it's not working.
I'm using VC 1.187.



Neural Net Based Artificial Intelligence.

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7715
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Voxcommando Media Player Classic Integration.
« Reply #12 on: May 20, 2014, 06:46:02 PM »
WTF?

I need to take a look at this.  I guess no one else has tried to use this program recently...  :bonk

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7715
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Voxcommando Media Player Classic Integration.
« Reply #13 on: May 20, 2014, 06:49:01 PM »
I made this and I don't use it personally, and I guess no one has every really tested and commented on it so ...  that's what happens.

The fact that the columns are reversed should be trivial to fix.   The hard part is to find the source code!

xtermin8r

  • $upporter
  • Sr. Member
  • *****
  • Posts: 366
  • Karma: 9
  • Crunchie
    • View Profile
Re: Voxcommando Media Player Classic Integration.
« Reply #14 on: May 20, 2014, 06:52:18 PM »
I made this and I don't use it personally, and I guess no one has every really tested and commented on it so ...  that's what happens.

The fact that the columns are reversed should be trivial to fix.   The hard part is to find the source code!

if you don't find the source let me know, I may be able to help.
Neural Net Based Artificial Intelligence.

xtermin8r

  • $upporter
  • Sr. Member
  • *****
  • Posts: 366
  • Karma: 9
  • Crunchie
    • View Profile
Re: Voxcommando Media Player Classic Integration.
« Reply #15 on: May 20, 2014, 07:10:04 PM »
James do i have your permission to fix it ?
it may only take me seconds to fix.
Neural Net Based Artificial Intelligence.

xtermin8r

  • $upporter
  • Sr. Member
  • *****
  • Posts: 366
  • Karma: 9
  • Crunchie
    • View Profile
Re: Voxcommando Media Player Classic Integration.
« Reply #16 on: May 20, 2014, 07:32:48 PM »
Sorry James, I fixed it.
« Last Edit: October 22, 2014, 08:27:50 AM by nime5ter »
Neural Net Based Artificial Intelligence.

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7715
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Voxcommando Media Player Classic Integration.
« Reply #17 on: May 20, 2014, 08:36:50 PM »
it's OK I found it and it's probably better anyway since there may be other things that need to be fixed

xtermin8r

  • $upporter
  • Sr. Member
  • *****
  • Posts: 366
  • Karma: 9
  • Crunchie
    • View Profile
Re: Voxcommando Media Player Classic Integration.
« Reply #18 on: May 20, 2014, 09:19:20 PM »
Thanks James.

latest Python script much better than the previous one that got posted earlier, this one does subdirectories also, and gets rid of unwanted characters,  and there is no need to have media player classic running.

Code: [Select]
#-------------------------------------------------------------------------------
# Name:        VC Payload Xml Generator
# Purpose:     I need it
#
# Author:      xtermin8r
#
# Created:     21/05/2014
# Copyright:   (c) xtermin8r 2014
# Licence:
#-------------------------------------------------------------------------------
import re
import os
from re import findall
from xml.etree import ElementTree as ET

# Set the directories
mvpath = "E:\Videos\Music Vids"
xmlpath = "E:\Appz\Vox\VC_187_Eden\payloads\musicvideos.xml"

#function get rid of unwanted characters
def cfix(zx):
    global x
    f2 = re.sub( '\s+', ' ', zx).strip()
    f2 = f2.replace(" -", "")
    f2 = f2.replace("-", "")
    f2 = f2.replace(":", ".")
    x = f2
    return x

#create the root </PayloadsRoot> <PayloadsRoot>
root_element = ET.Element("PayloadsRoot")

for dirName, subdirList, fileList in os.walk(mvpath):
    for fname in fileList:
        #create the first subelemet <payload> </payload>
        pay_element = ET.SubElement(root_element, "payload")
        #create the first child <value> </value>
        child = ET.SubElement(pay_element, "value")
        child.text = dirName +"\\" + fname
        #create the second child <phrase> </phrase>
        child = ET.Element("phrase")
        #get the filename without the extension
        fname = ('.').join(fname.split('.')[:-1])
        #get rid of unwanted characters
        cfix(fname)
        fileName = x
        child.text = fileName
        #now append
        pay_element.append(child)

def indent(elem, level=0):
    i = "\n" + level*'\t'
    if len(elem):
        if not elem.text or not elem.text.strip():
            elem.text = i + '\t'
        if not elem.tail or not elem.tail.strip():
            elem.tail = i
        for elem in elem:
            indent(elem, level+1)
        if not elem.tail or not elem.tail.strip():
            elem.tail = i
    else:
        if level and (not elem.tail or not elem.tail.strip()):
            elem.tail = i

indent(root_element)
#print ( ET.tostring(root_element) )

output_file = open(xmlpath, 'w' )
output_file.write( '<?xml version="1.0" encoding="utf-8"?>'+'\n' )
output_file.write( '<!--A VoxCommando Payload file-->' +'\n' )
output_file.write( ET.tostring(root_element) )
output_file.close()



Enjoy !
« Last Edit: May 21, 2014, 12:33:24 PM by xtermin8r »
Neural Net Based Artificial Intelligence.

xtermin8r

  • $upporter
  • Sr. Member
  • *****
  • Posts: 366
  • Karma: 9
  • Crunchie
    • View Profile
Re: Voxcommando Media Player Classic Integration.
« Reply #19 on: May 20, 2014, 09:47:50 PM »
I must admit this is bloody awesome, just been testing it and its working great, even when I speak to it in arabic, hindi, urdu, punjabi.

Video coming soon.
« Last Edit: May 20, 2014, 11:50:35 PM by xtermin8r »
Neural Net Based Artificial Intelligence.

xtermin8r

  • $upporter
  • Sr. Member
  • *****
  • Posts: 366
  • Karma: 9
  • Crunchie
    • View Profile
Re: Voxcommando Media Player Classic Integration.
« Reply #20 on: May 21, 2014, 01:11:15 PM »
« Last Edit: May 21, 2014, 01:17:40 PM by xtermin8r »
Neural Net Based Artificial Intelligence.

xtermin8r

  • $upporter
  • Sr. Member
  • *****
  • Posts: 366
  • Karma: 9
  • Crunchie
    • View Profile
Re: Voxcommando Media Player Classic Integration.
« Reply #21 on: June 09, 2014, 08:33:24 PM »
MPC = MPC-HC = Media Player Classic Home Cinema if you didn't know.

Latest news  on the MPC integration, I managed to write a python program that collects info like artist names  from file names and then create a artist  xml  payload for vc so that I can command vc to play all music videos or all mp3's ,  by Artist name, I also created another Python program that makes a playlist for MPC using the artist xml payload, a vc command executes this script and sends the playlist to MPC using command line arguments.


I'm gonna clean up the code before I decide to release it.

I might upload a video, who knows.





« Last Edit: June 09, 2014, 08:39:06 PM by xtermin8r »
Neural Net Based Artificial Intelligence.

lja

  • Sr. Member
  • ****
  • Posts: 145
  • Karma: 5
    • View Profile
Re: Voxcommando Media Player Classic Integration.
« Reply #22 on: July 17, 2014, 11:08:34 AM »
MPC = MPC-HC = Media Player Classic Home Cinema if you didn't know.

Latest news  on the MPC integration, I managed to write a python program that collects info like artist names  from file names and then create a artist  xml  payload for vc so that I can command vc to play all music videos or all mp3's ,  by Artist name, I also created another Python program that makes a playlist for MPC using the artist xml payload, a vc command executes this script and sends the playlist to MPC using command line arguments.


I'm gonna clean up the code before I decide to release it.

I might upload a video, who knows.





Hi xtermin8r

Did you upload the video? Was the intergration completed? Would love to be able to try this out.

xtermin8r

  • $upporter
  • Sr. Member
  • *****
  • Posts: 366
  • Karma: 9
  • Crunchie
    • View Profile
Re: Voxcommando Media Player Classic Integration.
« Reply #23 on: July 17, 2014, 05:02:17 PM »
Hi lja
I'll try uploading a video tonight, integration is complete, if you want to try it then download what's needed.
« Last Edit: July 17, 2014, 08:14:30 PM by xtermin8r »
Neural Net Based Artificial Intelligence.

xtermin8r

  • $upporter
  • Sr. Member
  • *****
  • Posts: 366
  • Karma: 9
  • Crunchie
    • View Profile
Re: Voxcommando Media Player Classic Integration.
« Reply #24 on: July 17, 2014, 08:51:56 PM »
All mpc commands for vc, click on the link below to download them.

Neural Net Based Artificial Intelligence.

xtermin8r

  • $upporter
  • Sr. Member
  • *****
  • Posts: 366
  • Karma: 9
  • Crunchie
    • View Profile
Re: Voxcommando Media Player Classic Integration.
« Reply #25 on: July 17, 2014, 08:55:41 PM »
Scan contents of directories and sub directories to xml, click on the link below to download the script.

Code: [Select]
#-------------------------------------------------------------------------------
# Name:        Scan Music Videos
# Purpose:     I need it
#
# Author:      xtermin8r
#
# Created:     21/05/2014
# Copyright:   (c) xtermin8r 2014
# Licence:
#-------------------------------------------------------------------------------
import re
import os
from re import findall
from xml.etree import ElementTree as ET
import urllib, urllib2

# Set the directories
rootDir = "E:\Videos\Music Vids"
rootDir2 = "F:\Videos\Music Vids"
xmlpath = "E:\\Appz\\Vox\\payloads\\musicvideos.xml"
txtfile = open("E:\\Appz\\Vox\\payloads\\music_videos_list.txt", "wb")

#function: get rid of unwanted characters
def cfix(zx):
    global x
    f2 = re.sub( '\s+', ' ', zx).strip()
    f2 = f2.replace(" -", " ")
    f2 = f2.replace("- ", " ")
    f2 = f2.replace(" - ", " ")
    f2 = f2.replace("-", " ")
    f2 = f2.replace(":", " ")
    f2 = f2.replace("_", " ")
    f2 = f2.replace("5.1", "")
    f2 = f2.replace(".", " ")
    f2 = f2.replace("!", " ")
    f2 = f2.replace("1080p", " ")
    f2 = f2.replace("720p", " ")
    f2 = f2.replace("x264", " ")
    f2 = f2.replace("ac3", " ")
    f2 = f2.replace("AC3", " ")
    f2 = f2.replace("DTS", " ")
    f2 = f2.replace("DVD", " ")
    f2 = f2.replace("DvD", " ")
    f2 = f2.replace("VOB", " ")
    f2 = f2.replace("rip", " ")
    f2 = f2.replace("aac", " ")
    f2 = f2.replace("Rip", " ")
    f2 = f2.replace("hd", " ")
    f2 = f2.replace("HD", " ")
    f2 = f2.replace("Hd", " ")
    f2 = f2.replace("Hq", " ")
    f2 = f2.replace("BluRay", " ")
    f2 = f2.replace("Blu Ray", " ")
    f2 = f2.replace("1080i", " ")
    f2 = f2.replace("H264", " ")
    f2 = f2.replace("h264", " ")
    f2 = f2.replace("(", " ")
    f2 = f2.replace(")", " ")
    f2 = f2.replace("]", " ")
    f2 = f2.replace("[", " ")
    f2 = f2.replace("AlbumArtSmall", " ")
    f2 = f2.replace("folder", " ")
    f2 = f2.replace("AlbumArt", " ")
    f2 = re.sub( '\s+', ' ', f2).strip()
    x = f2
    return x

#create the root </PayloadsRoot> <PayloadsRoot>
root_element = ET.Element("PayloadsRoot")


def Scan(rootDir):
    for dirName, subdirList, fileList in os.walk(rootDir):
        for fname in fileList:
            if not fname.endswith (".jpg") :
                #create the first subelemet <payload> </payload>
                pay_element = ET.SubElement(root_element, "payload")
                #create the first child <value> </value>
                child = ET.SubElement(pay_element, "value")
                child.text = dirName +"\\" + fname
                #create the second child <phrase> </phrase>
                child = ET.Element("phrase")
                #get the filename without the extension
                fname = ('.').join(fname.split('.')[:-1])
                #Call function get rid of unwanted characters
                cfix(fname)
                fileName = x

                #Debug : Display file names
                #print(fileName)

                #Write filename to text file
                txtfile.write(str(fileName) + "\n")

                #now append
                child.text = fileName
                pay_element.append(child)

                child = ET.Element("subsetmatching")
                child.text = "true"

                pay_element.append(child)

def indent(elem, level=0):
    i = "\n" + level*'\t'
    if len(elem):
        if not elem.text or not elem.text.strip():
            elem.text = i + '\t'
        if not elem.tail or not elem.tail.strip():
            elem.tail = i
        for elem in elem:
            indent(elem, level+1)
        if not elem.tail or not elem.tail.strip():
            elem.tail = i
    else:
        if level and (not elem.tail or not elem.tail.strip()):
            elem.tail = i

#Main
#Call function Scan directory
Scan(rootDir)
#Another directory to scan
#Scan(rootDir2)
txtfile.close()

indent(root_element)
#Debug : View xml tree
#print ( ET.tostring(root_element) )

output_file = open(xmlpath, 'w' )
output_file.write( '<?xml version="1.0" encoding="utf-8"?>'+'\n' )
output_file.write( '<!--A VoxCommando Payload file-->' +'\n' )
output_file.write( ET.tostring(root_element) )
output_file.close()

#Send tts command to vox over http
url = urllib.URLopener()
url.open('http://127.0.0.1:8081/api/tts.speak&&scan has completed,sir')
« Last Edit: July 17, 2014, 11:18:00 PM by xtermin8r »
Neural Net Based Artificial Intelligence.

xtermin8r

  • $upporter
  • Sr. Member
  • *****
  • Posts: 366
  • Karma: 9
  • Crunchie
    • View Profile
Re: Voxcommando Media Player Classic Integration.
« Reply #26 on: July 17, 2014, 09:01:36 PM »
Scan music video artists, this script will extract all artist names to an xml from the musicvideos.xml generated by the above script ScanMusicVideos.py,  make sure there is a hyphen between artist and song name.

Code: [Select]
#-------------------------------------------------------------------------------
# Name:        Extract elements from XML
# Purpose:
#
# Author:      xtermin8r
#
# Created:     10/06/2014
# Copyright:   (c) xtermin8r 2014
# Licence:     <your licence>
#-------------------------------------------------------------------------------
import urllib, urllib2
import re
import os
from re import findall
from xml.etree import ElementTree as ET

txtfile = open("E:\\Appz\\Vox\\payloads\\artist_videos.txt", "wb")
xmlin = "E:\Appz\Vox\Payloads\musicvideos.xml"
xmlout = "E:\\Appz\\Vox\\payloads\\ArtistVideos.xml"

#function: get rid of unwanted characters
def cfix(zx):

    f2 = re.sub( '\s+', ' ', zx).strip()
    #Remove Digits
    #f2 = re.sub(r"(^|\W)\d+", "", f2)

    f2 = f2.replace('xDR;', ' ')
    f2 = f2.replace(" -", " ")
    f2 = f2.replace("- ", " ")
    f2 = f2.replace(" - ", " ")
    f2 = f2.replace("-", " ")
    f2 = f2.replace(":", " ")
    f2 = f2.replace("_", " ")
    f2 = f2.replace("5.1", "")
    f2 = f2.replace(".", " ")
    f2 = f2.replace("!", " ")
    f2 = f2.replace("?", " ")
    f2 = f2.replace("@", " ")
    f2 = f2.replace("&#150", "-")
    f2 = f2.replace("1080p", " ")
    f2 = f2.replace("720p", " ")
    f2 = f2.replace("720P", " ")
    f2 = f2.replace("x264", " ")
    f2 = f2.replace("ac3", " ")
    f2 = f2.replace("AC3", " ")
    f2 = f2.replace("DTS", " ")
    f2 = f2.replace("DVD", " ")
    f2 = f2.replace("DvD", " ")
    f2 = f2.replace("VOB", " ")
    f2 = f2.replace("rip", " ")
    f2 = f2.replace("aac", " ")
    f2 = f2.replace("Rip", " ")
    f2 = f2.replace("hd", " ")
    f2 = f2.replace("HD", " ")
    f2 = f2.replace("Hd", " ")
    f2 = f2.replace("Hq", " ")
    f2 = f2.replace("BluRay", " ")
    f2 = f2.replace("Blu Ray", " ")
    f2 = f2.replace("1080i", " ")
    f2 = f2.replace("H264", " ")
    f2 = f2.replace("h264", " ")
    f2 = f2.replace("(", " ")
    f2 = f2.replace(")", " ")
    f2 = f2.replace("]", " ")
    f2 = f2.replace("[", " ")
    f2 = f2.replace("AlbumArtSmall", " ")
    f2 = f2.replace("folder", " ")
    f2 = f2.replace("AlbumArt", " ")
    f2 = re.sub( '\s+', ' ', f2).strip()
    global x
    x = f2
    return x

tree = ET.parse(xmlin)
root = tree.getroot()

#create the root </PayloadsRoot> <PayloadsRoot>
root_element = ET.Element("PayloadsRoot")

global t1
t1 = ""
n1 = 1

for data in root.findall('payload'):
    phrase = data.find('phrase').text
    value = data.find('value').text
    head, tail = os.path.split(value)
    value = ('.').join(tail.split('.')[:-1])
    #remove beginning digits
    value = re.sub('^[0-9]+.', '', value)
    #Remove empty lines
    #split before hyphen
    value = value.split('-', 1)[0]
    cfix(value)
    value = x
    if (value.lower() != t1.lower()):
        if t1 != value:
            if (value != ""):
                #remove beginning digits
                artist = re.sub('^[0-9]+.', '', value)

                #create the first subelemet <payload> </payload>
                pay_element = ET.SubElement(root_element, "payload")
                #create the first child <value> </value>
                child = ET.SubElement(pay_element, "value")
                child.text = str(n1)

                #create the second child <phrase> </phrase>
                child = ET.Element("phrase")

                child.text = artist
                #now append
                pay_element.append(child)

                child = ET.Element("subsetmatching")
                child.text = "true"
                #now append
                pay_element.append(child)

                n1 = n1 + 1
                #txtfile.write(str(artist) + "\n")
                txtfile.write(artist + "\n")
                #print(value)
    t1 = artist

txtfile.close()
def indent(elem, level=0):
    i = "\n" + level*'\t'
    if len(elem):
        if not elem.text or not elem.text.strip():
            elem.text = i + '\t'
        if not elem.tail or not elem.tail.strip():
            elem.tail = i
        for elem in elem:
            indent(elem, level+1)
        if not elem.tail or not elem.tail.strip():
            elem.tail = i
    else:
        if level and (not elem.tail or not elem.tail.strip()):
            elem.tail = i

indent(root_element)
#View xml tree
print ( ET.tostring(root_element) )

output_file = open(xmlout, 'w' )
output_file.write( '<?xml version="1.0" encoding="utf-8"?>'+'\n' )
output_file.write( '<!--A VoxCommando Payload file-->' +'\n' )
output_file.write( ET.tostring(root_element) )
output_file.close()

« Last Edit: July 17, 2014, 09:34:58 PM by xtermin8r »
Neural Net Based Artificial Intelligence.

xtermin8r

  • $upporter
  • Sr. Member
  • *****
  • Posts: 366
  • Karma: 9
  • Crunchie
    • View Profile
Re: Voxcommando Media Player Classic Integration.
« Reply #27 on: July 17, 2014, 09:40:34 PM »
more to follow.
Neural Net Based Artificial Intelligence.

xtermin8r

  • $upporter
  • Sr. Member
  • *****
  • Posts: 366
  • Karma: 9
  • Crunchie
    • View Profile
Re: Voxcommando Media Player Classic Integration.
« Reply #28 on: July 17, 2014, 10:55:07 PM »
artist to m3u playlist, this script scans the musicvideos.xml file created by the 1st script ScanMusicVideos.py and extracts all entries containing artist name and creates a m3u playlist file for mpc.

Code: [Select]
#-------------------------------------------------------------------------------
# Name:        Scan Music VidcArtists to m3u
# Purpose:
#
# Author:      xtermin8r
#
# Created:     18/07/2014
# Copyright:   (c) xtermin8r 2014
# Licence:     To Kill
#-------------------------------------------------------------------------------
from itertools import groupby
import urllib, urllib2
import re
import os
from re import findall
from xml.etree import ElementTree as ET
import sys
import subprocess
import urllib

pathmpc = "E:\Appz\Media Players\MPC-HC.1.7.3.x86\mpc-hc.exe"
pathvc = "E:\Appz\Vox\VoxCommando_1.951\VoxCommando.exe"
m3ufile = open("E:\\Appz\\Vox\\payloads\\Artist_list.m3u", "wb")

xml = "E:\Appz\Vox\Payloads\musicvideos.xml"

#-------------------------------------------------------------------------------
# get comamnd line arguments
#-------------------------------------------------------------------------------
if(len(sys.argv) > 1):
    string1 = (sys.argv)
    # join list as a string
    string1 = ' '.join(string1)
    # regex commandline argument from vc
    string1 = (re.findall('.py (.*)',string1))
    #store match 0
    string1 = string1[0]
#-------------------------------------------------------------------------------
# vc stuff
#-------------------------------------------------------------------------------
#DEBUG
#string1 = 'andain'
url = urllib.URLopener()
url.open('http://127.0.0.1:8081/api/tts.speak&&playing music videos by  ' + string1)
#-------------------------------------------------------------------------------

value = []
phrase = []

def ReadXml():
    for child in root:
        global nodup
        c1 = (child.find('value').text)
        if c1 is not None:
            if string1.lower() in c1.lower():
                value = (c1.encode("UTF-8"))
                m3ufile.write(str(value) + "\n")
                #print value
                phrase.append(value)
    return

#MAIN
tree = ET.parse(xml)
root = tree.getroot()
m3ufile.write("#EXTM3U" + "\n")
ReadXml()
m3ufile.close()
subprocess.call([pathmpc, "E:\Appz\Vox\Payloads\Artist_list.m3u"])

vc command to execute the script:

Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 1.9.5.6-->
<command id="890" name="Play videos by Artist" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
  <action>
    <cmdType>Launch.Hidden</cmdType>
    <params>
      <param>E:\Appz\Programming\Python26\python</param>
      <param>E:\Appz\Vox\PY\Artist2m3u.py {PF.1}</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>OSD.ShowText</cmdType>
    <params>
      <param>{PF.1}</param>
      <param />
      <param>30</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <phrase>play music videos by</phrase>
  <payloadFromXML phraseOnly="False" use2partPhrase="False" phraseConnector="by" Phrase2wildcard="anyone" optional="False">E:\Appz\Vox\Payloads\ArtistVideos.xml</payloadFromXML>
</command>
« Last Edit: July 17, 2014, 11:11:39 PM by xtermin8r »
Neural Net Based Artificial Intelligence.

xtermin8r

  • $upporter
  • Sr. Member
  • *****
  • Posts: 366
  • Karma: 9
  • Crunchie
    • View Profile
Re: Voxcommando Media Player Classic Integration.
« Reply #29 on: July 19, 2014, 10:09:09 PM »
the long awaited video.

&feature=youtu.be
Neural Net Based Artificial Intelligence.

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7715
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Voxcommando Media Player Classic Integration.
« Reply #30 on: July 19, 2014, 11:46:57 PM »
Works great. :-)

rio14

  • Contributor
  • ***
  • Posts: 59
  • Karma: 4
    • View Profile
Re: Voxcommando Media Player Classic Integration.
« Reply #31 on: March 02, 2016, 05:08:23 PM »
hi
i downloaded   the mpc-hc, i liked it because its easy and simple, i need help to use commandes , for pause play and stop....
i copied the command group to my tree, there is localhoste and port, do i need change setting in tcp plugin or vc setting to get it working, can any one explain. thank you

PegLegTV

  • $upporter
  • Hero Member
  • *****
  • Posts: 500
  • Karma: 43
    • View Profile
Re: Voxcommando Media Player Classic Integration.
« Reply #32 on: March 02, 2016, 05:16:56 PM »
if you read the 2nd post xtermin8r explains that you need to change the port numbers in the commands and how to get the port number

I don't use MPC so I'm not sure if the commands still work sense they are 2 years old

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 2012
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: Voxcommando Media Player Classic Integration.
« Reply #33 on: March 02, 2016, 08:35:38 PM »
There are no VC settings to configure. This is not a program that VC officially supports.

If you want to use the http api that xtermin8r describes, you will need to enable the web interface in the media software. He explains this here:
http://voxcommando.com/forum/index.php?topic=1572.msg13746#msg13746

You can change the IP and port settings there if you need to.

Then all the commands are sent using the Scrape action in VC, as he shows in his examples.

To use the play, pause etc. commands, the movie or music you want to play first needs to be queued.

« Last Edit: March 02, 2016, 08:39:07 PM by nime5ter »
TIPS: POST VC VERSION #. Explain what you want VC to do. Say what you've tried & what happened, or post a video demo. Attach VC log. Link to instructions followed.  Post your command (xml)

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 2012
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: Voxcommando Media Player Classic Integration.
« Reply #34 on: March 03, 2016, 03:56:02 PM »
I accidentally moved jitterjames's response, when trying to move the separate youtube question to its own thread.

James wrote:

i need help to use commandes , for pause play and stop....

For very simple things like pause play and stop you may find it simpler to use keyboard emulation and the shortcut keys that MPC uses for these functions.

For support for your youtube question, see: http://voxcommando.com/forum/index.php?topic=2532.0
TIPS: POST VC VERSION #. Explain what you want VC to do. Say what you've tried & what happened, or post a video demo. Attach VC log. Link to instructions followed.  Post your command (xml)