Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automate syncing of new incoming srt files #13

Open
huuub opened this issue Apr 23, 2019 · 0 comments
Open

Automate syncing of new incoming srt files #13

huuub opened this issue Apr 23, 2019 · 0 comments

Comments

@huuub
Copy link

huuub commented Apr 23, 2019

I made a little script that I run by systemd and checks every 10 min for new subtitles to sync.

#!/bin/bash -e

indir=$1
handled='/media/data/programs/SyncSubs_processed.txt'
handled_now='/media/data/programs/SyncSubs_processing.txt'

while true; do
	rm "$handled_now" && touch $handled_now
	touch "$handled"

	IFS=$'\n'
	srtfiles=$(find $indir -name '*srt' -mtime -3 -printf '%T@|%p\n' 2>/dev/null) || true
	for srt in $srtfiles; do
		IFS='|'
		set $srt
		epochfile=$1
		srtfile=$2
		sf_dir=$(dirname "$srtfile")
		sf_bn=$(basename "$srtfile")
		if grep -q "$srt" "$handled" ||  grep -q "$srt" "$handled_now"; then
			true
	        	echo "Already handled : $srt"
	        else
			## we handle only files older then 10minutes. So all other subs can be downloaded for the video
			curr_epoch=$(date +%s)
			if [ $(($curr_epoch - ${epochfile%%\.*})) -gt 200 ]; then
				## echo "Start handling : $sf_bn"
				movie=$(echo "$sf_bn" | perl -pe 's/(\...?.)?\.srt$//g')
				moviefile=$(find "$sf_dir" -size +300M -name "${movie}.*")
				find "$sf_dir" -name "${movie}*.srt" -printf "%T@|%p\n" >> $handled_now
				/home/jeroen/.local/bin/subsync $moviefile || true
				find "$sf_dir" -name "${movie}*.srt" -printf "%T@|%p\n" >> $handled
				## echo "end handling $movie"
			else
				echo "Not old enough : $sf_bn"
			fi
		fi
	done
rm $handled_now || true
sleep 600
done

cat /etc/systemd/system/SyncSubs.service
[Unit]
Description=Huubs Subtitle Sync Service

[Service]
User=jeroen
Group=jeroen
ExecStart=/media/data/programs/fixSubs.sh /media/data/complete

[Install]
WantedBy=multi-user.target

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant