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