news

Install Subliminal on Qnap to retrieve subtitles for your shows

Rss feed for topic ArticleArticle - Posted by: christian On 02-12-2013 @ 22:02 - Updated on: 03-12-2013 @ 21:02

I always used a fully automatic way to retrieve new subtitles for tv shows on my Qnap Nas. Since Bierdopje stopped last week and Auto Sub stopped working because of this I was searching for a new way to retrieve subtitles automatically. I found Subliminal. Since there is no qpkg for Qnap available I created my own bash script. The script will auto start subliminal on qnap startup and run it every few hours after this, it will also update subliminal automatically on every startup if needed. This all can be done from the Qnap app center.

The script will start Subliminal on startup and run Subliminal to search for Dutch and English subtitles every 2 hours.

To get Subliminal working on your Qnap Nas you should login to your NAS by SSH(for example you can use Putty for this).

Create a directory under: "/share/MD0_DATA/.qpkg" called "Subliminal" (without the quotes).

After this pull the Subliminal source by using git(the script uses Subliminal/subliminal as directory for this): "git clone https://github.com/Diaoul/subliminal.git"

You can install Subliminal yourself by running: "python setup.py install" from the subliminal directory.

If you get "error: /opt/local/lib/python2.5/site-packages (in --site-dirs) is not on sys.path" then you can fix this by using the following command: "export PYTHONPATH=/opt/local/lib/python2.5/site-packages". After this you have to run the subliminal install command again and no error should show up this time.

After this create the startup script in the Subliminal package root(/share/MD0_DATA/.qpkg/Subliminal)

#! /bin/sh
### BEGIN INIT INFO
# Provides: Subliminal application instance
# date: 02-12-2013
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts instance of Subliminal
# Description: starts instance of Subliminal using start-stop-daemon
### END INIT INFO
############### EDIT ME ##################
QPKG_NAME=Subliminal
QPKG_DIR=
DAEMON=/opt/bin/python2.7
DAEMON_OPTS="/share/MD0_DATA/.qpkg/Optware/local/bin/subliminal -l nl en -a 8w -c /share/MD0_DATA/.qpkg/Subliminal/subliminal.cache.dbm --log-file /share/MD0_DATA/Download/Subliminal_log.txt -v"
MOVIE_DIRECTORY="/share/MD0_DATA/TV Shows/"

add_cron(){
#adds the subtitle finderjob to the crontab
if [ x"$(/bin/cat /etc/config/crontab | /bin/grep "subliminal")" = x ]; then
/bin/echo "15 */2 * * * ${DAEMON} ${DAEMON_OPTS} \"${MOVIE_DIRECTORY}\"" >> /etc/config/crontab
fi
#restart crontab
/usr/bin/crontab /etc/config/crontab
}

remove_cron(){
#removes the update job from the crontab
if [ -n "$(/bin/cat /etc/config/crontab | /bin/grep "/subliminal")" ]; then
/bin/sed -i '/subliminal/d' /etc/config/crontab
fi
#restart crontab
/usr/bin/crontab /etc/config/crontab
}

update_subliminal(){
#update subliminal to last version from git
cd /share/MD0_DATA/.qpkg/Subliminal/subliminal
git fetch origin
reslog=$(git log HEAD..origin/master --oneline)
if [[ "${reslog}" != "" ]] ; then
echo "Updating Subliminal to newest version from Git!"
git pull
echo "Install new version"
export PYTHONPATH=/opt/local/lib/python2.5/site-packages
${DAEMON} setup.py install
else
echo "no update available"
fi
}


case "$1" in
start)
echo "Starting $QPKG_NAME"

if [ `/sbin/getcfg ${QPKG_NAME} Enable -u -d FALSE -f /etc/config/qpkg.conf` = UNKNOWN ]; then
/sbin/setcfg ${QPKG_NAME} Enable TRUE -f /etc/config/qpkg.conf
elif [ `/sbin/getcfg ${QPKG_NAME} Enable -u -d FALSE -f /etc/config/qpkg.conf` != TRUE ]; then
echo "${QPKG_NAME} is disabled."
exit 1
fi
#remove log file
rm /share/MD0_DATA/Download/Subliminal_log.txt

update_subliminal

/bin/echo "Running Subliminal now with the following arguments:"
/bin/echo ${DAEMON} ${DAEMON_OPTS} ${MOVIE_DIRECTORY}
${DAEMON} ${DAEMON_OPTS} "${MOVIE_DIRECTORY}"

/bin/echo "Add Subliminal to the crontab to run every few hours"
add_cron
;;

stop)
echo "Stopping $QPKG_NAME"
remove_cron
for pid in $(/bin/pidof python); do
/bin/grep -q "subliminal" /proc/$pid/cmdline && /bin/kill $pid
done
/bin/sleep 2
;;

restart|force-reload)
echo "Restarting $QPKG_NAME"
$0 stop
$0 start
;;

*)
N=/etc/init.d/$QPKG_NAME
echo "Usage: $N {start|stop|restart|force-reload}" >&2
exit 1
;;
esac
exit 0

 

The script can be downloaded here.

The arguments can be modified and the path to your tv show/movie directory must be changed. From default it's downloading dutch and english subtitles and only scans files from the last 8 weeks. Logging is enabled(see "/share/MD0_DATA/Download/Subliminal_log.txt")  and the log file is removed on every startup

To see Subliminal as a qpkg in the app center and make it start on qnap startup automatically you have to add a new qpkg to the qpkg.conf(can be found in "/etc/config/qpkg.conf").

I'm using the following code:

[Subliminal]
Name = Subliminal
Enable = FALSE
Version = Newest
QPKG_File =
Date = 2013-12-02
shell = /share/MD0_DATA/.qpkg/Subliminal/Subliminal.sh
Install_Path = /share/MD0_DATA/.qpkg/Subliminal
Author = Christian
RC_Number = 134

Now everything is ready and you can start Subliminal from the app center on your qnap. From now on you will always have the latest subtitles.

If you need support feel free to contact me trough email or leave a comment below

 Download: Subliminal.sh


Comments:

Jon
06-05-2014 - 03:31

Thanks for the script. I can get subliminal to work by executing command in script from command line but I am not having luck running the script manually. Script is below. Help is appreciated. #! /bin/sh ### BEGIN INIT INFO # Provides: Subliminal application instance # date: 02-12-2013 # Required-Start: $all # Required-Stop: $all # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: starts instance of Subliminal # Description: starts instance of Subliminal using start-stop-daemon ### END INIT INFO ############### EDIT ME ################## QPKG_NAME=Subliminal QPKG_DIR= DAEMON=/opt/bin/python2.7 DAEMON_OPTS="/share/HDA_DATA/.qpkg/Optware/local/bin/subliminal -l en -c /share/HDA_DATA/.qpkg/Subliminal/subliminal.cache.dbm --log-file /share/HDA_DATA/Download/Subliminal_log.txt -v -- " MOVIE_DIRECTORY="/share/HDA_DATA/Multimedia/Video/Movies/Foreign/" add_cron(){ #adds the subtitle finderjob to the crontab if [ x"$(/bin/cat /etc/config/crontab | /bin/grep "subliminal")" = x ]; then /bin/echo "15 */2 * * * ${DAEMON} ${DAEMON_OPTS} \"${MOVIE_DIRECTORY}\"" >> /etc/config/crontab fi #restart crontab /usr/bin/crontab /etc/config/crontab } remove_cron(){ #removes the update job from the crontab if [ -n "$(/bin/cat /etc/config/crontab | /bin/grep "/subliminal")" ]; then /bin/sed -i '/subliminal/d' /etc/config/crontab fi #restart crontab /usr/bin/crontab /etc/config/crontab } update_subliminal(){ #update subliminal to last version from git cd /share/HDA_DATA/.qpkg/Subliminal/subliminal git fetch origin reslog=$(git log HEAD..origin/master --oneline) if [[ "${reslog}" != "" ]] ; then echo "Updating Subliminal to newest version from Git!" git pull echo "Install new version" export PYTHONPATH=/opt/local/lib/python2.5/site-packages ${DAEMON} setup.py install else echo "no update available" fi } case "$1" in start) echo "Starting $QPKG_NAME" if [ `/sbin/getcfg ${QPKG_NAME} Enable -u -d FALSE -f /etc/config/qpkg.conf` = UNKNOWN ]; then /sbin/setcfg ${QPKG_NAME} Enable TRUE -f /etc/config/qpkg.conf elif [ `/sbin/getcfg ${QPKG_NAME} Enable -u -d FALSE -f /etc/config/qpkg.conf` != TRUE ]; then echo "${QPKG_NAME} is disabled." exit 1 fi #remove log file rm /share/HDA_DATA/Download/Subliminal_log.txt update_subliminal /bin/echo "Running Subliminal now with the following arguments:" /bin/echo ${DAEMON} ${DAEMON_OPTS} ${MOVIE_DIRECTORY} ${DAEMON} ${DAEMON_OPTS} "${MOVIE_DIRECTORY}" /bin/echo "Add Subliminal to the crontab to run every few hours" add_cron ;; stop) echo "Stopping $QPKG_NAME" remove_cron for pid in $(/bin/pidof python); do /bin/grep -q "subliminal" /proc/$pid/cmdline && /bin/kill $pid done /bin/sleep 2 ;; restart|force-reload) echo "Restarting $QPKG_NAME" $0 stop $0 start ;; *) N=/etc/init.d/$QPKG_NAME echo "Usage: $N {start|stop|restart|force-reload}" >&2 exit 1 ;; esac exit 0

Jon
06-05-2014 - 03:37

Forgot to mention.... error is below. : command not found 18: 'ubliminal.sh: line 19: syntax error near unexpected token `{ 'ubliminal.sh: line 19: `add_cron(){

Christian
14-05-2014 - 11:50

Are you sure the file is not named incorrectly since I guess the name should be Subliminal.sh instead of ubliminal.sh

Jeffrey
23-09-2018 - 10:38

Heb je misschien een makkelijkere handleiding? ik kom al niet in de eerste directory!!! Heb je een handleiding met wellicht screenshots van hoe men dit moet doen? Ik kom er helemaal niet uit wijs.

Leatha
11-12-2020 - 19:18

My spouse and I stumbled over here coming from a different web address and thought I should check things out. I like what I see so now i'm following you. Look forward to looking over your web page yet again. https://t.me/s/BuyLactase where exactly is lactase in the brush border where exactly is lactase in the brush border

Buford
11-02-2024 - 13:15

15 Facts Your Boss Would Like You To Know You Knew About Accidents Attorney Near Me accidents attorney near me

https://Waste-Ndc.pro/com
25-03-2024 - 20:31

You can definitely see your skilpls within the article you write. The arena hopes for more passionate writers like you whho are not afraid to say how they believe. All the time go after youur heart. https://Waste-Ndc.pro/community/profile/tressa79906983/