Python script: channel list -> CSV file to easily see where channels are available

I wanted to have a clear overview of channel overlaps between the different sources so I wrote a python script that generates a CSV file with the information.
If you open the CSV file with a spreadsheet program, you can format the display nicely and add filters.

For example:

7 channels are available in 4 different sources:

60 channels are available in 3 sources (showing the first 10):

5 Likes

You may want to add some de-dupe if you haven't already (I have not read your code), but channels 6700-6999 are all FTA internet streams added with every TVE source.

Also, you may want to also consolidate by TMS/TVC ID ... those are actually the same channels/feeds/streams.

FAST providers that users add via M3U/"Custom Channels" can have wildly different data associated with them. Also, some of those providers regularly change their available feeds. (Primarily Pluto, but all FAST providers are guilty.)

Are you up to supporting a moving target?

2 Likes

These are all very good points. :slight_smile:

Now that you mention it, I will add another column for the FTA channels with numbers 6700-6999 and not list them in my DIRECTV TVE source.

Right now, I chose the easy way and just compared the guide names (which I convert to uppercase to ignore differences in casing.)
I agree with you about the TMS/TVC IDs but it was more of a fun challenge that I gave myself to write this script. It is not meant to be "professional" so I'm going to leave the logic as is.
Unless maybe if there is a demand for it, which I doubt. :laughing:

This is not something that I will run everyday. I was just curious about finding the overlaps and, with more than 1,000 channels, I decided to automate the process.

Thank you for your suggestions, they are all very good. :+1:

Please share this Python script. I've been wanting to do this for some time.

1 Like

Sure. I just need to clean up the code a little bit and then I will provide a link to download it. :slight_smile:

Here it is, @cyoungers, from my Google Drive: channels_to_csv.py - Google Drive

(Note to self: look into using GitHub at some point)

As suggested by @racameron, I added a column for the free channels so it's clearer now instead of having them included with the TVE channels.

In the process of refactoring the code, I also found a bug that I fixed.
With the fix, some channel results are different now and more accurate in terms of how many times they appear in different sources. For example, it turns out that QVC is not the only channel that is available in 4 different sources now. I will fix my first post.

Usage of the script:

PS C:\Users\mjitk\Documents\Scripts> python channels_to_csv.py -h
usage: channels_to_csv.py [-h] [-i IP_ADDRESS] [-p PORT_NUMBER] [-v]

Channels DVR channel list -> CSV file.

options:
  -h, --help            show this help message and exit
  -i IP_ADDRESS, --ip_address IP_ADDRESS
                        IP address of the Channels DVR server
  -p PORT_NUMBER, --port_number PORT_NUMBER
                        Port number of the Channels DVR server
  -v, --version         Print the version number

If no options are specified, the default URL will be used: http://127.0.0.1:8089
PS C:\Users\mjitk\Documents\Scripts> python channels_to_csv.py
Using Channels DVR server at: http://127.0.0.1:8089

Getting the details of all the sources from Channels DVR...
Got 10 sources.

Writing the channel information to the CSV file...
Channel information available in channels_dvr_channel_list_20230519_172942.csv

I hope this works for you.
Let me know about your experience with it.

Thanks. I'm getting an error when I try to run the script.

python3 channels_to_csv.py -i 192.168.0.11 -p 8089
Using Channels DVR server at: http://192.168.0.11:8089

Getting the details of all the sources from Channels DVR...
Traceback (most recent call last):
  File "/Documents/Channels/channels_to_csv.py", line 351, in <module>
    sources = get_source_info_from_channels_dvr_api(server_ip_address, server_port_number)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Documents/Channels/channels_to_csv.py", line 300, in get_source_info_from_channels_dvr_api
    return [Source(source) for source in devices]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Documents/Channels/channels_to_csv.py", line 300, in <listcomp>
    return [Source(source) for source in devices]
            ^^^^^^^^^^^^^^
  File "/Documents/Channels/channels_to_csv.py", line 56, in __init__
    self.channels  = self._get_channels()
                     ^^^^^^^^^^^^^^^^^^^^
  File "/Documents/Channels/channels_to_csv.py", line 69, in _get_channels
    number = int(channel['GuideNumber'])
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: invalid literal for int() with base 10: '4.1'

Oh I see. Sorry about that. I know how to fix it.
I'm away from my computer at this time. I will fix it as soon as I get the chance later today.

Please try the new version of the script, @cyoungers (same link).

I don't have an OTA source and I didn't plan for channel numbers to contain decimal points, which is typical of OTA channel numbers.
The bug should be fixed now. :slight_smile:

By the way, you don't need to specify the port number because you are using the default one.

This command should work for you:

python3 channels_to_csv.py -i 192.168.0.11

Works great. Thanks for the update. This is so useful for me for creating channel collections and getting the big picture of the sources.

1 Like

Thanks for the reply regarding Pluto and HDHR Prime channels

1 Like

This is awesome.. I came to the forum today to ask if anyone has built exactly this.. As I consider cancelling comcast and using TVE with some other provider, I wanted a way to identify what I might be losing, and this worked great!!

Only thing I have to deal with is thinking I'll lose a channel when in reality the same channel is available in HD on another source! Can't think of a way that could be programmatically solved though, so I guess I'll have to work through that manually.

One thing I did notice is that if you have 2 of the same model HDHomeRun units, it seems to get them confused. I have been fighting with a second HDHomeRun Prime with a cable card (one reason I'm thinking of cutting cord) and so one of my Primes has no channels, but in the export, it shows the full list of channels for both. I wish the second one was getting all the channels, but no.. it seems to be just confusing the script. No big deal, but thought I'd mention it!

Thanks for all the hard work!!
-Steve

Just wanted to let you know that this script, and several other nice scripts by @mjitkop are available in the OliveTin-for-Channels project. All are consolidated in a single Docker container using OliveTin to launch them. Currently functionality includes:

  • Turn Comskip On/Off by Channel
  • List Channels with Comskip Off
  • Manually Add Recordings (TV series and movies supported)
  • Find Gracenote Station IDs
  • Fix YouTube Thumbnails (Can be run cron-style -- active scripts have green icon)
  • Generate TWiT.tv Guide Data (Can be run cron-style-- active scripts have green icon)
  • Create Channels List in CSV Format
  • Create Movies List in CSV Format
  • Scan/Prune Local Content
  • Mark an Episode for Re-Recording
  • Channel Lineup Change Notifications (Notifications can be sent by e-mail or SMS)
  • Generate Filtered Channels DVR Log (Frequently used filters can be saved in a file)
  • List Sources for a Single Channel (Uses CSV generated by above @mjitkop script as the source)
  • Delete Channels DVR Recording Log Files (Can be run cron-style and delete logs older than x days)
  • Send Message to Defined Channels Clients (Send onscreen message to all defined Channels clients)
  • Docker Compose Examples for Channels & Related Extensions
  • Remove Comskip Markers from a Recording
  • Restart or Shutdown a Channels Server
  • Ping Channels DVR Server (Can be run cron-style -- active scripts have green icon)

Most of the above will work with multiple Channels DVRs

Wow! that's great! I had no idea something like that existed.. I'm going to go try to install that now! As I was researching what Channels had to offer in regards to that channel list, I found the channels API and was thinking how powerful that looked!