Page 1 of 1

[Script] Periscope/Subliminal Subtitles Script

Posted: Sun Jan 22, 2012 5:48 pm
by ctrl
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 :D)

Code: Select all


# Configuration
videoext=('AVI' 'MKV' 'MP4');

# 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:
in_array() {
    local hay needle=$1
    for hay; do
        [[ $hay == $needle ]] && return 0
    return 1

# Paramters extraction

level=$(( level + 1 ))

log "Called with parameters $thash, $fname, $fpath, recursion level=$level"

if (( level > 3 )); then
   log "Max recursion level reached, exiting"

# 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" &


   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"
      log "Skipping extension $fext"

log "Execution terminated"

For periscope installation, you should follow guidelines on My test environment is an headless debian stable, I installed periscope using python-periscope_0.2.4-1_all.deb

Re: [Script] Subtitles script for execute plugin

Posted: Sat Jan 28, 2012 11:51 am
by ctrl
Edit: now with subfolders recursion

Re: [Script] Subtitles script for execute plugin

Posted: Sun Jan 29, 2012 12:19 pm
by acemiperson
Thanks to ctrl,
i tried ur script yesterday, however if the name of the directory or file include space (" ") , this script fails. So, i rewrite it using python :

Code: Select all

import fnmatch
import os
import sys

torrent_id = sys.argv[1]
torrent_name = sys.argv[2]
save_path = sys.argv[3]
full_path='%s/%s' %( save_path ,torrent_name)

print 'test:',full_path,os.path.isfile(full_path)

if  os.path.isfile(full_path):
    myCmd='periscope "%s" -l en -f' %( full_path )
    for root, dirnames, filenames in os.walk(full_path):
     for filename in fnmatch.filter(filenames, '*.avi'):
        recFullPath='%s/%s' %( root ,filename)
        myCmd='periscope "%s"  -l en -f' %( recFullPath )

Bye :)

Re: [Script] Subtitles script for execute plugin

Posted: Sat Feb 04, 2012 11:56 am
by ctrl
I didn't catch the space issue, I'll check it. I updated again the original script because there was an issue with recursion that now should be fixed. Unfortunately, I'm still missing python for now :)

Re: [Script] Subtitles script for execute plugin

Posted: Sat Feb 04, 2012 8:54 pm
by ctrl
Fixed space in folder issue and added an & on periscope call because sometimes it hangs and this hangs deluge right after. Not a neat solution anyway.

Re: [Script] Subtitles script for execute plugin

Posted: Sat Sep 01, 2012 11:20 am
by anonymous_user
Dont work for me, even when trying to run it manualy

Code: Select all

sh /media/-Arhiiv-/Filmid/Filmid/By year/2012/08 - August/The.Cabin.In.The.Woods.2011.DVDRip.XviD-EXViD/exvid-cabinwoods.avi 4: Syntax error: "(" unexpected

Re: [Script] Subtitles script for execute plugin

Posted: Sat Sep 01, 2012 1:54 pm
by Cas
Its a bash script not sh, so run it with bash.

Re: [Script] Subtitles script for execute plugin

Posted: Wed Sep 05, 2012 9:35 am
by anonymous_user
Thx, got it working.

Now the periscope has moved to new project called subliminal

any new updates for the script?

Re: [Script] Periscope Subtitles Script

Posted: Sun Sep 16, 2012 10:28 pm
by rasjani
I have a script that for deluge that works with either periscope or subliminal .. Albeit Subliminal support is still not 100% done because it doesn't (yet) support configuration file. I have a patch for that coming though and hopefully it will get merged to upstream..

script can be cloned from here:

and my fork of subliminal if you feel adventurous is here:

IF you want to give this one a try, you should clone config-dev branch of my subliminal fork, create a config file for it (described) in README and add subliminal into @downloaders array in the subdltrigger in initialize method ..

PS. Both scripts could and most likely are: buggy ..

PS1. 1st of October: subdltrigger updated and included some instructions in the github page.