AUTOMATION!! how to automatically process RSS shows. Rename/Move/Scrape unattended!
#1
So I'm having my first baby in a touch over two months. I figure I'm going to have a lot less free time to fiddle with things. So why not set up XBMC and my network to automatically sort and scrape new watchables as they come in off my torrent RSS feeds?

Well that was my justification anyways. I probably just wanted to fiddle.

I won't get into my old process, which was darn near to what I'm describing above, but not as instantaneous. With Prae5's point in the right direction I now have something better. Perhaps I'll explain the old method later if anyone is curious or the below method doesn't work for them. It piggy backs off a lot of the same stuff as this Lifehacker article just like much of the below.

What you'll need:

uTorrent
version shouldn't matter, so long as it has the ability to download incomplete files to a default location, then move the completed files to another location. the last several versions have had this for sure. I am using the current.

RSS feeds for your shows
Pretty much any shows. Though date based shows like the daily show or colbert don't need to use this process and can use another to automatically be sorted and scraped into XBMC. Ignore those two for now.

TVRename v2.1.1a6
Click the name to get it. Has to be this version. Can't be newer. It is the only one to support command line arguments, which we want.

Z-Cron
Click the link to get it. You don't necessarily need this, it's a Task Scheduler program. Windows and Linux have task schedules built in. I prefer using this one to Windoze's. Easy to configure, but more options. Free for home use.

Google Chrome
Yeah no DL links to that, you can find it I think. I personally still use Firefox as my browser, as I like adblock+ and some other extensions Chrome doesn't really have the equal of yet. But for this purpose, it has to be Chrome. Firefox forces a user prompt popup for a command we need to use - and this is supposed to be automated, remember!

My Scripts
Well not REALLY mine at all - the visual basic ones are modified versions of a script written by stewood on tvrename forum. I'll be posting the scripts in <code> tag below, copy them into .txt files, or if someone can host a very small .zip let me know.

XBMC web server
Turned on and with the proper port forwarded in your router (8080 default)
Reply
#2
How it works:

1. we will Configure uTorrrent to store the temporary files (while they are still downloading) into one folder.

2. We configure uTorrent so that when they are finished, uTorrent moves them to another folder

3. We have three visual basic scripts running (on any local network windows computer) which are watching that uTorrent "finished" folder, which do the following:

4. The three scripts are all watching the folder for content changes. When a file is moved there by uTorrent, the script starts TVRename, with the command line switches, silently in the background. TVRename compares the files to shows you have told TVRename you have collections for, and if it finds matches, it renames the files, and puts them into the show/season location you specified in TVrename.

5. The second script is also watching for changes to that same "finished" download folder, and when something does, uses chrome to send a command to XBMC to update its video library. It has a timer of 5mins after the watched folder changes before it executes, to give TVRename time to execute and move the file to the show/season folder that XBMC watches.

6. The third script also watches the folder, and is set to wait 5mins 30seconds after the folder contents change - its job is just to kill the chrome instance so that you don't collect another chrome instance every time a file gets downloaded.
Reply
#3
OK, Let's configure everything.

uTorrent
I'm going to assume you already know how to set up RSS feeds for shows. And have uTorrent installed. If not, there are plenty of other guides around. I'm not sure what would be different for vuze or transmission or what have you. Chime in if you know how these might be similarly configured.

Anyways, under preferences, folders, should look like this. You can use any folder names you want, just make note of them so they can be put into the scripts later. They do not have to be folders on the local machine running uTorrent. Mine aren't. Just map the drives in "my computer" if not. Both the default download location and finished download location should not be folders XBMC can see!
If you were using uTorrent labels to move your RSS feeded shows around, be sure to remove the labels, or label them so they all dump into that "finished" folder. Mine is called "unsorted video"

Image

TVRename

Download and install the version of TVRename linked above. Default location for installation. Run the program. Anytime you add an RSS feed for a new series, you will have to tell TVRename about it. As this is the first setup, tell it all the shows you have coming in that it will need to deal with.
On the bottom of the left hand pane, click "new" and you will see the dialog in the image below.

Type the name of the show into the search box and hit search. It should come back with a result - if not, broaden your search. Instead of "The Cleveland Show" try "Cleveland" for example. When you see the correct result, click it once to highlight it. Then fill out the info below - the important parts being "base folder" and "folder per season".

Base folder is the folder all the shows live under. Like C:\Video\Top Gear\ would be a base folder. If you just have that one folder for all your top gears, no individual season folders, leave folder per season unchecked. If you have a folder for each season, enter what each folder is called - if it is Season 01/2/3/4 etc, enter "Season " into the box. (with that trailing space, unless you have a format of like "Season01") Check "pad to two digits" if you use a 0 before single digit seasons. Make sure "do renaming" and "do missing" are checked but not "missing check for all episodes"

After you have entered all your shows, click the "finding and organizing" tab. Under "search folder", add the folder location that uTorrent is moving completed downloads to. When TVRename can't find an episode in your "base" folder tree, this is where it will look. If it finds anything in there, it will rename it to the proper format (TV Show Name - S00E00 - Episode Name.whatever) and then move it to the Base folder you specified for that show.
Image
Reply
#4
Script to start TVRename

Paste the text from the code box into a new text file. Edit the following:

make sure that tvrename.exe is at the C drive path indicated in line 2.

Change the line:
& "'Win32_Directory.Name=""s:\\\\video\\\\unsorted video""'")
to reflect where your personal uTorrent completed folder is. This should be the same folder you set as your "search" folder in TvRename as well. Note that the extra slashies and quotes are there for a reason. The path represented above is s:\video\unsorted video if you were entering it in windows explorer.

Code:
Set objShell = CreateObject("Wscript.Shell")

strComputer = "."
strCMD =  """c:\Program Files\TVRename\tvrename.exe"" /renamingcheck /renamingdo /missingcheck /fnocheck /fnodo /quit"
'Wscript.Echo strCMD
    'objShell.Run(strCMD)

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colMonitoredEvents = objWMIService.ExecNotificationQuery _
    ("SELECT * FROM __InstanceCreationEvent WITHIN 10 WHERE " _
        & "Targetinstance ISA 'CIM_DirectoryContainsFile' and " _
            & "TargetInstance.GroupComponent= " _
                & "'Win32_Directory.Name=""s:\\\\video\\\\unsorted video""'")

Do
    Set objLatestEvent = colMonitoredEvents.NextEvent
    strNewFile = objLatestEvent.TargetInstance.PartComponent
    arrNewFile = Split(strNewFile, "=")
    strFileName = arrNewFile(1)
    strFileName = Replace(strFileName, "\\", "\")
    strFileName = Replace(strFileName, Chr(34), "")
    'objShell.Run("notepad.exe " & strFileName)
    objShell.Run(strCMD)
Loop

Save the text file and rename it to <whateveryouwant>.vbs - you should get a "changing extension" warning from windows. Doubleclick the file to start it running. You should see wscript.exe in task manager if there are no compile errors. Once you know it's working, you can add a shortcut to it in the windows startup folder. To test if it is working, take one of your previously downloaded show episdoes and move it to the watched folder. Check windows Task Manager and you should see Tvrename.exe start a few seconds later. Within a minute or two, it will disappear from the watched folder and you should find it in the proper show/season location with the rest of that show's episodes.
Reply
#5
Script to update xbmc video library

This script is essentially the same as the script that launches TVrename - it watches the same folder, and is activated for the same reason - a file was added to the folder, or a filename in the watched folder was changed. When that happens, instead of launching TVRename, this script sleeps for five minutes (to give TV rename time to do its thing) and then starts chrome with a URL argument, which tells XBMC (if it is running) to execute a library update.
First, make sure your XBMC web server is turned on, and that you know the following: the IP address of your XBMC box, the port you have configured for the server (default 8080) and the username and password for login.
As before, copy the text from the code box to a new text file, and change the following:

in line 4, make sure chrome.exe is in that path - if you have it installed elsewhere, change the path to reflect where your chrome.exe is located. change "username:[email protected]:8080" to your xbmc web server username and password, and change the IP address and port to whatever your XBMC web server's is. You can paste the completed line above into a chrome brower address bar and it should log you into your web server. Then you know you have it right.
Again be sure that
& "'Win32_Directory.Name=""s:\\\\video\\\\unsorted video""'")
represents the path to your personal watched folder.

Code:
Set objShell = CreateObject("Wscript.Shell")

strComputer = "."
strCMD = """C:\Users\media\AppData\Local\Google\Chrome\Application\chrome.exe"" http://username:[email protected]:8080/xbmcCmds/xbmcHttp?command=ExecBuiltIn(UpdateLibrary(video))"
'wscript.Sleep(300000)
'Wscript.Echo strCMD
    'objShell.Run(strCMD)
    'objshell.SLeep(300000)

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colMonitoredEvents = objWMIService.ExecNotificationQuery _
    ("SELECT * FROM __InstanceCreationEvent WITHIN 10 WHERE " _
        & "Targetinstance ISA 'CIM_DirectoryContainsFile' and " _
            & "TargetInstance.GroupComponent= " _
                & "'Win32_Directory.Name=""s:\\\\video\\\\unsorted video""'")

Do
    Set objLatestEvent = colMonitoredEvents.NextEvent
    strNewFile = objLatestEvent.TargetInstance.PartComponent
    arrNewFile = Split(strNewFile, "=")
    strFileName = arrNewFile(1)
    strFileName = Replace(strFileName, "\\", "\")
    strFileName = Replace(strFileName, Chr(34), "")
    'objShell.Run("notepad.exe " & strFileName)
    Wscript.Sleep 300000
    objShell.Run(strCMD)
Loop

Save the file, and then rename it to <whateveryouwant>.vbs
Double click it to start the script watching the new content folder. Check the task manager and there should now be two wscript.exe entries.
Again, you can add a shortcut to your windows startup folder so that it runs everytime you reboot. Also note that you can use variations of the URL above to run just about any XBMC command - update library, clean library, export library, etc. Consult the wiki for the proper command and change the URL, and you can do just about anything either using a script, or saving the URL as a link in your browser bookmarks to do things manually.

To test this script you can do the same thing as last time - put a previously downloaded episode into the watched folder. A couple of seconds TVRename.exe will appear in your task manager, a min or two later the show will disappear, moved to the proper folder. Five minutes after you dropped the episode into the watched folder, a chrome browser window will open, with a blank web page showing "OK". Meaning that XBMC is executing the command. If you turn on your Xbox you will see it scanning for content.
Reply
#6
Script to kill the resulting Chrome window

So five minutes after the show hit the new content folder and TVrename did its thing, the previous script ordered XBMC to scan its library using a chrome window. Great. Now every time a show finishes downloading, you will have an unwanted chrome window that stays open until you physically click it closed. If you didn't check it for awhile, you could get dozens of windows opening, choking your system. So, this script waits until 5 minutes ~45 seconds after a new file hits the watched folder, giving TVrename time to do its thing, the chrome script time to send its command to XBMC, and then this final script will execute, killing the chrome browser. It uses windows' taskkill command to do so.

A possible snag is that it will kill *all* running chrome instances, so if you are sitting there using chrome to browse, it will kill your window. Not a problem for me, since I use firefox, but a problem if you are a chrome user, and are using it for other things at the time this script executes.

You can't go vice versa, and have the scripts first use firefox to send the XBMC update command, and then have the this script kill all firefox instances, because firefox can't send the update library command to XBMC without prompting you to accept the login to the XBMC web server. There used to be a way to disable this prompt in firefox's "about:config" settings, but that functionality has been broken for several versions. So if you are a Chrome user, the only workarounds I can suggest are to run this script and a chrome instance on another computer that you don't use, or see if you can configure Opera or some other browser to execute with an available command line argument to visit a specific website upon opening.

Anyways, on to the script.
In this script, you should only have to change the watched folder path, same as the previous two.

Code:
Set objShell = CreateObject("Wscript.Shell")

strComputer = "."
strCMD = "taskkill /f /im chrome.exe"
'wscript.Sleep(350000)
'Wscript.Echo strCMD
    'objShell.Run(strCMD)
    'objshell.SLeep(350000)

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colMonitoredEvents = objWMIService.ExecNotificationQuery _
    ("SELECT * FROM __InstanceCreationEvent WITHIN 10 WHERE " _
        & "Targetinstance ISA 'CIM_DirectoryContainsFile' and " _
            & "TargetInstance.GroupComponent= " _
                & "'Win32_Directory.Name=""s:\\\\video\\\\unsorted video""'")

Do
    Set objLatestEvent = colMonitoredEvents.NextEvent
    strNewFile = objLatestEvent.TargetInstance.PartComponent
    arrNewFile = Split(strNewFile, "=")
    strFileName = arrNewFile(1)
    strFileName = Replace(strFileName, "\\", "\")
    strFileName = Replace(strFileName, Chr(34), "")
    'objShell.Run("notepad.exe " & strFileName)
    Wscript.Sleep 350000
    objShell.Run(strCMD)
Loop

same deal - save to text file, rename to .vbs, double click to start it watching, add shortcut to windows startup folder.
Note that the sleep times for the chrome scripts above are "300000" and "350000" respectively - that's in milliseconds, so 300000 is five minutes. You can change them if you feel the need to. Will still work.
Reply
#7
So - that should be that - full automation. When you sit down to watch XBMC, new content should be ready and waiting for you, mere minutes after it being downloaded.

Gotchas:

if the file you download has a horribly formatted name, TvRename may not know what it is. It has several regex masks it applies, so it catches most everything, but if it's truly bad, it won't. If you are good with regular expressions, startup tvrename and there is a menu where you can add regular expressions to catch oddball naming conventions. Or just change the filename by hand, and because the filename changed while the file was sitting in the "watched" folder, the scripts will take over from there and move it/scrape it.

Daily show and Colbert Report are examples of shows that Tvrename can't really deal with, because release groups on the web don't tend use a season/episode number file naming format. They are something like

the.daily.show.03.05.10.malcolm.gladwell{EZ}HDTV.Xvid.avi

So best not to set up your RSS feeds to dump those files into the main watched folder for TVrename. Use uTorrent's "label" system so that the completed files are moved by uTorrent to the proper show/season folder, like c:\video\the daily show\season 15\
XBMC can scrape the date string alright - and if you want to you can copy and modify the folder watching scrips set above (the second two) to watch for new files, and send the signal via chrome to scan.

That's it on the RSS automation.
The following are extra methods I use to automate other tasks.
Reply
#8
Extras - Database/collection management, backup, and cleanup on a schedule


What this combo of scripts does is send a command every night, overnight, to XBMC. The first cleans the video library (removes entries for deleted/unavailable files) The second exports XBMC's video library - saving nfo, thumbnail, actor info files alongside the video files for new content that day (it does not overwrite existing files). The reason for the first command is obvious, it sucks to click on something to watch and it's gone, because it's deleted or has been renamed or somesuch. The reasoning for the second is that it provides a backup in case XBMC's library is accidentally deleted or corrupted. Yeah, I've done that often. It also creates an NFO for the new files - I often need to edit NFO files, particularly for Movies, so that I can add entries for downloaded apple HD trailers, or add the movie to a set, for example, documentaries, which helps keep my library easily navigable.
The method -
1. Write a batch script for each command. Where chrome is started with the appropriate URL to order XBMC to clean or export the library. A third batch script to kill chrome windows after they run.
2. Use Z-Cron to schedule a nightly time for each script to run, and to run the kill chrome script a min or two later.


Ok let's do it. Batch script for library clean in text box
Change the path to Chrome .exe
Change the URL so that it has your username/password, and the IP address/port of your XBMC box.

Code:
"C:\Users\media\AppData\Local\Google\Chrome\Application\chrome.exe" http://username:[email protected]:8080/xbmcCmds/xbmcHttp?command=ExecBuiltIn(CleanLibrary(video))

Paste the code to text file, rename to anythingyouwant.bat

Code for library export. Same deal with path and URL stuff.

Code:
"C:\Users\media\AppData\Local\Google\Chrome\Application\chrome.exe" http://xbmc:[email protected]:8080/xbmcCmds/xbmcHttp?command=ExecBuiltIn(exportlibrary(video,true,thumbs,true,overwrite,true,actorthumbs,true))

Script to kill chrome. no edit needed, also save as .bat

Code:
taskkill /f /im chrome.exe

Now we will use Z-Chrome to schedule and run these batch files. Download it (free for home use) from the link above in the first post. Install normally. Let it install as a system service. Reboot if it asks. Should see z-cron.exe in task manager if the service is running properly. May have to go to control panel -> administrative tasks -> services and start it if you didn't reboot. If you have windows 7 you may need to give it rights to run programs so you don't get windows nannying you and making you approve everything that executes. That may hold true for all the scripts I've offered in fact. I dunno, I disabled all that crap.

Run Z-Cron from start menu. Hit "task" on the lefthand menu, and you see this dialog

Image

Give the library clean task a name (umm, like mine?). Click the button next to the batch script line and navigate to the batch script you made for library cleaning. Click the "scheduler" tab and you will see the screen below. Click the scheduler button and you can see the two windows I have in the pic.

Image

Mouse over the grid and you will see the time in bold change - check the box that corresponds to the time you want the script to run. I chose 3:30am.
The clean script will run right on top of any video you happen to be playing, unlike a library scan, so you don't want to run this script when you might be using XBMC. So overnight while you sleep is good.

Click "ok" on that grid page after you have set a time. On the scheduling tab again, click "everyday" and it should autocheck all days of the week.

You can click over to the "run as" tab and enter your windows username/password if you want, which will run the commands as your user, but I don't think this is necessary. I did it anyway. click back to the first screen above where you set the name of the task, and check the box "activate task". Also check "RunAs job" IF you set up your user/pass in run as tab. Again I don't think this is necessary. May be on some locked down systems. Then click Save.

Repeat those steps for another task, this time pointing to the script for library export that you made. Set the time it runs at least 15 minutes after than the library clean. Library clean shouldn't take more than five minutes even on big libraries, but you don't want the scripts overlapping. I have mine starting at 4:30

Repeat those steps one more time for your Chrome kill script. Same process, only when you are setting a time, set it twice. I put a checkbox at 3:40am and 4:40am. The chrome window does *not* have to be open the whole time after the commands have been sent to XBMC and the scans are being run. Chrome has done it's job within a couple seconds of opening. I have the script wait ten minutes to close the chrome windows because...I dunno. Why not.
Reply
#9
Postscripts:

You don't in theory need to use the fancy schmancy VBS scripts to have tvrename kick into action every time a file comes in. Using a scheduled task to execute the command

"c:\Program Files\TVRename\tvrename.exe"" /renamingcheck /renamingdo /missingcheck /fnocheck /fnodo /quit"

say, every hour, should also work. This is how I used to have it set up. Problem was, it wouldn't always work properly. Pretty regularly, when TVrename would start to run on its schedule in the background, it would pop up a prompt box while doing the missing check - with me not there to answer the prompt, the application would just sit there.
Only when I started using the folder watching VBS script did everything work properly, every time. With the added benefit that TvRename runs only as often as it needs to - and instantly, no waiting.

Similarly, I used to run three python scripts from the XBMC scripts folder which scheduled library maintenance. library update ran every hour, and li. clean, and lib export ran once a day. That worked fairly well, though every time XBMC was restarted, the countdown "clock" to start the scripts would restart as well. As a result, the "once per day" scripts were barely ever running. I've had to restart XBMC almost daily of late, as my XBMC seems to hang when thetvdb.com is running slowly.

In case anyone wants those working python scripts for library updating/cleaning/exporting XBMC, here those are.

put all four files in /home/xbmc/scripts

save this as autoexec.py - no edit needed

Code:
import xbmc, xbmcgui

xbmc.executebuiltin('XBMC.AlarmClock( VideoLibraryExport, XBMC.RunScript(special://home/scripts/VideoLibraryExport.py),1438,true)')

xbmc.executebuiltin('XBMC.AlarmClock( VideoLibraryCleaner, XBMC.RunScript(special://home/scripts/VideoLibraryCleaner.py),719,true)')

xbmc.executebuiltin('XBMC.AlarmClock( VideoLibraryUpdater, XBMC.RunScript(special://home/scripts/VideoLibraryUpdater.py),59,true)')

save as VideoLibraryCleaner.py

Code:
import xbmc, xbmcgui
xbmc.executebuiltin('CleanLibrary(video)')
xbmc.executebuiltin('AlarmClock( VideoLibraryCleaner, RunScript(special://home/scripts/VideoLibraryCleaner.py),719,true)')

save as VideoLibraryUpdater.py

Code:
import xbmc, xbmcgui
xbmc.executebuiltin('UpdateLibrary(video)')
xbmc.executebuiltin('AlarmClock(VideoLibraryUpdater, RunScript(special://home/scripts/VideoLibraryUpdater.py),59,true)')

save as VideoLibraryExport.py

Code:
import xbmc, xbmcgui
xbmc.executebuiltin('exportlibrary(video,true,thumbs,true,overwrite,true,actorthumbs,true)')
xbmc.executebuiltin('AlarmClock( VideoLibraryExport, RunScript(special://home/scripts/VideoLibraryExport.py),1438,true)')

All the intervals can be adjusted by changing the numbers in the script. Numbers are in MINUTES from the time of XBMC starting.


So that's what I have. Very long, but tried to make it as step by step as possible. Let me know if you have any questions, and DEFINITELY let me know if you have a better way and can streamline the process.
Reply
#10
very cool.

i do basically the same thing with rtorrent and a couple of other scripts, but i don't have it in one nice bundle like you do.

maybe if i get around to it, i will write something similar for rtorrent.

what is nice about rtorrent is that the script can be executed as soon as the torrent is completed without anything external.
Reply
#11
oh man, I totally wish uTorrent had that option. It has the ability to run a file/command of your choosing when it's done downloading something - but that has to be set manually for every torrent, every time. Can't set up a default program/command for anything.

I did set up a command to have a txt message sent to my iphone when a torrent is done, or have an email sent, but again, have to set that manually. No automation involved.

People been asking uTorrent to implement something like that foreva though, probably not happening.
Reply
#12
Thanks a lot for the walkthrough and the scripts! Once I get them all working in concert, it's going to be pretty slick.

Much appreciated!
Reply

Logout Mark Read Team Forum Stats Members Help
AUTOMATION!! how to automatically process RSS shows. Rename/Move/Scrape unattended!1