Python script to be notified of channel lineup changes

Please try the suggestion from @bnhf first. :slightly_smiling_face:

If you still have the same problem after that, I will want to get more details from you as I wrote in my previous message.

I did have the second dvr defined, but now I've commented that out. I pulled the latest olivetin.

      #- CHANNELS_DVR_ALTERNATES=${CHANNELS_DVR2_HOST}:${CHANNELS_DVR2_PORT} # Space separated list of alternate Channels DVR servers to choose from in the form hostname:port or ip:port.

I'm still getting the "IndexError: list index out of range" message when I start the script.

This error is generated by my script.

Please provide the settings used in all your sources and I will take a look.

@cyoungers In addition to providing the sources settings requested above, there's a line in stderr that starts with "nohup" that runs off the page. If you could post that full line (with needed redactions) as text, that might be helpful as that's the line that calls the @mjitkop python script.

My env variables:

TAG=latest
DOMAIN=tail6d9e.ts.net
HOST_PORT=1337
CHANNELS_DVR_HOST=192.168.0.11
CHANNELS_DVR_PORT=8089
CHANNELS_DVR2_HOST=
CHANNELS_DVR2_PORT=
CHANNELS_CLIENTS=apple-tv
ALERT_SMTP_SERVER=smtp.gmail.com:587
[email protected]
ALERT_EMAIL_PASS={redacted}

ALERT_EMAIL_TO={redacted}@gmail.com
UPDATE_YAMLS=true
UPDATE_SCRIPTS=true
TZ=US/Pacific
HOST_DIR=/volume1/data
DVR_SHARE=/volume1/ChannelsDVR
LOGS_SHARE=/var/packages/ChannelsDVR/target/channels-dvr
HOST_SFS_PORT=8080
FOLDER=/web
PORTAINER_TOKEN={redacted}
PORTAINER_HOST=cjynas

Standard Error:

+ dvr=192.168.0.11:8089
++ echo 192.168.0.11:8089
++ awk -F: '{print $1}'
+ channelsHost=192.168.0.11
++ echo 192.168.0.11:8089
++ awk -F: '{print $2}'
+ channelsPort=8089
+ foregroundScript=channels_dvr_monitor_channels
++ ps -ef
++ grep '[p]ython3 .* -i 192.168.0.11 -p 8089'
++ awk '{print $2}'
+ runningScriptPID=
+ greenIcon='"icons/channels.png"'
+ purpleIcon='"https://community-assets.getchannels.com/original/2X/5/55232547f7e8f243069080b6aec0c71872f0f537.png"'
+ logFile=/config/192.168.0.11-8089_channels_dvr_monitor_channels_latest.log
+ [[ -f /config/192.168.0.11-8089_channels_dvr_monitor_channels_latest.log ]]
+ configFile=/config/config.yaml
+ cp /config/config.yaml /tmp
+ configTemp=/tmp/config.yaml
+ trap finish EXIT
+ frequency=30
+ [[ 30 == \0 ]]
+ [[ 30 != \0 ]]
+ sed -i '/#channels_dvr_monitor_channels frequency default/s/default: .* #/default: 30 #/' /tmp/config.yaml
+ email={redacted}@gmail.com
+ [[ {redacted}@gmail.com != \n\o\n\e ]]
+ optionalArguments='-e {redacted}@gmail.com'
+ sed -i '/#channels_dvr_monitor_channels email default/s/default: .* #/default: {redacted}@gmail.com #/' /tmp/config.yaml
+ password={redacted_password}
+ [[ {redacted_password} != \n\o\n\e ]]
+ optionalArguments='-e {redacted}@gmail.com -P {redacted_password}'
+ [email protected]
+ [[ [email protected] != \n\o\n\e ]]
+ optionalArguments='-e {redacted}@gmail.com -P {redacted_password} -r [email protected]'
+ sed -i '/#channels_dvr_monitor_channels recipient default/s/default: .* #/default: [email protected] #/' /tmp/config.yaml
+ text=none
+ [[ none != \n\o\n\e ]]
+ main
+ cd /config
+ scriptRun
++ ps -ef
++ grep '[p]ython3 .* -i 192.168.0.11 -p 8089'
++ awk '{print $2}'
+ runningScriptPID=
+ [[ -n '' ]]ralizedlxafqknqd
+ runningScriptPID=623
+ echo 'channels_dvr_monitor_channels.sh 192.168.0.11:8089 30 {redacted}@gmail.com {redacted_password} [email protected] none'
+ nohup python3 -u /config/channels_dvr_monitor_channels.py -i 192.168.0.11 -p 8089 -f 30 -e {redacted}@gmail.com -P {redacted_password} -r [email protected]
+ grep -q '(.*) #channels_dvr_monitor_channels' /tmp/config.yaml
+ [[ 1 == \1 ]]
++ date +%d%b%y_%H:%M
+ sed -i '/#channels_dvr_monitor_channels title/s/#/(09May24_14:19) #/' /tmp/config.yaml
+ sed -i '/#channels_dvr_monitor_channels icon/s|img src = .* width|img src = "icons/channels.png" width|' /tmp/config.yaml
+ sleep 2
+ cat /config/192.168.0.11-8089_channels_dvr_monitor_channels_latest.log
+ runningScripts
+ servers=($CHANNELS_DVR $CHANNELS_DVR_ALTERNATES)
+ for server in "${servers[@]}"
++ echo 192.168.0.11:8089
++ awk -F: '{print $1}'
+ serverHost=192.168.0.11
++ echo 192.168.0.11:8089
++ awk -F: '{print $2}'
+ serverPort=8089
++ ps -ef
++ grep '[p]ython3 .* -i 192.168.0.11 -p 8089'
++ awk '{print $2}'
+ activeProcess=
+ [[ -n '' ]]
+ finish
+ cp /tmp/config.yaml /config

@mjitkop I don't see any issues on the OliveTin side, so as you suggested, the answer will likely be found in the source data.

I will take a look later when I'm back home.
I will check my code to figure out in what situation this error is generated. That will give me an idea what to suggest to @cyoungers.

@cyoungers it seems that one of your sources is lacking some information that my script is looking for. I'm not sure exactly what it is as it could be one of several things.

In a browser, on the same machine where OliveTin is running, please go to this URL:
192.168.0.11:8089/devices

You should see a lot of text with information about all your sources and channels.

Once this page is fully loaded, please copy the whole content and paste it into a text file.
Then please send it to me at [email protected]

It will be easier for me to troubleshoot this.

Thank you for providing the data, @cyoungers.

After reviewing your data, I immediately identified the issue: your source "EPLUS" has zero channels.
My script did not account for this scenario.

Sorry you ran into this issue and thank you for reporting this.

Thanks to you, this will be fixed in the next version of my script that I'm planning on releasing later today.

Cool. My EPLUS container stopped working awhile ago and I never got around to fixing it. Glad it uncovered this edge case I guess.

1 Like

I have made changes to the script and I am in the testing phase now.

If everything goes well, I will release a new version tomorrow.


Update 5/11:

Test failed. I broke something in the code. 🫤

Today is a busy day and I probably won't be able to look at it until late evening, if at all.
Maybe tomorrow morning.

Version 3.2.0:

[IMPROVED] Ignore sources that have the "Lineup" field empty

[FIXED] Crash when a new source with zero channels is detected

[NEW] Detect, report, and back up removed sources (in "Deleted_Sources" subdirectory)


@bnhf please integrate in OliveTin at your convenience. :slight_smile:

@chDVRuser sorry for the delay, this is a release that is long overdue with your requested change. :wink:

@cyoungers it should work for you now :crossed_fingers:

1 Like

Thanks! Works great.

2 Likes

Version 3.3.0

[FIXED] Two or more sources each using the same HDHomeRun device model were combined into one source.

Note: sources that use a HDHomeRun device will be reported as new sources the first time this version of the script is run. The names of their channel lineup log files will contain the device IDs to differentiate them in case they use the same HDHomeRun device model.

I really like this idea, so I'm just trying this out in command line on a Windows 11 machine. I'm trying to monitor on a different PC than the one where Channels server is located and I get the error message below.

C:> python channels_dvr_monitor_channels.py -f 15 -i 192.168.88.240
Traceback (most recent call last):
File "C:\channels_dvr_monitor_channels.py", line 62, in
import argparse, glob, os, requests, smtplib, sys, time
ModuleNotFoundError: No module named 'requests'

1 Like

The "ModuleNotFoundError: No module named 'requests'" occurs when you forget to install the requests module before importing it or if you install it in an incorrect environment. To resolve this error, follow these steps:

  1. Install the requests module:

    • Open your terminal or command prompt.
    • Navigate to your project's root directory.
    • Run the following command to install the requests module:
      pip install requests
      
      If you're using Python 3, use:
      pip3 install requests
      
  2. Check your Python installation:

    • Make sure you have Python and pip installed.
    • If pip is not in your path, you can use:
      python -m pip install requests
      
      For Python 3:
      python3 -m pip install requests
      
  3. Alternative methods:

    • On Linux, you can use your system's package manager:
      • CentOS: sudo yum install python-requests
      • Debian/Ubuntu (Python 2): sudo apt-get install python-requests
      • Debian/Ubuntu (Python 3): sudo apt-get install python3-requests
    • On Windows, use:
      pip install requests
      
      Or if pip is not in your path:
      python -m pip install requests
      

Remember to install the requests module in the correct environment, and you should be good to go! :rocket:¹²³⁴⁵

Source: Conversation with Copilot, 5/31/2024
(1) python - ImportError: No module named requests - Stack Overflow. python - ImportError: No module named requests - Stack Overflow.
(2) ModuleNotFoundError: No module named 'requests' in Python. ModuleNotFoundError: No module named 'requests' in Python | bobbyhadz.
(3) Solved: ModuleNotFoundError: No module named 'requests' in Python 3. Solved: ModuleNotFoundError: No module named 'requests' in Python 3 | CyberITHub.
(4) ModuleNotFoundError: no module named 'requests' [Solved in Python Django]. ModuleNotFoundError: no module named 'requests' [Solved in Python Django].
(5) python - ModuleNotFoundError: No module named 'requests' - Stack Overflow. python - ModuleNotFoundError: No module named 'requests' - Stack Overflow.
(6) undefined. PyPI · The Python Package Index.
(7) undefined. requests · PyPI.

Thank you for the quick response! Installed the module; all is running now and the number of channels in the log for each source I have is the same as what is listed in Channels settings. Thank you again.

2 Likes

@daldana7296 are you using the latest version of the script, version 3.3.0?

Yes. It just did it's first update and logged correctly.

1 Like

Perfect. Thank you for confirming. :slightly_smiling_face: