Python script to be notified of channel lineup changes

Just pushed version 2.2.0 to GitHub after quietly pushing version 2.1.0:

  • 2.1.0 :
    [CHANGED] Show lineup changes in order of channel numbers.
    [CHANGED] Show channel changes in order of channel names.

  • 2.2.0 :
    [IMPROVED] Added "Channels DVR lineup changes:" as first line in SMS message
    [NEW] Show duplicated channels in each modified source

1 Like

@mjitkop I'm planning to update OliveTin-for-Channels soon, which will include the latest version of this fabulous script! :slight_smile:

I was able to plug it in to my existing framework without issue so far, but I do have a question. On initial run, I received this output to the OliveTin log, along with a matching e-mail. However, I have not been able to locate the referenced files:

Using Channels DVR server at: http://media-server6:8089.
Checking for channel lineup changes every 30 minutes.

An email will be sent to [email protected] when changes are detected.

Last check    : 2024-02-05 16:27:22
Server version: 2024.01.08.1431

Channels DVR version: 2024.01.08.1431

New source with 160 channels: DIRECTV
See file DIRECTV.txt for the full lineup.

New source with 96 channels: CDVR - Minneapolis
See file CDVR - Minneapolis.txt for the full lineup.

New source with 20 channels: Fire TV - DTV
See file Fire TV - DTV.txt for the full lineup.

New source with 31 channels: Fire TV - Live TV
See file Fire TV - Live TV.txt for the full lineup.

New source with 370 channels: Pluto TV
See file Pluto TV.txt for the full lineup.

New source with 329 channels: Samsung TV Plus
See file Samsung TV Plus.txt for the full lineup.

New source with 44 channels: FrndlyTV
See file FrndlyTV.txt for the full lineup.

New source with 5 channels: FrndlyTV-noEPG
See file FrndlyTV-noEPG.txt for the full lineup.

New source with 31 channels: Stirr
See file Stirr.txt for the full lineup.

New source with 2 channels: Chrome Capture
See file Chrome Capture.txt for the full lineup.

New source with 7 channels: Virtual Channels
See file Virtual Channels.txt for the full lineup.

New source with 1 channels: VLC-Bridge - PBS
See file VLC-Bridge - PBS.txt for the full lineup.

Sending email to [email protected]...
Background Channel Lineup Change Notifications process running for media-server6:8089

Are those files only generated if the -l option is used? And, if -l is used, is there still output to the console?

1 Like

Glad that you will be updating with my latest script. :slightly_smiling_face:

No. They are always created. They are necessary since they are used as references.

They are (should be!) located in the same directory from where the script is called.

This is a good point, though. I realize now that I should display the full paths.

Watch for another version coming soon. :wink:

Yes.

Actually, the text that you pasted is what is shown on the console.
Well, for me, the text is shown in the terminal window when I run it on my Windows PC.

I must admit that I still have not installed OliveTin.
Sorry. :blush:
I went as far as installing Portainer but this is all new to me. Now I need to figure out how to use the docker compose files.
I have some work to do to educate myself. :grimacing:

That would work, however doing a "find" just now, they are located in "~", which in the case of a container running as root, is /root. It would be much better if they could be placed in ".", as that would place them in the directory that is mapped to the host.

One twist though, I've set this up to support multiple DVRs, just in case someone has different lineups in each. So, ideally if you could support a sub-directory flag, that would fit with my current structure (i.e. ./subdirectory). If not, I'd imagine I can figure something out.

I'd be happy to walk you through the process, either in a thread here that others might benefit from, or we could do it over on Discord -- for best speed of the back-and-forth.

That shouldn't be too hard. :slightly_smiling_face:

Not sure what you mean by "flag".

If I understand correctly, will it work if I save the files in ./ip_port?
Example: ./192_168_18_120_8089

Or what names should the sub-directories have?

I might take your offer but first let me see what I can do with all the information that you posted in the thread.
You put a lot of work into it so it's only fair that I put a minimum effort into it.
Other people have been able to do it so I should be able to. I just need to have a clear head and focus on the task. :wink:

Actually, there's no need to pass a new argument given you already have the values of -i and -p to work with. If you write the data files to host-port_data, that would fit perfectly with the scheme I'm already using. So examples would be ./192.168.18.120-8089_data or ./media-server6-8089_data -- how's that work for you?

1 Like

Sure, no problem.

I just need to make sure I capture the current directory.
I do my development on Windows but it should work the same with '.' hopefully.

I will let you know when I have something you can try. :slightly_smiling_face:

@bnhf I've started to make the code changes. I should be done before the weekend.

Here it is, @bnhf, the new and improved version 3.0.0:

[IMPROVED] Save reference files and the log file into a subdirectory that is named using the IP address and the port number of the server (better support for multiple servers)

[IMPROVED] When displaying duplicated channels, show the channel numbers without square brackets and without quotes (just the numbers)

[IMPROVED] Some cosmetic changes to increase readability in the detailed message

[NEW] Added the server URL as the first line of the detailed message (useful information when monitoring multiple servers)

[NEW] Added the source URL (used in the source settings) below the source name in the detailed message

[NEW] Added the starting channel number of the modified source when displaying the "Lineup changes" header

[NEW] Added the DVR URL on the second line of the SMS message (useful information when monitoring multiple servers)

I hope I got the directory structure right now so that it works in OliveTin. :crossed_fingers:
If not, there is something else I can try.

Thanks! I should be able to test this tomorrow, and if all seems good, I'll push an update to OliveTin.

2 Likes

Looks promising, but I did need to make one change to the code (and related comment) at lines 331 and 335:

def create_data_subdirectory(ip_address, port_number):
    '''
    Create a directory with the path as:
    current directory + "_<ip_address>-<port_number>_data" at the end
    '''
    global Data_Subdirectory_Path

    end_of_path = f'{ip_address}-{port_number}_data'
    data_subdirectory_path = os.path.join(os.getcwd(), end_of_path)

    if not os.path.exists(data_subdirectory_path):
        os.mkdir(data_subdirectory_path)
        
    Data_Subdirectory_Path = data_subdirectory_path

"_" changed to "-" between {ip_address} and {port_number}

On first run the data files ended up under /root again, but this time I cleverly :slight_smile: changed the directory to /config before running the script. Don't know why I didn't think of that before. It's good to have the data files in a subdirectory though.

1 Like

Thanks for the feedback and the code change. I'll make the correction. :slightly_smiling_face:

I'm curious: when you refer to "./” in OliveTin, what is the actual full path for this current directory?

/config is the usual working directory for most scripts, as that's the one that's bound to the host. All the scripts are there, as well as logs and other data-files -- some of which are in sub-directories.

I'm not landing in that directory on container start though, and I use the full path for many/most things, since a container has a completely predictable file system. It'd probably make sense to just change to /config at container start, as opposed to doing it as needed for a given script.

1 Like

OK so you don't think I need to make any more changes in my script with regard to the directory names?
I think this is what I'm understanding but please confirm. :slightly_smiling_face:

Yes -- all good! Just the "-" change referenced above.

New OliveTin-for-Channels pushed incorporating the latest 3.x version of this excellent script:

1 Like

Thanks much for the new improved script!
Especially the persistent reference files that keep track of channels between runs/restarts.

Have a question regarding this

I don't see the duplicate channels called out, for instance in my Pluto source. Are they supposed to appear? I'm not doing text/email notifications as that's overkill for me. Just looking in the log file.

Using Channels DVR server at: http://192.168.1.4:8489.
Checking for channel lineup changes every 720 minutes.

Visual monitoring only, no email or text will be sent.

Last check    : 2024-02-10 11:10:58
Server version: 2024.02.10.0353

Channels DVR server URL: http://192.168.1.4:8489
Channels DVR version: 2024.02.10.0353

New source with 391 channels: "Pluto"
See file /config/192.168.1.4-8489_data/Pluto.txt for the full lineup.

New source with 523 channels: "HDHomeRun PRIME"
See file /config/192.168.1.4-8489_data/HDHomeRun_PRIME.txt for the full lineup.

Next check: 2024-02-10 23:10:58

Here's what I'm seeing in media-server6-8089_channels_dvr_monitor_channels_latest.log:

Using Channels DVR server at: http://media-server6:8089.
Checking for channel lineup changes every 30 minutes.

An email will be sent to [email protected] when changes are detected.

Last check    : 2024-02-10 09:44:55
Server version: 2024.02.08.0626

Channels DVR server URL: http://media-server6:8089
Channels DVR version: 2024.02.08.0626

--------------------------

Pluto TV: 390 channels (-1)
(http://htpc6:8183/playlist.m3u)

<--- Lineup changes (starting at 0) --->
! 2480 : NFL Channel (was Hot Bench)
- 2800 : NFL Channel

<--- Channel changes --->
- Hot Bench (2480)

<--- Duplicated channels --->
AspireTV Life: 262, 3220
BET Her: 2050, 258
BET Pluto TV: 2040, 256
Black Cinema: 130, 250
Black Classics: 254, 530
Black Throwbacks: 252, 320
CBS News Chicago: 2570, 5120
CBS News Colorado: 2540, 5130
CBS News Los Angeles: 2560, 5150
CBS News New York: 2550, 5180
Love & Hip Hop: 1690, 264
Vevo R&B: 266, 4730
XITE Gospel: 268, 4800

Sending email to [email protected]...
Message sent successfully!

Next check: 2024-02-10 10:14:55

Last check    : 2024-02-10 10:14:56
Server version: 2024.02.08.0626
No changes found in any source.
Next check: 2024-02-10 10:44:56

Last check    : 2024-02-10 10:44:56
Server version: 2024.02.08.0626
No changes found in any source.
Next check: 2024-02-10 11:14:56

Last check    : 2024-02-10 11:14:56
Server version: 2024.02.08.0626
No changes found in any source.
Next check: 2024-02-10 11:44:56

Last check    : 2024-02-10 11:44:56
Server version: 2024.02.08.0626
No changes found in any source.
Next check: 2024-02-10 12:14:56

Last check    : 2024-02-10 12:14:56
Server version: 2024.02.08.0626
No changes found in any source.
Next check: 2024-02-10 12:44:56

Last check    : 2024-02-10 12:44:56
Server version: 2024.02.08.0626
No changes found in any source.
Next check: 2024-02-10 13:14:56

Checking every 30 minutes atm for "stress testing". I'm not doing PERSISTENT_LOGS though, so I'm not sure what my first run looked like anymore. @chDVRuser maybe shorten your interval for testing purposes, and see if the next run shows the dups?

Nope. Changed it to a 5 minute interval


Using Channels DVR server at: http://192.168.1.4:8489.
Checking for channel lineup changes every 720 minutes.

Visual monitoring only, no email or text will be sent.

Last check    : 2024-02-10 11:10:58
Server version: 2024.02.10.0353

Channels DVR server URL: http://192.168.1.4:8489
Channels DVR version: 2024.02.10.0353

New source with 391 channels: "Pluto"
See file /config/192.168.1.4-8489_data/Pluto.txt for the full lineup.

New source with 523 channels: "HDHomeRun PRIME"
See file /config/192.168.1.4-8489_data/HDHomeRun_PRIME.txt for the full lineup.

Next check: 2024-02-10 23:10:58


Using Channels DVR server at: http://192.168.1.4:8489.
Checking for channel lineup changes every 5 minutes.

Visual monitoring only, no email or text will be sent.

Last check    : 2024-02-10 12:26:22
Server version: 2024.02.10.0353
No changes found in any source.
Next check: 2024-02-10 12:31:22

Last check    : 2024-02-10 12:31:23
Server version: 2024.02.10.0353
No changes found in any source.
Next check: 2024-02-10 12:36:23

Last check    : 2024-02-10 12:36:23
Server version: 2024.02.10.0353
No changes found in any source.
Next check: 2024-02-10 12:41:23

Last check    : 2024-02-10 12:41:23
Server version: 2024.02.10.0353
No changes found in any source.
Next check: 2024-02-10 12:46:23

Last check    : 2024-02-10 12:46:24
Server version: 2024.02.10.0353
No changes found in any source.
Next check: 2024-02-10 12:51:24

Last check    : 2024-02-10 12:51:24
Server version: 2024.02.10.0353
No changes found in any source.
Next check: 2024-02-10 12:56:24

@chDVRuser in the case where a new source is found, the script doesn't check the lineup itself, it just reports the new source and the number of channels

That's one thing I didn't think of.

Duplicated channels get reported only if a lineup has changed.

I can add it.