[Script] Periscope/Subliminal Subtitles Script

Suggest, post, or discuss plugins for Deluge
Post Reply
ctrl
New User
New User
Posts: 5
Joined: Sat Jan 21, 2012 4:34 pm

[Script] Periscope/Subliminal Subtitles Script

Post 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
Last edited by ctrl on Sat Feb 04, 2012 8:53 pm, edited 3 times in total.
ctrl
New User
New User
Posts: 5
Joined: Sat Jan 21, 2012 4:34 pm

Re: [Script] Subtitles script for execute plugin

Post by ctrl »

Edit: now with subfolders recursion
acemiperson

Re: [Script] Subtitles script for execute plugin

Post 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 :)
ctrl
New User
New User
Posts: 5
Joined: Sat Jan 21, 2012 4:34 pm

Re: [Script] Subtitles script for execute plugin

Post 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 :)
ctrl
New User
New User
Posts: 5
Joined: Sat Jan 21, 2012 4:34 pm

Re: [Script] Subtitles script for execute plugin

Post 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.
anonymous_user
Member
Member
Posts: 40
Joined: Sat Jan 31, 2009 7:28 am

Re: [Script] Subtitles script for execute plugin

Post 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
http://www.bugmenot.com
Cas
Top Bloke
Top Bloke
Posts: 3679
Joined: Mon Dec 07, 2009 6:04 am
Location: Scotland

Re: [Script] Subtitles script for execute plugin

Post by Cas »

Its a bash script not sh, so run it with bash.
anonymous_user
Member
Member
Posts: 40
Joined: Sat Jan 31, 2009 7:28 am

Re: [Script] Subtitles script for execute plugin

Post 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?
http://www.bugmenot.com
rasjani

Re: [Script] Periscope Subtitles Script

Post 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.
Post Reply