You removed the function at the beginning so it gets to line 34 and exits.
Also looking at the code, if youāre going to run something from ~/Library/LaunchAgents/.plist, it should be run as the user, not root. If you want it to run as root (which it seems like you want this run as), itās better to place it in /Library/LaunchAgents.
And thanks for helping getting this setup properly!
Some more bug corrections in. You were right about running the Launch Agent as user; I had it as root previously, but there was no reason for that, and I forgot to update it.
-Karl
Looks like line 38 has a comment before the comment should be there? Thereās no end quote, but it looks like the comment got placed in the wrong spot to me. I removed the ā# Default=ālocalhost:8089ā. For running script remotely.ā and tried running but still another errorā¦
sed: 1: "/DEST_DIR*/c\DEST_DIR=" ...": extra characters after \ at the end of c command
So I added a line to just move the prefs file:
mv channels-transcoder.prefs "${prefsdir}/prefs"
Then changed the sed lines to inline:
sed -i ".bak" "s,DEST_DIR=\"/mnt/network/Plex\",DEST_DIR=\"${destination}\"," "${prefsdir}/prefs" sed -i ".bak" "s,HOST=\"\",HOST=\"${host_name}\"," "${prefsdir}/prefs"
From there I ran it and that whole section finally worked, so now I had ~/Library/Application Support/channels-transcoder with a correct prefs fileā¦
Then it jumped down and moved channels-transcoder.sh to /usr/local/bin
And then it just failed:
./install.sh: line 101: syntax error: unexpected end of file
So I read farther and noticed there was no ;; in the ā*)ā caseā¦ But I still canāt get it to work, so somethingās wrong in the: āif [ ! -f ā${prefsdir}/transcode.dbā ] ; thenā section but I canāt see itā¦
Found itā¦ missing a āfiā!
But now more errors:
Please wait for the database to be initiated and backlog to be transcoded... Working directory: /tmp/.PQyjviI0 Channels DVR API Interface Found Cannot write to /Users/timstephens24/Library/Application Support/channels-transcoder/transcode.db, using /Users/timstephens24/channels-transcoder/transcode.db instead /usr/local/bin/channels-transcoder.sh: line 219: /Users/timstephens24/channels-transcoder/transcode.db: No such file or directory Transcode database initialised at /Users/timstephens24/channels-transcoder/transcode.db Cannot write to /Users/timstephens24/channels-transcoder/transcode.db. I give up! Installing automation script... If prompted, please enter your password now... /Users/timstephens24/Library/LaunchAgents/com.getchannels.channels-transcoder.plist: service already loaded Launch Agent installed Installation files removed Done.
Okay, back home now, so I can pay this some more attention. It might take me a while, but I intend to test it more thoroughly before the next update of the install script.
The error here:
Cannot write to /Users/timstephens24/Library/Application Support/channels-transcoder/transcode.db, using /Users/timstephens24/channels-transcoder/transcode.db instead
suggests that the permissions on transcode.db are wrong. Please check that and run:
sudo chown timstephens24 "/Users/timstephens24/Library/Application Support/channels-transcoder/transcode.db"
if they are.
If all else fails, then the main things are to get the main script to /usr/local/bin, the prefs file (just called prefs) into that directory above, and the LaunchAgent installed, before running it. Use the following (only for a Mac), making sure to use your preferred editor on line 6 to set DEST_DIR in the prefs file, and change the number of days backlog on line 8 to whatever you want:
wget https://github.com/karllmitchell/Channels-DVR-to-Plex/archive/master.zip
unzip master.zip
cd Channels-DVR-to-Plex-master
sudo cp channels-transcoder.sh /usr/local/bin/
mkdir -p "~/Library/Application Support/channels-transcoder/"
nedit channels-transcode.prefs #Use whichever editor to point DEST_DIR
mv channels-transcode.prefs "~/Library/Application Support/channels-transcoder/prefs"
/usr/local/bin/channels-transcoder.sh DAYS=0. # Set to whatever you prefer
cp com.getchannels.channels-transcoder.plist "~/Library/LaunchAgents/"
launchctl load "~/Library/LaunchAgents/com.getchannels.channels-transcoder.plist"
That should install everything you need.
I have uploaded an almost completely new installation script, as well as some minor corrections to the README file and main script. This has been tested on both a Mac and an ARM64 Ubuntu Linux system, but not a wide range of circumstances, so please test. It should be more reliable than the previous script.
New installation command is:
curl https://raw.githubusercontent.com/karllmitchell/Channels-DVR-to-Plex/master/install.sh > install.sh && bash install.sh
If you are running GNU parallel and only have the relevant code installed on your remote system(s), then please run:
curl https://raw.githubusercontent.com/karllmitchell/Channels-DVR-to-Plex/master/install.sh > install.sh && bash install.sh force
Everything can now work in user space, although by default if you have sudo access it will install the main script in /usr/local/bin.
Thanks,
-Karl
Hi there.
Iāve tried several times to install with the curl string you provided on my Mac mini running 10.11.4 and have run into errors about prerequisites. Iāve checked using āwhichā and jq, ffmpeg, curl, and realpath are all on my system. Below is the line I copy/pasted into the term window with error message.
$ curl https://raw.githubusercontent.com/karllmitchell/Channels-DVR-to-Plex/master/install.sh > install.sh && bash install.sh
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 7153 100 7153 0 0 10722 0 --:--:-- --:--:-- --:--:-- 10724
If you're running this script on a machine other than the one running Channels DVR, you should specify the host here.
Enter the hostname and port number (leave blank for default "localhost:8089"), followed by [ENTER]:
Checking for critical pre-requisite programs:
jq curl ffmpeg realpath
Optional packages include:
AtomicParsley >= 0.9.6 and parallel >= 20161222
If they do not exist on your system, please use whichever package manager
works for your system to install them
On Ubuntu/Debian Linux:
sudo apt-get install jq curl HandBrakeCLI ffmpeg realpath
On Mac, use homebrew, macports or fink similarly.
Some pre-requisites not installed.
Please try again or use "bash install.sh force" then edit your prefs file manually
I get a little further when using the āforceā flag, but run into an error on line 124.
Installing automation script...
install.sh: line 124: /log: Permission denied
Any advice or pointers would be greatly appreciated.
-Andrew
@karlmitchell You might be interested in http://www.shellcheck.net
Personally I always write my shell scripts with āset -eā
@tmm1 I use shellcheck often. Itās a great resource.
@amann180 Sorry about that. I added some corrections for Linux installations a while back, think I got them working, but perhaps broke something for the Mac. Iāll try to fix it again, but in the meantime there are only three files you really need to set up, and itās easy enough to do manually from the terminal, so try running the following, making sure to pause at and read the comments I inserted.
ā
wget https://github.com/karllmitchell/Channels-DVR-to-Plex/archive/master.zip
unzip master.zip
cd Channels-DVR-to-Plex-master/
mkdir ~/.channels-transcoder
cp channels-transcoder.prefs "${HOME}/.channels-transcoder/prefs"
sudo cp channels-transcoder.sh /usr/local/bin # Enter your password here
cp com.getchannels.channels-transcoder.plist "${HOME}/Library/LaunchAgents/"
At this stage you could double-check that ~/.channels-transcoder/prefs looks okay to you. The first line, DEST_DIR, is the critical one. This should be where you want your Plex recordings to go. You will need to point Plex at the subfolders āTV Showsā and āMoviesā afterwards. Other than that, mostly it will operate fine with default settings, but there might be things you want to tweak, and familiarizing yourself with the options does no harm.
Once youāve done that, the next command both tests that channels-transcoder.sh is working for you, and initiates the database. If you would like to transcode some past shows, I recommend changing DAYS to be a bigger number that encompasses the time range of shows you wish to transcode, e.g. DAYS=7 will transcode the last weekās recordings for you. The subsequent command initializes nightly transcoding.
channels-transcoder.sh DAYS=0
launchctl load "${HOME}/Library/LaunchAgents/com.getchannels.channels-transcoder.plist
ā
And thatās it. You should be done!
-Karl
I should add that I just re-ran the script on a Mac (current version of the OS) and had no issues. Very strange.
From the error, it looks like itās trying to write to /log when it should be writing to ~/Library/Application\ Support/channels-transcoder/log. If you could check whether ~/Library/Application\ Support/channels-transcoder was created for you and whether you can write to it (cd ~/Library/Application\ Support/channels-transcoder; touch test), that might help me diagnose what is going wrong. Alternative, for some reason ${prefsdir} wasnāt set correctly by the script, but I canāt see why.
I did update the script a little, as per my subsequent post.
Updates:
HandBrakeCLI dependency removed in favor of ffmpeg.
ffmpeg version installed by channels-dvr can be used instead of installing a separate one.
All transcoding is now handled via ffmpeg
Installation script updated to improve Mac install and correct some bugs
- āset -eā added
- realpath replacement bash alias now installed in ~/.profile if binary not available.
- script requirements updated to reflect changes to HandBrakeCLI and ffmpeg requirements
If channels-transcoder is already working for you, there is no need to upgrade. It shouldnāt break your system if you do, though.
I moved the files into place manually, however when running āchannels-transcoder.shā it now complains that it canāt find the db and canāt write to any of the locations. Iāve chowned the ~/Library/Application Support/channels-transcoder/ and can write to the location. I even ran chmod 777 just to make sure it could be written to.
$ channels-transcoder.sh DAYS=0
Working directory: /tmp/transcode.BtmS8v16
Channels DVR API Interface Found
Cannot write to /Users/amannone/Library/Application Support/channels-transcoder/transcode.db, using /Users/amannone/.channels-transcoder/transcode.db instead
/usr/local/bin/channels-transcoder.sh: line 205: /Users/amannone/.channels-transcoder/transcode.db: No such file or directory
Transcode database initialized at /Users/amannone/.channels-transcoder/transcode.db
Cannot write to /Users/amannone/.channels-transcoder/transcode.db. I give up!
However, if I do ātouch transcode.dbā in the location, I get the following when running āchannels-transcoder.shā:
$ channels-transcoder.sh DAYS=7
Working directory: /tmp/transcode.AtsnJKX6
Channels DVR API Interface Found
No new shows to transcode
No matter what value I put for Days, it always says āNo new shows to transcodeā.
In Prefs, for the DEST_DIR key, do I need to escape any spaces in the path? For example DEST_DIR="/Users/amannone/My\ Video\ Folder"? or is this fine DEST_DIR="/Users/amannone/My Video Folder"
Okay, something went wrong in your initial install, but it can all be fixed. Please simply delete ~/.channels-transcoder, e.g.
rm -rf ~/.channels-transcoder
Basically, if that folder still exists it will stop looking for the one under Application Support, and at some point it probably populated your transcode.db with all past episodes by running DAYS=0. The transcode.db is simply a list of recording numbers that have previously been transcoded, and that by default it ignores for future transcoding unless you override this behavior. To reset and repopulate your transcode.db, after deleting the .channels-transcoder directory, run e.g.:
channels-transcoder.sh DAYS=7 CLEAR_DB=1
No escape characters should be used in the prefs file, as long as you put them in quotes. If you do not include quotes, youāll need them.
Iām afraid Iām still having issues.
I ran ārm -rf ~/.channels-transcoderā as requested (even tho I didnāt see that folder in my user directory using ls -a). I also removed ā~/Library/Application Support/channels-transcoderā and the channels-transcoder.sh from /usr/local/bin/
I recreated ~/Library/Application Support/channels-transcoder and copied a new prefs and log file there, put a fresh copy of channels-transcoder.sh in /usr/local/bin.
Running channels-transcoder.sh DAYS=7 CLEAR_DB=1, I get that āCannot write to /Users/amannone/Library/Application Support/channels-transcoder/transcode.db,ā etc. error. It seems the script dosenāt like it if a transcode.db file is not in that folder. In each time Iāve gone through the installation Iāve had to create a transcode.db file using touch.
With the transcode.db in place, I get this:
$ channels-transcoder.sh DAYS=7 CLEAR_DB=1
Working directory: /tmp/transcode.WjnDSekZ
Channels DVR API Interface Found
Transcode database initialised at /Users/amannone/Library/Application Support/channels-transcoder/transcode.db
No new shows to transcode
Iām starting to think thereās a gremlin in my mac!!
That is very strange. It sounds like the script doesnāt have write permissions to ā/Users/amannone/Library/Application Support/transcode.dbā but you do, which shouldnāt happen. Youāre definitely installing this all as user? The only time you should use āsudoā is for moving the main script to /usr/local/bin/channels-transcoder.sh.
Iāve tried duplicating everything you describe, and it works fine for me, so Iām a little lost.
Could you run the following little diagnostic and report back on any output?
mkdir -p ~/Library/Application\ Support/channels-transcoder/test
touch ~/Library/Application\ Support/channels-transcoder/ test.db
ls -l ~/Library/Application\ Support/channels-transcoder/
ls -l ~/Library/Application\ Support/ | grep channels-transcoder
ls -l ~/Library/ | grep Application\ Support
ls -l /usr/local/bin/channels-transcoder.sh
rm -rf ~/Library/Application\ Support/channels-transcoder/test*
Bear in mind that you can also simply generate/edit your own transcode.db file if you like. It is one recording per line, and if you donāt know what show these recordings corresponds to, try changing to the DVR directory (from the Settings page of your Channels DVR web interface) and running this:
for i in ./Logs/comskip/* ; do printf "$(echo $i | rev | cut -d/ -f1 | rev): " ; readlink $i/video.mpg | rev | cut -d/ -f1 | rev; done
If you delete episodes manually, and then run channels-transcoder.sh with a large DAYS= value, and without setting CLEAR_DB=1, it should transcode them. Alternatively, simply run:
echo 0 >> ~/Library/Application\ Support/channels-transcoder/transcode.db
and it will initiate without blocking any episodes from being transcoded.
Thanks,
-Karl
Hi Karl,
Hereās the output of the terminal commands you asked for. I donāt see anything that jumps out at me. Also, yes, I did everything as my user ā no sudo was used.
amannone@mann1mini:~$ mkdir -p ~/Library/Application\ Support/channels- transcoder/test
amannone@mann1mini:~$ touch ~/Library/Application\ Support/channels-transcoder/test.db
amannone@mann1mini:~$ ls -l ~/Library/Application\ Support/channels-transcoder/
total 32
-rw-r--r-- 1 amannone staff 0B May 9 18:55 log
-rw-r--r-- 1 amannone staff 8.1K May 9 19:45 prefs
drwxr-xr-x 2 amannone staff 68B May 10 01:41 test/
-rw-r--r-- 1 amannone staff 0B May 10 01:41 test.db
-rw-r--r-- 1 amannone wheel 105B May 9 22:27 transcode.db
amannone@mann1mini:~$ ls -l ~/Library/Application\ Support/ | grep channels-transcoder
drwxr-xr-x 7 amannone staff 238B May 10 01:41 channels-transcoder/
amannone@mann1mini:~$ ls -l ~/Library/ | grep Application\ Support
drwx------+ 132 amannone staff 4.4K May 9 17:59 Application Support/
amannone@mann1mini:~$ ls -l /usr/local/bin/channels-transcoder.sh
-rwxr-xr-x 1 amannone admin 29K May 9 18:09 /usr/local/bin/channels-transcoder.sh*
amannone@mann1mini:~$ rm -rf ~/Library/Application\ Support/channels-transcoder/test*
Appreciate the assistance!
I have started to use PLEX a lot more now. I have considered moving my Channels DVR Recordings there but I really like the double click to skip āmarkedā commercials. I understand you can just have the commercials removed but I have seen too many times where the marked commercials are not perfect. Is there a way with the PLEX version to have āmarkedā commercials like with Channels DVR / Apple TV play back? If so, might be nice if Channels DVR had a PLEX Option to support it natively.
Also, I use WatchAid as a Universal Watch List for Hulu, CBS, HBO, Showtime and many more and they are soon to add PLEX for those with TV Shows. So, this might be a good option.
@d21mike: Commercial boundaries are marked as Chapters by default using my scripts. On the web version of the client, you can go forward and back by using squade brackets: [ and ]. On the Apple TVās Plex, you can downswipe on the Siri Remote and see these chapter markings, but unfortunately this is not as easy as just pressing a button to skip to the next chapter, and I tend to not use this interface as a result. The precise implementation of chapter change by client is out of my hands.