Automatic tv show converting and other stuff

Come up with a useful post-processing script? Share it here!
Post Reply
relman
Release Testers
Release Testers
Posts: 46
Joined: September 30th, 2008, 2:42 am

Automatic tv show converting and other stuff

Post by relman »

I have been reading on these forums for a while now and thought it might be a nice idea to add my script I have been working on for tv shows for a while now.

The script does a few things. Firstly it will check if it is a avi or an mkv. then do one of two things.

1. If an avi, it will convert it into a m4v file for iphones. It will also set the meta tag values on the file for such things as episode name, season and episode numbers. I have added an extra something which has about a 80% success rate which means it will download the tv show art from a site and add that into the meta file information so in itunes it displays a nice tvshow logo/poster. I have made it so it only needs to download it the first time so every other episode can just use the one which is already downloaded. If it can't find the tvshow it saves a jpg called Need-%tvshowname%.jpg. You can then manually get the image you want for the show and called it the same but remove the need- at the beginning.

2. If it is a mkv file it will convert the file to complient xbox360 format in mp4 format. Not WMV sorry.

It then does any clean up needed.

I know it is messy, I have patched together scripts some locations are hardcoded and could do with some rewriting to be more user friendly which I will do at some point. Also to get the tv show images you need wget for windows which is a small freeware app, use google.

You can remove the first part as its just a calls a VBS script I wrote which updates my SQL database with the download information so I can query it for information.

Code: Select all


@echo off
set name=%3
set name=%name:"=%
set dirname=%1
set dirname=%dirname:"=%

Echo ###############################
Echo ###############################
Echo ###
Echo ### Running Script against 
Echo ### %3
Echo ###############################
Echo ###############################


echo cscript c:\scripts\tvshows.vbs %4 %3 %6 %1

Echo ###############################
Echo ###############################
Echo ###
Echo ### SQL Update run,
Echo ### Now running iPhone video 
Echo ### convert.
Echo ###
Echo ###############################
Echo ###############################

cd /d %1
if exist *.avi goto AVI
if exist *.mkv goto MKV

:AVI
Echo -----------------------------------------------------------------------

dir /b %1\*.avi >"c:\FFmpeg\list.dir"
for /f %%Q in (c:\FFmpeg\list.dir) do C:\FFmpeg\ffmpeg.exe -y -i %1\%%Q -f mp4 -vcodec libx264 -level 30 -s 480x320 -r 30000/1001 -b 500k -bt 500k -bufsize 2000k -maxrate 768k -g 250 -coder 0 -threads auto -acodec libfaac -ac 2 -ab 128k "D:\Share\Disk1\-=-iPhone-=-\tvshows\%name%.m4v"



Echo ###############################
Echo ###############################
Echo ###
Echo ### iPhone convert completed,
Echo ### now moving files.
Echo ###
Echo ###############################
Echo ###############################

GOTO tagTVshow

Echo -----------------------------------------------------------------------

:tagTVshow

Echo ###############################
Echo ###############################
Echo ###
Echo ### Appling mp4 tagging
Echo ### 
Echo ### %name%
Echo ###
Echo ###############################
Echo ###############################

REM split down into component parts
FOR /F "TOKENS=1-3 DELIMS=-" %%a in ("%name%") DO set show="%%a"
FOR /F "TOKENS=1-3 DELIMS=-" %%a in ("%name%") DO set seasXep="%%b"
FOR /F "TOKENS=1-3 DELIMS=-" %%a in ("%name%") DO set eptitle="%%c"

REM clean up leading or trailing spaces
SET eptitle=%eptitle:" =%
SET eptitle=%eptitle: "=%
SET eptitle=%eptitle:"=%
SET show=%show:" =%
SET show=%show: "=%
SET show=%show:"=%
SET m4vfile="D:\Share\Disk1\-=-iPhone-=-\tvshows\%name%.m4v"

call :ToLowCase

:ToLowCase
setlocal enableextensions
set var_=%show%
set var_=%var_:A=a%
set var_=%var_:B=b%
set var_=%var_:C=c%
set var_=%var_:D=d%
set var_=%var_:E=e%
set var_=%var_:F=f%
set var_=%var_:G=g%
set var_=%var_:H=h%
set var_=%var_:I=i%
set var_=%var_:J=j%
set var_=%var_:K=k%
set var_=%var_:L=l%
set var_=%var_:M=m%
set var_=%var_:N=n%
set var_=%var_:O=o%
set var_=%var_:P=p%
set var_=%var_:Q=q%
set var_=%var_:R=r%
set var_=%var_:S=s%
set var_=%var_:T=t%
set var_=%var_:U=u%
set var_=%var_:V=v%
set var_=%var_:W=w%
set var_=%var_:X=x%
set var_=%var_:Y=y%
set var_=%var_:Z=z%
set var_=%var_:=†%
set var_=%var_:Ž=„%
set var_=%var_:™=”%
set var_=%var_:"=%
set var_=%var_:!=%
set var_=%var_: =_%
endlocal & set shownocaps=%var_%



REM remove all spaces (and quotes)
SET seasXep=%seasXep:"=%
SET seasXep=%seasXep: =%
 

REM split down the season and episode number
FOR /F "TOKENS=1-2 DELIMS=xX" %%a in ("%seasXep%") DO set season=%%a
FOR /F "TOKENS=1-2 DELIMS=xX" %%a in ("%seasXep%") DO set episode=%%b

REM now tag the file with this information for iTunes

Echo ## Episode = %value%
Echo ## Show = %show%
Echo ## Show No caps = %shownocaps%
Echo ## Season = %season%
Echo ## Episode = %episode%
Echo ## SeasonXEp = %seasXep%
Echo ## fileExt = %fileExt%
Echo ## Artwork = %artwork%



SET imagename=%shownocaps%-show.jpg
SET Artworkurl=http://sharetv.org/images/%shownocaps%-show.jpg
SET Imagepath=E:\temp\artwork\%shownocaps%-show.jpg
SET extravalue=--artwork %Imagepath%

IF EXIST "%imagepath%" GOTO Skipimagedownload

CD /d e:\temp\artwork\
e:\temp\artwork\wget.exe "%artworkurl%"

IF NOT EXIST "%imagepath%" SET extravalue=
Del need-%show%.jpg /q /f
IF EXIST soon.jpg ren soon.jpg need-%show%.jpg


:Skipimagedownload

Echo ##
Echo ## Now running Atomic Parsley
Echo ## Running d:\Atomic\AtomicParsley.exe %m4vfile% --overWrite --title "%value%" --genre "TV Shows" --stik "TV Show" --TVShowName "%show%" --TVEpisodeNum %episode% --TVSeason %season%

d:\Atomic\AtomicParsley.exe %m4vfile% --overWrite --title "%value%" --genre "TV Shows" --stik "TV Show" --TVShowName "%show%" --TVEpisodeNum %episode% --TVSeason %season% %extravalue%









Echo ###############################
Echo ###############################
Echo ###
Echo ### Mp4 tagging applied.
Echo ### 
Echo ###
Echo ###############################
Echo ###############################
GOTO MOVEFILES
Echo -----------------------------------------------------------------------

:MOVEFILES
Echo -----------------------------------------------------------------------

cd /d %1
move *.avi ..\
del *.nfo /q /f
cd /d e:\..
del list.dir /q /f

Echo -----------------------------------------------------------------------
GOTO END

:MKV
Echo -----------------------------------------------------------------------


:mkv
cd /d %1
Copy *.mkv E:\temp\
cd /d E:\temp\
ren *.mkv input.mkv
cd /d d:\xenonmkv\
XenonMKV.exe -inputfile E:\temp\input.mkv -outputfolder E:\temp\
cd /d e:\temp
if exist input*1.mp4 ren input*1.mp4 %3-1.mp4
if exist input*2.mp4 ren input*2.mp4 %3-2.mp4
if exist input.mp4 ren input.mp4 %3.mp4
del input.mkv /q /f

Echo ###############################
Echo ###############################
Echo ###
Echo ### Xbox 360 convert completed,
Echo ### now moving files.
Echo ###
Echo ###############################
Echo ###############################

cd /d %1
move *.mkv ..\
del *.nfo /q /f
cd /d E:\temp\
move *.mp4 "D:\Share\Disk1\-=-Xbox360-=-\tvshows\"



Echo -----------------------------------------------------------------------
GOTO END


:END


Echo ###############################
Echo ###############################
Echo ###
Echo ### Files move completed,
Echo ### Script completed.
Echo ###
Echo ###############################
Echo ###############################
Post Reply