#!/usr/bin/python ''' SVPlayer dvb channels.conf import script. (c) 2011-2013 Jan ONDREJ (SAL) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. Usage: w_scan > /tmp/channels.conf import-dvb.py /tmp/channels.conf ''' import sys class base: def __init__(self, f): self.f = f self.freqs = [] self.channels = [] self.parse() def str_freqs(self): for freq in self.freqs: yield 'f%d = dict(' % (freq['frequency']/self.unit) for key, value in freq.items(): yield ' %s=%s,' % (key, value) yield ')' def str_channels(self): yield "CHANNELS = [" for ch in self.channels: yield ch yield "]" def __str__(self): return '\n'.join(list(self.str_freqs())+['']+list(self.str_channels())) class channels_conf(base): unit = 1000000 def parse(self): for line in self.f.readlines(): if line.startswith("#"): continue # ignore comment line = line.strip().split(":") name, frequency, inversion, bandwidth, fec, fec2, qam, transmission, \ guard, hierarchy, a, b, channel = line data = {} data['frequency'] = int(frequency) if inversion=="INVERSION_AUTO": data['inversion'] = 2 else: print "UNKNOWN inversion:", inversion if bandwidth.startswith("BANDWIDTH_"): data['bandwidth'] = \ bandwidth.replace("BANDWIDTH_", "").replace("_MHZ", "").lower() else: print "UNKNOWN bandwidth:", bandwidth if fec=='FEC_2_3' and fec2=="FEC_NONE": data['code_rate_lp'] = 0 data['code_rate_hp'] = 2 elif fec=="FEC_AUTO" and fec2=="FEC_AUTO": data['code_rate_lp'] = 9 data['code_rate_hp'] = 9 else: print "UNKNOWN fec:", fec, fec2 if qam=="QAM_AUTO": data['modulation'] = 0 elif qam=="QAM_64": data['modulation'] = 64 elif qam=="QAM_128": data['modulation'] = 128 else: print "UNKNOWN modulation:", qam if guard=="GUARD_INTERVAL_1_4": data['guard'] = 4 elif guard=="GUARD_INTERVAL_AUTO": data['guard'] = 0 else: print "UNKNOWN guard:", guard if transmission=="TRANSMISSION_MODE_AUTO": data['transmission'] = 0 elif transmission=="TRANSMISSION_MODE_8K": data['transmission'] = 8 else: print "UNKNOWN transmission:", transmission if hierarchy=="HIERARCHY_AUTO": data['hierarchy'] = 0 elif hierarchy=="HIERARCHY_NONE": data['hierarchy'] = -1 else: print "UNKNOWN hierarchy:", hierarchy if data not in self.freqs: self.freqs.append(data) self.channels.append( ' dvbt(u"%s", %s, **f%d),' % (name, channel, data['frequency']/1000000) ) class w_scan(base): unit = 1000000 def parse(self): for line in self.f.readlines(): if line.startswith("#"): continue # ignore comment line = line.strip().split(":") # STV1;Towercom:506000:I999B8C999D999M999T999G999Y999 # :T:27500:3102=2:3111:3130:0:3001:0:0:0 name, frequency, params, p1, p2, p3, p4, p5, p6, channel, p7, p8, p9 \ = line name = name.replace(';(null)', '') data = dict( frequency = int(frequency)*1000 ) if data not in self.freqs: self.freqs.append(data) self.channels.append( ' dvbt(u"%s", %s, **f%d),' % (name, channel, data['frequency']/1000000) ) if len(sys.argv)<2: print __doc__ sys.exit() f = open(sys.argv[1], 'rt') # autodetect format line = f.readline() f.seek(0) if 'INVERSION_' in line and 'FEC_' in line: print str(channels_conf(f)) else: print str(w_scan(f))