Notice: This forum has been recovered from an old backup, so some content, links, and dates may be outdated. The forum is currently read-only while we restore sign-in and registration functionality. Details

If you find this forum valuable and would like to help keep it online, donations to help cover hosting and domain costs are greatly appreciated, but never expected. You can support the forum through Buy Me a Coffee or Ko-fi. Thank you for helping preserve the EventGhost community.

python to parse eg.event.payload path

If you have a question or need help, this is the place to be.
Post Reply
Flook
Posts: 20
Joined: Thu Mar 04, 2010 1:07 pm

python to parse eg.event.payload path

Post by Flook »

I've previously gotten help to create an awesome python script that parses eg.event.payload to give me only the filename at the end so that I can email it to me. The thread is here http://www.eventghost.org/forum/viewtop ... f=2&t=2462 and this is the final code:

Code: Select all

from os import path
fp = eg.event.payload[0]
head, tail = path.split(fp)
name, ext = path.splitext(tail)
eg.result  = "New Episode of %s" % name
eg.globals.testVar = eg.result
This code is parsing the event.payload that was created from the directory watcher plugin.

I am trying to create a similar one that gives me just the path of the file instead of just the file name.
example event.payload: (u'\\\\HTPC\\Torrent-Finished\\TV\\exampleShow\\example.mkv',)
I would like to get: "\\HTPC\Torrent-Finished\TV\exampleShow"
I will then create a variable with that result and use the variable for a path in a command line operation. I'm also not sure if I can use expressions like {eg.globals.testVar} in the Start Application actions command line area of evenghost. I was able to use {eg.globals.testVar} in fields of the E-mail plugin before....edit expressions do work fine in the command line field.

I've been trying to figure this out myself with no real python knowledge. It looks like i need to figure out the:

Code: Select all

head, tail = path.split(fp)
name, ext = path.splitext(head)
eg.result  = name
Right now this code gives me part of the path "\\HTPC\Torrent-Finished\TV". I'm just short one more subdirectory.

Code: Select all

from os import path
fp = eg.event.payload[0]
head, tail = path.split(fp)
name, ext = path.splitext(head)
eg.result  = name
eg.globals.miscPath = eg.result
print eg.globals.miscPath
I'm doing this so that I can enter my custom variable path into the command line for the program SCRU. It unrars files from one directory to another. With this it will be able to unrar from a specific directory based on the path of my newly finished download.
Flook
Posts: 20
Joined: Thu Mar 04, 2010 1:07 pm

Re: python to parse eg.event.payload path

Post by Flook »

I just got it after about a 100 variations. I needed to change

name, ext = path.splitext(tail) to
name, ext = path.splitext(fp)

Final code:

Code: Select all

from os import path
fp = eg.event.payload[0]
name, ext = path.splitext(fp)
eg.result  = name
eg.globals.miscPath = eg.result
example of my use of the eg.globals.miscPath variable:

Code: Select all

"{eg.globals.miscPath}" "Z:\- Misc Video\Example Folder\New Files"
This is entered into the command line options of eventghost's Start Application Action Item that is starting the program SCRU. It now extracts files from the variable path and puts them in a never changing path ("Z:\- Misc Video\Example Folder\New Files").
Flook
Posts: 20
Joined: Thu Mar 04, 2010 1:07 pm

Re: python to parse eg.event.payload path

Post by Flook »

Thought it was working but for weird names it cleans it up too much.

(u'\\\\HTPC\\Torrent-Finished\\Misc\\example.DVDRip.XviD-name',)

comes out to
\\HTPC\Torrent-Finished\Misc\example.DVDRip

It's missing the end ".XviD-name"

Any ideas?
Flook
Posts: 20
Joined: Thu Mar 04, 2010 1:07 pm

Re: python to parse eg.event.payload path

Post by Flook »

I now have it working! Probably not the cleanest as I'm sire this could have been done in one python script. I played with python stuff for a while and ended up with just the end I was missing but could not combine the beginning and end so I created two scripts, one for the proper beginning, and one for the end of the path.

Script one creating the variable miscPath1:

Code: Select all

from os import path
fp = eg.event.payload[0]
name, ext = path.splitext(fp)
eg.result  = name
eg.globals.miscPath1 = eg.result
print eg.globals.miscPath1
example output for original path of (u'\\\\HTPC\\Torrent-Finished\\Misc\\example.DVDRip.XviD-name',): \\HTPC\Torrent-Finished\Misc\example.DVDRip

Script two creating the variable miscPath2:

Code: Select all

from os import path
fp = eg.event.payload[0]
name, ext = path.splitext(fp)
eg.result  = path.splitext(fp)[1]
eg.globals.miscPath2 = eg.result
print eg.globals.miscPath2
example output: .XviD-name

Now I just combine the two in the command line part of launching SCRU:

Code: Select all

"{eg.globals.miscPath1}{eg.globals.miscPath2}" "Z:\- Misc Video\example folder\New Files"
leboff
Posts: 1
Joined: Sat Sep 18, 2010 1:39 am

Re: python to parse eg.event.payload path

Post by leboff »

Hey, I realize this post is a little old but i think what you were looking for is path.abspath.

So

Code: Select all

from os import path
fp = path.abspath(eg.event.payload[0])
eg.globals.miscPath = fp
I could even probably skip the fp stuff and just say miscPath = path.abspath, but you get the idea.
This way you dont worry about splitting text or anything getting confused by dots in the directory name.


Thanks for your help with the python script idea though. I'm doing something very similar to what you have going on, and I think I've finally got it to work!
Flook
Posts: 20
Joined: Thu Mar 04, 2010 1:07 pm

Re: python to parse eg.event.payload path

Post by Flook »

Awesome!! Thanks for the reply. Mine has been working great but this is much more simple and exactly what I was looking for.

I have to say it feels great watching my automated system work. Just the idea that I'm able to specifically unrar newly downloaded content to another directory, rename, download library data and update my XBMC database, send an email to me saying what I downloaded, seed for a specific amount of time and then delete the files, all automatically without a single touch of a button, is amazing.
Post Reply