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

#!/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"


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

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

#!/usr/bin/python
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 )
    os.system(myCmd)
else:
    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 )
        os.system(myCmd)


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 subtitles_download_deluge.sh /media/-Arhiiv-/Filmid/Filmid/By year/2012/08 - August/The.Cabin.In.The.Woods.2011.DVDRip.XviD-EXViD/exvid-cabinwoods.avi
subtitles_download_deluge.sh: 4: subtitles_download_deluge.sh: 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

https://github.com/Diaoul/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:

https://github.com/rasjani/subdltrigger

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

https://github.com/rasjani/subliminal/tree/config-dev

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.