import struct from collections import OrderedDict import sys """ char Available; // flag if entry is available for use char Used; // flag if entry is used char Skip; // flag if entry is to be skipped by +/- char Source; // signal source, see enumeration below char Signal; // signal type, see enumeration below char Modulation; // modulation, see enumeration below char Locked; // channel locked (0=open, 1=locked) char Unknown7; //*14 | 8 char Tuned; //*0 | 1 short Number; //*customized channel number char Unknown11; //*-1 | 14 long Unknown12; //*0 short Preset; //*pre-assigned channel number unsigned short Length; // channel name length (in BYTES!) unsigned short Name[6]; // big-endian Unicode characters float Frequency; // frequency in MHz with fractions char Unknown36; //* 1 char Unknown37; //*-1 unsigned char Favorites; // favorites, see definitions below unsigned char CRC; """ def parseA(data, c): keyz = ['Available', 'Used', 'Skip', 'Source', 'Signal', 'Modulation', 'Locked', 'Unknown7', 'Tuned', 'Number', 'Unknown11', 'Unknown12', 'Preset', 'Length', 'Name', 'Frequency', 'Unknown36', 'Unknown37', 'Favorites', 'CRC'] format = " 0): packA(d.split(";"), f) else: print "done!" break f.close() c.close() print "Packing map-CableA...", f = open("map-CableA", "wb") c = open("map-CableA.csv", "r") c.readline() while (True): d = c.readline().strip() if (len(d) > 0): packA(d.split(";"), f) else: print "done!" break f.close() c.close() def readD(): keyz = ["Number", "VID_PID", "PCR_PID", "SID", "Unknown8", "Unknown9", "Source", "Signal", "Modulation", "Unknown13", "Bandwidth", "Type", "VideoCodec", "Unknown17", "Unknown18", "Unknown19", "VideoWidth", "VideoHeight", "Scrambled", "FrameRate", "Unknown26", "Unknown27", "SymbolRate", "Unknown30", "Locked", "ONID", "NID", "Unknown36", "Provider", "Channel", "LCN", "Unknown46", "TSID", "Unknown50", "Unknown56", "Unknown60", "Name", "Short", "VideoFormat", "Unknown283", "Unknown284", "Unknown288", "Favorites", "CRC"] print "Unpacking map-AirD...", f = open("map-AirD", "rb") c = open("map-AirD.csv", "w") c.write(";".join(map(str, keyz))+"\n") while (True): data = f.read(292) if (len(data) != 292): print "done!" break parseD(data, c) f.close() c.close() print "Unpacking map-CableD...", f = open("map-CableD", "rb") c = open("map-CableD.csv", "w") c.write(";".join(map(str, keyz))+"\n") while (True): data = f.read(292) if (len(data) != 292): print "done!" break parseD(data, c) f.close() c.close() def writeD(): print "Packing map-AirD...", f = open("map-AirD", "wb") c = open("map-AirD.csv", "r") c.readline() while (True): d = c.readline().strip() if (len(d) > 0): packD(d.split(";"), f) else: print "done!" break f.close() c.close() print "Packing map-CableD...", f = open("map-CableD", "wb") c = open("map-CableD.csv", "r") c.readline() while (True): d = c.readline().strip() if (len(d) > 0): packD(d.split(";"), f) else: print "done!" break f.close() c.close() if __name__ == "__main__": if (len(sys.argv) != 2) or (sys.argv[1].lower() != 'read' and sys.argv[1].lower() != 'write'): print "Usage: runme.py read - to decode channel list" print " runme.py write - to reencode channel list" sys.exit(0) if (sys.argv[1].lower() == 'write'): writeA() writeD() else: readA() readD()