Windows TV Show Post Processing Script for AppleTV

Come up with a useful post-processing script? Share it here!
Post Reply
randyharris
Full Member
Full Member
Posts: 146
Joined: January 21st, 2010, 5:36 pm

Windows TV Show Post Processing Script for AppleTV

Post by randyharris »

Thanks to code that others have posted on these forums, some googling, and a helpful person over at the www.Computing.net forums, M2, I was able to put together a nice Windows script that fully processes TV shows for an AppleTV.

In limited testing this is working as I hoped it would. If you try it out please let me know your results, good or bad.

This script does not delete the original downloaded TV show, that is left for the user to delete when they are ready.

The script is currently set to transcode MKV/AVI/MP4/WMV and tag it for AppleTV into an M4V file, and it puts it into the iTunes folder which automatically adds content into iTunes.

Originally I was going to add code to grab and tag the Cover Art, but I decided not to after all because the images over at www.ShareTV.org are really low resolution, I prefer how iTunes just grabs a frame from the file better.

You can download a zipped copy of the script here.


TWO SETTINGS TO CONSIDER:

1) This is setup for how I have SORTING enabled in SAB, which is such that it outputs the TV Shows like this:

TV Show Name - SxxExx.ext

This is my sort string for TV Shows in SABnzbd: %sn/%sn - S%0sE%0e.%ext

You'll have to match the SORTING option for TV or modify the script if you use something else.

2) You will need to set SAB so that it does not download Samples. To do this go into the SAB web interface, CONFIG | SWITCHES | and set IGNORE SAMPLES to "do not download".



Thanks and hopefully this will help somebody else.


Randy

For your visual pleasure, here is the script.

Code: Select all

@ECHO OFF

:: ##################################
::
:: IMPORTANT USAGE NOTES
::
:: READ THIS NOTE OR THE SCRIPT WILL NOT WORK
::
:: You need to be sure that the "Automatically add to iTunes" location matches your computer, search for it
:: it is way down in the script on the 'move' line.
::
:: Also you need to either ensure that AtomicParsley and HandBrakeCLI are in those locations listed,
:: or modify the locations listed to match where they reside on your system.
::
:: SABnzbd needs to be set to not download Samples
:: To do this go into the SAB web interface, CONFIG | SWITCHES | and set IGNORE SAMPLES to "do not download".
::
::
:: This script is setup for how I have SORTING enabled in SAB, which is such that it outputs the TV Shows like this:
::
:: TV Show Name - SxxExx.ext
::
:: This is my sort string for TV Shows in SABnzbd: %sn - S%0sE%0e/%sn - S%0sE%0e.%ext
::
:: If you want to delete the source files and directory when this job is complete
:: search for "Delete Source Directory" and take out the "::" in front of the "rmdir" line below it.
::
:: You can receive an email of the summary of the jobs that this script runs on by doing:
:: SAB Web interface, CONFIG | EMAIL | check the "always" box for Email Notificaion on Job Completion
:: and complete the "Email Account Settings" (search the SAB forums if you're not sure how to do this.)
::
:: ##################################


:: What's another word for Thesaurus?  -- Steven Wright

Echo.
Echo.
Echo ------------------------------
Echo ------------------------------
Echo Start of the PostProcessing  Script
Echo.
Echo.

set AtomicParsley="C:\Program Files\SABnzbd\AtomicParsley\AtomicParsley.exe"
set HandBrakeCLI="C:\Program Files\SABnzbd\HandBrake\HandBrakeCLI.exe"
setlocal enableextensions enabledelayedexpansion

set name=%3
set name=%name:"=%

Echo.
Echo.
Echo ------------------------------
Echo ------------------------------
Echo SABnzbd+ Output Parameters Definitions:
Echo.
Echo 1: The final directory of the job (full path)
Echo 2: The original name of the NZB file
Echo 3: Clean version of the job name (no path info and ".nzb" removed)
Echo 4: Newzbin report number (may be empty)
Echo 5: Newzbin or user-defined category
Echo 6: Group that the NZB was posted in e.g. alt.binaries.x
Echo 7: Status of post processing. 0 = OK, 1=failed verification, 2=failed unpack, 3=1+2 (0.5.0 only!)
Echo.
Echo SABnzbd+ Output Parameters Values:
Echo.
Echo 1: %1
Echo 2: %2
Echo 3: %3
Echo 4: %4
Echo 5: %5
Echo 6: %6
Echo 7: %7
Echo.
Echo End of SABnzbd+ Output Parameters
Echo.
Echo.

Echo.
Echo.
Echo ------------------------------
Echo ------------------------------
Echo Determining the file type from known list...
Echo.
Echo (Known list: MKV, AVI, MP4, WMV)
Echo.

pushd %1

Echo.
Echo The file(s) found:

dir /b

Echo.
if exist *.mkv set filetype=.mkv && GOTO Transcode
if exist *.avi set filetype=.avi && GOTO Transcode
if exist *.mp4 set filetype=.mp4 && GOTO Transcode
if exist *.wmv set filetype=.wmv && GOTO Transcode
Echo.
Echo.
Echo Sorry, no valid video file found
Echo.
Echo The directory searched for a file is:
Echo %1

GOTO :EOF


:tagTVshow

Echo.
Echo.
Echo ------------------------------
Echo ------------------------------
Echo Determining the Tag information...

for /f "tokens=* delims= " %%a in ('dir/b *.m4v') do (
set path=%%~DPa
set filename=%%~NXa
for /f "tokens=1-2 delims=-" %%i in ("%%a") do (
set show=%%i
set show=!show:~0,-1!
set S=%%~Nj
set season=!S:~2,2!
set episode=!S:~5,2!
)
)

Echo.
Echo.
Echo Tag information found:
Echo.
Echo Path to file = %path%
Echo File name = %filename%
Echo.
Echo Show = %show%
Echo Season = %season%
Echo Episode = %episode%
Echo.
Echo  Writing the Tag information to the M4V file...
Echo.
Echo.

%AtomicParsley% "%path%%filename%" --overWrite --title "%show%" --genre "TV Shows" --stik "TV Show" --TVShowName "%show%" --TVEpisodeNum %episode% --TVSeason %season%  >nul

Echo.
Echo.
Echo Moving the Tagged M4V to iTunes Auto-Add directory.
Echo.
Echo.

Move "%path%%filename%" "C:\Users\randyharris\Music\iTunes\iTunes Music\Automatically Add to iTunes\." >nul

Echo.
Echo.
Echo Move along, nothing to see here.
Echo.
Echo Really, all done, go check iTunes for your TV Show.
Echo.
Echo.


:: Delete Source Directory
:: Take out the "::" in front of the line below to delete the source files
:: rmdir /s /q %1

GOTO :EOF


:Transcode

Echo A valid file has been found.
Echo.

for /f "tokens=* delims=" %%i in ('dir/b/a-d *%filetype%') do (
      echo Transcoding: %%i
      echo ------------------------------
      echo ------------------------------
      echo.
      echo The next section of information is output from HandBrake,
      echo try your best to ignore it.
      echo.
      echo
      %HandBrakeCLI% --input "%%i" --output "%%~ni%.m4v" --preset="AppleTV" >nul
)

Echo.
Echo Transcoding complete.
Echo.
Echo.


GOTO tagTVshow
Last edited by randyharris on April 3rd, 2010, 3:08 pm, edited 1 time in total.
gitface
Newbie
Newbie
Posts: 1
Joined: September 19th, 2011, 3:17 pm

Re: Windows TV Show Post Processing Script for AppleTV

Post by gitface »

Hi,

Just registered to thank you for this script - works a treat.

A few gotchas for anyone wanting to use it. The zip version attached is slightly different from the one pasted in the post above. The zip file script contains the following line in the transcode section:

Echo (Ignore the output from HandBrake)

This line should be removed as it breaks out of the for loop that the line is contained in and prevents the transcode from running (specifically the close brackets at the end is the problem)

I also needed to right click on the AtomicParsely.exe executable and enable compatibility mode (WinXP 32bit) as it otherwise crashed on my Win7 x64 system.

I reverted from Handbrake 0.9.5 to 0.9.4 as I think the latest version was having an issue on my system, but I was in the midst of fixing other problems with the script so this might not have been necessary.

Thanks - it works a treat.
Elmomcd
Newbie
Newbie
Posts: 1
Joined: August 3rd, 2013, 1:51 am

Re: Windows TV Show Post Processing Script for AppleTV

Post by Elmomcd »

First of all i want to say thank you for this script.
Like a lot of people using this forum i'm a complete beginner when it comes to scripts and programming.
What i'm wanting is to add 2 more features to what currently is working very well and i was wondering if you could help.

I want it to metatag the file before it puts it into itunes with Series/Episode/Description and TV Show art. Also i would like to implement the iPhone notification using Prowl.

Could you please advise me what code and where to put it in the current .cmd file please :) or atleast help me learn/understand how to add features like this so i can have a play and attempt to do it myself.

Much appreciated.
Post Reply