in

andy vt's tools & blog

automating lazy

File Watcher custom Batch file

Last post Tue, Jun 4 2013 11:37 AM by Zorna. 7 replies.
Page 1 of 1 (8 items)
Sort Posts: Previous Next
  • Sat, Apr 6 2013 12:15 PM

    File Watcher custom Batch file

    OK I think I am close to fully automating everything just the way I want it.  But I've gone about it a slightly different way.  Rather than using the profiles in DVRMSToolbox I crafted a batch file that does everything I need.  This was initially primarily to test that the command line tools would accomplish what I needed.  It started fairly simple and very manual with multiple steps and batch files, but has morphed into a fairly automated albeit manually triggered process.

    The goal here is to convert files in the MKV container into WTV so they will play nice with my MC extenders.  The batch file I've created basically takes the format:  mkv2wtv "input folder name (year)" "input file name"

    the mkv2wtv file

    • checks that the user has administrative rights
    • checks that the file (.mkv) exists in the directory provided
    • If the above items are OK then it determines if the mkv contains DTS audio
    • Then based on the above:
      • It extract the DTS audio and converts it to ac3 then re-packages a temp.mkv (with ac3 audio) then converts that to the WTV container OR
      • it simply repackages the MKV to WTV (in the event DTS was not detected)
    • Then of course it cleans up after itself.

    The batch file appears to be fully debugged and works like a champ, now I want the extra nerd points to automate everything fully.  I expect filewatcher is the way to go about this, but seems now that all this is built and working that the easiest thing would be to have filewatcher call the batch file when it discovers a new mkv file.  I would need to pass the file name and potentially the folder name (just need the folder within the watched folder - the path to the watched folder is embeded in the batch file).  Curious if there is a way to do this?

    Details for clarity:
    Watched Folder: \\opennas\media\movies\ --> this would be the watched folder in FW it is also embeded in the batch file so it knows this much of the path to start with.

    New Movie arrives:  Savnzbd places the new movie in a folder within the watched dir above in the format "movie name (year)" within that folder the movie is in the format "movie name.mkv".  Currently I don't need the extension for the batch to run, it appends .mkv but I can change this to accomodate if need be.

    I can add a post process script to SABNzd+ but that piece runs on a different linux box, and being these tools are all windows based...

    Ideally FW would watch the folder, if a new file is detected (wait 5 mins to be sure SabNZBd gets a chance to finish copying) then run my batch file and pass the folder name and file name to the batch file.

     

    If this isn't possible I can start trying to understand the profiles more and build a profile that does everything I did in the batch file, initially I was getting delayed due to my knowledge gap on the profiles so I used the batch file just to test that the conversion would even work, but now that the batch is working like a champ just looking to leverage that work.

    Thanks for taking the time to view my post - appreciate any assistance.


  • Sun, Apr 7 2013 7:42 AM In reply to

    Re: File Watcher custom Batch file

     UPDATE

    OK, I was able to figure this out for the most part with some more googling, and stare-and-compare with some other pre-defined profiles.  I now have this working when invoked manually from the DTB GUI.

     Have a couple of questions:

    • Still working on getting FileWatcher to do that last step in automation, but the process isn't doing anything, and the log stops at 'Start...' it never processes any files or queues them up.
      • A Little about the FW setup Listing only the fields that I have changed from default
        • Watched Directory: \\opennas\media\movies
        • Watched Ex: .mkv
        • Recursive watch: Checked
          • Process Files Missing Artifacts and Include Watched Folders are also checked which is the default.
    • FW appears to be listening on 9199 for IPC, what is the function/purpose?  If it's a way to remotely trigger FW to scan that could be some extra coolness, I could have it sit idle until it is told to scan (triggered by a script from the system putting the file on the NAS).
    I built a process condition that is true if the file size is not 0 and the extension is mkv, I've adjusted my batch file to rename the original mkv to mkvx when complete, it will eventually delete the original file (once I'm comfortable with everything).  Again the issue right now is nothing is happening, anyone 

    Thanks for any help

    Pack3tL0ss

     

    In case anyone needs it, here is what I did to get the batch file to be ran from the DTB profile:

    • create profile to first take the context of "inputFile"and based on Regex ^((.*\\)(.*)\.(.*))\z with output $2 set context of InputPath (a new context created for my need)
    • Same as above but with ReplaceRegex $3 to get the filename without extension
    • Use Durrant.Plugin.RunExternal to call batch file:  full path to .bat with extension.  Passing arguments "%InputPath%" "%InputFile%" "%FileName%"
    Modified batch file so it no longer check for elevated priveledges, turns out this wasn't actually required I just had a flaw in my script.  Batch file collects those 3 variables passed in and stores them in variables in the file and processes.  The context OutputFile is not needed from DTB, the batch file places the temporary files and the final output in the same folder, then deletes all the temp stuff and eventually will delete the original file.
  • Mon, Apr 8 2013 6:08 AM In reply to

    Re: File Watcher custom Batch file

    I guess I'm wondering what you are expecting to happen. FileWatcher will only take off if a file is created, it won't just start processing a watched folder. You can make this happen though by opening the DVRMSToolbox GUI and processing a directory of your choice. If you are indeed creating new files and FileWatcher is not kicking off, please post the logs for the individual file and the filewatcher service. If necessary, I may need to see screenshots of your settings, but we'll see.
  • Mon, Apr 8 2013 6:10 AM In reply to

    Re: File Watcher custom Batch file

    Also, I'm not sure recursive watching works, if you look through the forums there are lots of people with issues there.
  • Mon, Apr 8 2013 10:40 PM In reply to

    Re: File Watcher custom Batch file

     Thanks for the replies, that does help.  I misunderstood how FW was working.  Based on the first process condition that checked the tools field to be sure it wasn't processed already I thought it was periodically scanning the directory.

    I was able to add a file to the root of the watched directory and it processed as intended, so that was cool.

     

    sccrgoalie1:
    Also, I'm not sure recursive watching works, if you look through the forums there are lots of people with issues there.

    This part is a bummer.  I'll have to toy with it to see if dumping everything in a flat directory will work in Media Browser (the WMC plugin), right now there are sub folders for each movie.

    Just to clarify what I'm doing per your original reply:
    I have a system which downloads movies for me and automatically renames the files and places them in a nice directory structure.  So I end up with a folder in the form <Movie Title> (Year) with the movie in the folder in the form <title>.extension (the file type is normally an mkv)  Right now it looks like everything is automated except for dealing with the recursive watch or moving away from sub-folders to accomodate.  The profile grabs the context/variables I need and calls a batch file passing the variables (which runs the various DTB functions I need via cli, cleans up etc.)  The batch file will evaluate the MKV to see if it has DTS audio, if it does it will extract the dts, convert it to ac3 then make a new mkv, the new mkv will then be converted to wtv (now with AC3 audio).  If it doesn't contain dts audio it simply converts the original to wtv.  

    This is all done to accomodate the Media Center extenders which don't handle dts audio and don't play mkvs well.  I know I can do most of the same stuff natively within a profile (not sure if I could evaluate for DTS and process based on result), but the batch file was complete (originally built just to test stuff) so this seemed to be the faster route.

    Thanks for the clarification, and the heads up on the recursive watch

  • Tue, Apr 9 2013 5:59 PM In reply to

    Re: File Watcher custom Batch file

    One possibility to get around the recursive watch issue. You can have your program download the movie to a folder not watched by the DTB and then have the file renamed as you like. Then copy it over to folder the DTB is watching and have it do it's process and let the DTB create the folder. Actually this might not work because you are looking to get the year in the folder name and the DTB will have no way to find that. Another option would be to download the file to the DTB directory, let the file process and complete. Then install YAMMM which is built into the Ceton Companion services and I think it will automatically rename and create folders for you. Let me know if you want me to elaborate on either of these options.
  • Wed, Apr 10 2013 7:42 PM In reply to

    Re: File Watcher custom Batch file

     I got it going, I may do some additional tweaking but I flattened the directory and got rid of the folders, the media center extender recognizes them either way.  

     So right now:  sabnzbd+ downloads the file does it's post-processing (repair, extract, rename, move) and places the file in the watched folder.  FW's process conditions look for any mkv and converts them to wtv with audio conversion if necessary, I added a step in the batch file to move the original mkv to a folder outside the watched directory.  That way I have the original mkv if I want to put the movie on the tablet.  

    The change I'm considering, which is an easy change, would be something like what you mentioned.  I'd have the mkv placed in a non-watched folder, have FW kickoff DTB from there, and essentially accomplish the same thing, except I'd send the resulting wtv to the folder WMC uses for movies rather than process from within the final folder.  Same result, but seems more tidy - just keeps the final folder from ever being cluttered with the temporary files and logs created during the process ( the script cleans them up regardless).

     I'm covered on meta-data.  When I flattened the directory I changed the renamer to add the date with the movie title.  The program that plays on the extender goes out and gets all the posters, actor info, etc based on the filename.  The format '<Movie Title> (Year) ' gives it enough to go on.

     

    Thanks for your help.  I'm more excited watching movies automagically appear in the foler correctly formatted, than I am to watch any of them.

     

  • Tue, Jun 4 2013 11:37 AM In reply to

    • Zorna
    • Not Ranked
    • Joined on Tue, Jun 4 2013

    Re: File Watcher custom Batch file

    I would look a copy of this batch file. I'm trying to watch a folder for a newly created file. I then want to OCR the file get some pertinent information from it and use this information to populate a topaz signature screen in order to accept a signature that will then be used to sign a receipt and save a copy of the signed receipt to a repository.
Page 1 of 1 (8 items)
@2008 andy vt
Powered by Community Server (Non-Commercial Edition), by Telligent Systems