Jump to content

Run bash script


ionutt

Recommended Posts

Hi I need to run a bash script right after subtitle download.

 

This is the script I need to run:

#!/bin/bash
ORIGINAL="$1"
ISO=iso-8859-1
UTF=utf-8
ICONV="iconv -f $ISO -t $UTF"
CHECK=`file "${ORIGINAL}" | grep -i iso-8859`
	if [ "$CHECK" = "" ]; then
		exit 1;
	else
		FILENAME="${ORIGINAL/.rum/}"
		FILENAME="${FILENAME/.srt/}.romanian.srt"
		$ICONV < $ORIGINAL > "$FILENAME"
		sed -i 's:þ:ț:g' "$FILENAME"
		sed -i 's:º:ș:g' "$FILENAME"
		sed -i 's:ª:Ș:g' "$FILENAME"
		sed -i 's:Þ:Ț:g' "$FILENAME"
		mv $ORIGINAL $ORIGINAL".bak"
	fi

I need to run this script as:

./path/to/convert.sh /path/to/subtitle.srt

The script checks the encoding and replace some characters.

 

Thank you for your help.

Link to comment
Share on other sites

Hi, there's currently no setting for this. I suppose if you have a way of monitoring for new files you could run it on that type of event.

Link to comment
Share on other sites

I can use inotifywait, but I was thinking if the bash script can be called from emby server.

Edited by cr@sh
Link to comment
Share on other sites

This is my solution for file conversion to UTF-8 and accented character replacement in subtitle files.
I run my ubuntu 16.04 server under user: "emby".
Replace "emby" with your username where you see it.

First install inotify-tools.

sudo apt-get install inotify-tools

Then we create subtitle.sh script in /home/emby

nano /home/emby/subtitle.sh

and paste inside subtitle.sh the following code

#!/bin/bash
ISO=iso-8859-1
UTF=utf-8
ICONV="iconv -f $ISO -t $UTF"
movies="/home/emby/movies"
series="/home/emby/series"
inotifywait -r -m $movies $series -e create -e moved_to |
	while read path action file; do
		if [[ "$file" == *.srt ]] && [[ ! `file "$path$file" | grep -i iso-8859` == "" ]]; then
			filename="${file/.rum/}"
			filename="${filename/.srt/}.romanian.srt"
			$ICONV < "$path$file" > "$path$filename"
			sed -i 's:þ:ț:g' "$path$filename"
			sed -i 's:º:ș:g' "$path$filename"
			sed -i 's:ª:Ș:g' "$path$filename"
			sed -i 's:Þ:Ț:g' "$path$filename"
			mv $path$file $path$file".bak"
		fi
	done

Make subtitle.sh executable

sudo chmod +x /home/emby/subtitle.sh

To autostart the subtitle script use systemd:

cd /etc/systemd/system/
sudo nano subtitle.service

and paste the following code

[Unit]
Description=Subtitle Renamer
After=network.target

[Service]
User=emby
Restart=always
RestartSec=5
Type=simple
ExecStart=/home/emby/subtitle.sh
TimeoutStopSec=20

[Install]
WantedBy=multi-user.target

Make subtitle.service executable and enable it

sudo chmod +x subtitle.service
sudo systemctl enable subtitle.service

Start the service

sudo service subtitle start
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...