[Script] Periscope/Subliminal Subtitles Script
Posted: Sun Jan 22, 2012 5:48 pm
In case anyone is interested, I created this script for automatic subtitles download using periscope. It's to be configured in execute plugin on torrent completion and looks for english subtitles for AVIs and MKVs. Maybe in the future I'll make one with video file recognition using file magic number (instead of extensions) and supporting archives.
This new version also supports folders and subfolders, and temporarily (I hope) disables language selection because of periscope issue #124. Feel free to remove the hack if it works for you.
Needless to say it's provided AS IS, no warranties (but it works for me )
For periscope installation, you should follow guidelines on http://code.google.com/p/periscope/. My test environment is an headless debian stable, I installed periscope using python-periscope_0.2.4-1_all.deb
This new version also supports folders and subfolders, and temporarily (I hope) disables language selection because of periscope issue #124. Feel free to remove the hack if it works for you.
Needless to say it's provided AS IS, no warranties (but it works for me )
Code: Select all
#!/bin/bash
# Configuration
videoext=('AVI' 'MKV' 'MP4');
language="en"
# Code
log() { logger -t periscope "$@"; echo "$@"; }
# Check if a value exists in an array
# @param $1 mixed Needle
# @param $2 array Haystack
# @return Success (0) if value exists, Failure (1) otherwise
# Usage: in_array "$needle" "${haystack[@]}"
# See: http://fvue.nl/wiki/Bash:_Check_if_array_element_exists
in_array() {
local hay needle=$1
shift
for hay; do
[[ $hay == $needle ]] && return 0
done
return 1
}
# Paramters extraction
thash=$1
fname=$2
fpath=$3
level=$4
level=$(( level + 1 ))
log "Called with parameters $thash, $fname, $fpath, recursion level=$level"
if (( level > 3 )); then
log "Max recursion level reached, exiting"
exit
fi
# Check if fpath is a folder or a regular file
if [ -d "$fpath/$fname" ]; then
log "Folder detected, analyzing contents"
find "$fpath/$fname"/* -print0 | while read -d $'\0' rFile; do
log "Checking file or folder $rFile"
# Only on handled extensions
fext=`echo ${rFile##*.}|tr '[a-z]' '[A-Z]'`
if [ -d "$rFile" ] || in_array "$fext" "${videoext[@]}" ; then
log "Recursion on file or folder $rFile"
rFileBase=$(basename "$rFile")
$0 "$thash" "$rFileBase" "$fpath/$fname" "$level" &
fi
done
else
fext=`echo ${fname##*.}|tr '[a-z]' '[A-Z]'`
log "Extension: $fext"
if in_array "$fext" "${videoext[@]}" ; then
log "Downloading subtitle for $fpath/$fname"
# Temporary fix for periscope issue #124
# periscope --language=$language "$fpath/$fname"
periscope "$fpath/$fname"
else
log "Skipping extension $fext"
fi
fi
log "Execution terminated"