Comcast did it to me again - moved the broadcast HD channels around, so I had to rescan them using mythtv-setup.
I wrote a script that I run every morning to scan the channels, and compare to an existing list. Any differences are printed out. So hopefully, this will allow me to know if I need to rescan before I find out by getting a zero length recording.
To use it, you would first create a reference scan file named scan0.txt.old using
Code:
hdhomerun_config FFFFFFFF scan /tuner0 scan0.txt.old
This takes about 10 minutes. Keep this file around.
Then when you want to run this script, create another scan file using hdhomerun_config, then use the two scan file names as arguments to this script.
Code:
hdhomerun_config FFFFFFFF scan /tuner0 scan0.txt
python compare_scan.py scan0.txt.old scan0.txt
Any differences get printed out like this:
Code:
Didn't find 101 1 67.2 MPT Sel
Didn't find 101 2 13.1 PN-2
Didn't find 101 3 67.3 MPT V-M
Didn't find 101 6 67.1 MPTHD
Comments and improvements are welcome.
Code:
#!/usr/bin/env python
import os
import string
import sys
class Channel:
def __init__(self, channel, program, name):
self.channel= int(channel)
self.program = int(program)
self.name = name
def __cmp__(self, other):
if (self.channel < other.channel):
return -1
if (self.channel > other.channel):
return 1
if (self.program < other.program):
return -1
if (self.program > other.program):
return 1
return cmp(self.name, other.name)
def str(self):
return str(self.channel) + " " + str(self.program) + self.name
def read_channel_scan(file):
f = open(file)
lines = f.readlines()
f.close()
channels = [ Channel(0, 0, '0') ]
for l in lines:
this_line = l.split()
if (this_line[0] == "SCANNING:"):
channel_str = this_line[2]
this_channel = channel_str[0:-1].split(':')[1]
if (this_line[0] == "PROGRAM:"):
this_line = l.split(':')
this_program = this_line[1]
if (len(this_line) > 2):
this_name = this_line[2][:-1]
hdchan = this_name.split()[0]
if (hdchan != "0.0" and hdchan != "1008.0"):
channels.append(Channel(this_channel, this_program,
this_name))
channels = channels[1:]
channels.sort()
return channels
def write_channel_scan(channels, file):
f = open(file, "w")
for c in channels:
f.write(c.str()+"\n")
f.close()
def compare_channel_scan(channels0, channels1):
if (len(channels0) != len(channels1)):
print "lists are of different lengths: ", len(channels0), ", ", len(channels1)
for c0 in channels0:
found = 0
for c1 in channels1:
if (c0 == c1):
found = 1
break
if (found == 0):
print "Didn't find ", c0.str()
if __name__ == "__main__":
# Create channel scan
if (len(sys.argv) < 3):
print 'Usage:'
print '\tTo compare two scan files:'
print '\t\t', sys.argv[0], ' scan0.txt.old scan0.txt'
if (len(sys.argv) == 3):
channels0 = read_channel_scan(sys.argv[1])
channels1 = read_channel_scan(sys.argv[2])
compare_channel_scan(channels0, channels1)