Shell script to join & convert video files

Hi there,
Sorry my first post is a cry for help rather than a helpful tip, I started using Hazel only a few days ago and I'm not quite there yet! However, my question could interest people in a quest of tweaking further their video files management.
Basically I'm trying to do 2 things:
[list=]
[*]join movie files that are split in xxx-cd[digit].extension - for avi & mkv files (99% of my video files)
[*]convert movies currently in 2 files (1 for the video + 1 for the subtitles) into just 1 mkv file - for srt & sub files
[/list]
Being 1) not knowledgeable when it comes to programming 2) but still geek enough to spend quite a few hours on google to search for a solution, I stumbled upon a lot of tutorials about sorting TV shows folders and files. At first, I thought I could adapt the one from http://www.mactalk.com.au/content/organising-media-hazel-pt-2-986/ to solve problem 1 (joining files).
Here is what I started with...

Until I realised AJoiner coulnd't be controlled through applescript because it doesn't have an applescript dictionary. So I was just opening it up but still have to do the rest manually. Half-baked.
For problem 2 (merging video+subtitles into one mkv file), I did discover a way to convert sub to srt (http://www.robelix.com/sub2srt/) and then use mkvmerge with the srts.
Fortunately I found a similar question from a Linux user looking to batch clean his video storage folder with shell scripts: https://www.linuxquestions.org/questions/programming-9/making-a-batch-shell-script-to-convert-merge-and-append-join-movies-to-mkv-773699/
I have been trying to adapt his bits of code to a Hazel routine but either the 2 files I'm trying to join as a test vanish (deleted) without being joined or I get a shell script error. I have never used shell script before and I can't seem to find my way around it, although I can see that those bits of code (hereafter) are the way to go.
To join video files:
To merge video & subtitle files:
So if anyone could point me in the right direction or is willing to help out with those code snippets, I'd be very grateful
Thanks
Sorry my first post is a cry for help rather than a helpful tip, I started using Hazel only a few days ago and I'm not quite there yet! However, my question could interest people in a quest of tweaking further their video files management.
Basically I'm trying to do 2 things:
[list=]
[*]join movie files that are split in xxx-cd[digit].extension - for avi & mkv files (99% of my video files)
[*]convert movies currently in 2 files (1 for the video + 1 for the subtitles) into just 1 mkv file - for srt & sub files
[/list]
Being 1) not knowledgeable when it comes to programming 2) but still geek enough to spend quite a few hours on google to search for a solution, I stumbled upon a lot of tutorials about sorting TV shows folders and files. At first, I thought I could adapt the one from http://www.mactalk.com.au/content/organising-media-hazel-pt-2-986/ to solve problem 1 (joining files).
Here is what I started with...

Until I realised AJoiner coulnd't be controlled through applescript because it doesn't have an applescript dictionary. So I was just opening it up but still have to do the rest manually. Half-baked.
For problem 2 (merging video+subtitles into one mkv file), I did discover a way to convert sub to srt (http://www.robelix.com/sub2srt/) and then use mkvmerge with the srts.
Fortunately I found a similar question from a Linux user looking to batch clean his video storage folder with shell scripts: https://www.linuxquestions.org/questions/programming-9/making-a-batch-shell-script-to-convert-merge-and-append-join-movies-to-mkv-773699/
I have been trying to adapt his bits of code to a Hazel routine but either the 2 files I'm trying to join as a test vanish (deleted) without being joined or I get a shell script error. I have never used shell script before and I can't seem to find my way around it, although I can see that those bits of code (hereafter) are the way to go.
To join video files:
- Code: Select all
#!/bin/bash
for FIRST in ./*.cd1.mkv ; do
NAME=$(basename "$FIRST" .cd1.mkv)
REST=("./$NAME".cd[^1].mkv)
mkvmerge -o "$NAME.mkv" "$FIRST" "${REST[@]/#/+}"
rm "$FIRST"
rm "${REST[@]/#}"
done
To merge video & subtitle files:
- Code: Select all
#!/bin/bash
AVI_DIR="avi"
SRT_DIR="srt"
MKV_DIR="mkv"
for AVI in "$AVI_DIR"/*.avi ; do
NAME=$(basename "$AVI" .avi)
if [[ -r "$SRT_DIR/$NAME.srt" ]] ; then
echo "Subbing $NAME (SRT)"
mkvmerge -o "$MKV_DIR/$NAME.mkv" "$AVI" "$SRT_DIR/$NAME.srt"
rm "$AVI"
rm "$SRT_DIR/$NAME.srt"
else
echo "No subtitles found for $NAME"
fi
done
So if anyone could point me in the right direction or is willing to help out with those code snippets, I'd be very grateful

Thanks
