Page 1 of 1
OS X + HandBrake + Convert to iPhone
Posted: September 20th, 2009, 11:59 am
by imthenachoman
Has anyone made any OS X scripts that convert downloaded movies/shows to iPhone format using HandBrake?
I'm not very good at scripting so I don't know where/how to start by making my own....
Re: OS X + HandBrake + Convert to iPhone
Posted: October 5th, 2009, 3:37 am
by engine9
Hi,
I'm not that good at scripting but I managed to do a script which convert my tv show files, tag them, and add them to iTunes.
My file are named like this : Serie - 1x01 - Title.avi
based on that here's the script:
Code: Select all
dirname=$1
filename=$3
tag_filename_split=$filename
# I save the tagged file and delete them later in case anything goes wrong during the process.
dir_tag="path/to/save/tagged/files"
#I save the original file and delete them manually in case anything goes wrong during the process.
savepath="path/to/save/original/files"
#here's the conversion:
#You can change the conversion presets according to handbrake docs.
HandBrakeCLI -i "$dirname/$filename.avi" -o "$dirname/$filename.mp4"
mv -fv "$dirname/$filename.avi" "$savepath/"
#as all the informations to tag the file are present in the filename we need to extract them
tag_filename_split=`echo $tag_filename_split | awk '{
n = split ( $0, a, " - " )
for ( i = 1; i <= n; i++ ) {
printf("%s:", a[ i ] );
}
#the title of the show
show=`echo $tag_filename_split | awk -F: '{print $1}'`
#the season and episode of the episode
seasonepisode=`echo $tag_filename_split | awk -F: '{print $2}'`
#the season of the episode
season=`echo $seasonepisode | awk -Fx '{print $1}'`
#the number of the episode
episode=`echo $seasonepisode | awk -Fx '{print $2}'`
#the title of the episode
title=`echo $tag_filename_split | awk -F: '{print $3}'`
}'`
#here's I tag the file converted file using AtomicParsley:
AtomicParsley "$dirname/$filename.mp4" --genre "TV Shows" --stik "TV Show" --title "$title" --TVShowName "$show" --TVEpisode "$season$episode" --TVEpisodeNum "$episode" --TVSeason "$season" --output "$dir_tag/$filename.mp4"
# I delete the not tagged mp4 file
rm -fv "$dirname/$filename.mp4"
#Then I add the tagged file to iTunes using AppleScript:
osascript << EOT
tell application "iTunes"
set posix_path to "$dir_tag/$filename.mp4"
set mac_path to posix_path as POSIX file
add mac_path to library playlist 1
end tell
EOT
# I delete the tagged file as iTunes copies the file to the proper library folder.
rm -fv "$dir_tag/$filename.mp4"
Re: OS X + HandBrake + Convert to iPhone
Posted: October 5th, 2009, 1:32 pm
by imthenachoman
engine9 wrote:
Hi,
I'm not that good at scripting but I managed to do a script which convert my tv show files, tag them, and add them to iTunes.
My file are named like this : Serie - 1x01 - Title.avi
based on that here's the script:
Code: Select all
dirname=$1
filename=$3
tag_filename_split=$filename
# I save the tagged file and delete them later in case anything goes wrong during the process.
dir_tag="path/to/save/tagged/files"
#I save the original file and delete them manually in case anything goes wrong during the process.
savepath="path/to/save/original/files"
#here's the conversion:
#You can change the conversion presets according to handbrake docs.
HandBrakeCLI -i "$dirname/$filename.avi" -o "$dirname/$filename.mp4"
mv -fv "$dirname/$filename.avi" "$savepath/"
#as all the informations to tag the file are present in the filename we need to extract them
tag_filename_split=`echo $tag_filename_split | awk '{
n = split ( $0, a, " - " )
for ( i = 1; i <= n; i++ ) {
printf("%s:", a[ i ] );
}
#the title of the show
show=`echo $tag_filename_split | awk -F: '{print $1}'`
#the season and episode of the episode
seasonepisode=`echo $tag_filename_split | awk -F: '{print $2}'`
#the season of the episode
season=`echo $seasonepisode | awk -Fx '{print $1}'`
#the number of the episode
episode=`echo $seasonepisode | awk -Fx '{print $2}'`
#the title of the episode
title=`echo $tag_filename_split | awk -F: '{print $3}'`
}'`
#here's I tag the file converted file using AtomicParsley:
AtomicParsley "$dirname/$filename.mp4" --genre "TV Shows" --stik "TV Show" --title "$title" --TVShowName "$show" --TVEpisode "$season$episode" --TVEpisodeNum "$episode" --TVSeason "$season" --output "$dir_tag/$filename.mp4"
# I delete the not tagged mp4 file
rm -fv "$dirname/$filename.mp4"
#Then I add the tagged file to iTunes using AppleScript:
osascript << EOT
tell application "iTunes"
set posix_path to "$dir_tag/$filename.mp4"
set mac_path to posix_path as POSIX file
add mac_path to library playlist 1
end tell
EOT
# I delete the tagged file as iTunes copies the file to the proper library folder.
rm -fv "$dir_tag/$filename.mp4"
Does the script work for you? I keep getting an error:
Code: Select all
168:180: execution error: iTunes got an error: Can’t make some data into the expected type. (-1700)
Any thoughts?
Re: OS X + HandBrake + Convert to iPhone
Posted: October 5th, 2009, 2:14 pm
by imthenachoman
I think I fixed it. I was missing a "/" on the set posix_path to "$DIR/${i%.*}.mp4" line.
Re: OS X + HandBrake + Convert to iPhone
Posted: January 27th, 2010, 6:14 pm
by randyharris
imthenachoman wrote:
I think I fixed it. I was missing a "/" on the set posix_path to "$DIR/${i%.*}.mp4" line.
Can this code be updated so that it converts either AVI or MKV?
Thanks
Re: OS X + HandBrake + Convert to iPhone
Posted: January 27th, 2010, 6:25 pm
by imthenachoman
http://forums.sabnzbd.org/http://forums ... 175#p25175
I updated it a while ago. Should work with avi and mkv. Converts to iPhone and adds season, episode information in iTunes. Let me know what you think...
Re: OS X + HandBrake + Convert to iPhone
Posted: February 1st, 2010, 6:37 pm
by imthenachoman
Re: OS X + HandBrake + Convert to iPhone
Posted: February 1st, 2010, 10:11 pm
by inpheaux