From: Jaroslav Kysela Date: Fri, 23 May 2014 18:42:28 +0000 (+0200) Subject: scanfile: Add satellite.xml database support (enigma2, satellites-xml.eu) X-Git-Tag: v4.1~2050 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1418b6411284b52bce2f2d7a949be06309505622;p=thirdparty%2Ftvheadend.git scanfile: Add satellite.xml database support (enigma2, satellites-xml.eu) - also improve the linuxdvb scanfile database fetching --- diff --git a/Makefile b/Makefile index 609a5a0bc..dee8c4122 100644 --- a/Makefile +++ b/Makefile @@ -277,6 +277,7 @@ BUNDLES-yes += docs/html docs/docresources src/webui/static BUNDLES-yes += data/conf BUNDLES-${CONFIG_DVBSCAN} += data/dvb-scan BUNDLES = $(BUNDLES-yes) +ALL-$(CONFIG_DVBSCAN) += check_dvb_scan # # Add-on modules @@ -298,7 +299,7 @@ DEPS = ${OBJS:%.o=%.d} # # Default -all: ${PROG} +all: $(ALL-yes) ${PROG} # Special .PHONY: clean distclean check_config reconfigure @@ -356,3 +357,27 @@ $(BUILDDIR)/bundle.o: $(BUILDDIR)/bundle.c $(BUILDDIR)/bundle.c: @mkdir -p $(dir $@) $(MKBUNDLE) -o $@ -d ${BUILDDIR}/bundle.d $(BUNDLE_FLAGS) $(BUNDLES:%=$(ROOTDIR)/%) + +# linuxdvb git tree +$(ROOTDIR)/data/dvb-scan/.stamp: + @echo "Receiving data/dvb-scan/dvb-t from http://linuxtv.org/git/dtv-scan-tables.git" + @rm -rf $(ROOTDIR)/data/dvb-scan/* + @$(ROOTDIR)/support/getmuxlist $(ROOTDIR)/data/dvb-scan + @touch $(ROOTDIR)/data/dvb-scan/.stamp + +.PHONY: check_dvb_scan +check_dvb_scan: $(ROOTDIR)/data/dvb-scan/.stamp + +# dvb-s / enigma2 / satellites.xml +$(ROOTDIR)/data/dvb-scan/dvb-s/.stamp: $(ROOTDIR)/data/satellites.xml \ + $(ROOTDIR)/data/dvb-scan/.stamp + @echo "Generating data/dvb-scan/dvb-s from data/satellites.xml" + @if ! test -s $(ROOTDIR)/data/satellites.xml ; then echo "Put your satellites.xml file to $(ROOTDIR)/data/satellites.xml"; exit 1; fi + @if ! test -d $(ROOTDIR)/data/dvb-scan/dvb-s ; then mkdir $(ROOTDIR)/data/dvb-scan/dvb-s ; fi + @rm -rf $(ROOTDIR)/data/dvb-scan/dvb-s/* + @$(ROOTDIR)/support/sat_xml_scan.py \ + $(ROOTDIR)/data/satellites.xml $(ROOTDIR)/data/dvb-scan/dvb-s + @touch $(ROOTDIR)/data/dvb-scan/dvb-s/.stamp + +.PHONY: satellites_xml +satellites_xml: $(ROOTDIR)/data/dvb-scan/dvb-s/.stamp diff --git a/data/satellites.xml b/data/satellites.xml new file mode 100644 index 000000000..e69de29bb diff --git a/support/apt-update b/support/apt-update index a843050bf..59c04998c 100755 --- a/support/apt-update +++ b/support/apt-update @@ -45,8 +45,6 @@ git archive --prefix=tvheadend/ HEAD | tar -C "${TMPDIR}" -x ||\ die "failed to archive git tree" cd "$TMPDIR/tvheadend" || die "failed to enter archived tree" -# Fetch scan files -./support/getmuxlist || die "failed to fetch dvb-scan files" cd .. # For each distro diff --git a/support/getmuxlist b/support/getmuxlist index c4479c3f6..0c81a27e2 100755 --- a/support/getmuxlist +++ b/support/getmuxlist @@ -9,12 +9,15 @@ DIR=$1 # Update if [ -d "${DIR}/.git" ]; then - (cd "${DIR}"; git pull) &> /dev/null - + LAST=$(pwd) + cd "${DIR}" || exit 1 + git pull &> /dev/null || exit 1 + git reset --hard &> /dev/null || exit 1 + cd "${LAST}" || exit 1 # Fetch elif [ ! -d "${DIR}" ]; then URL=http://linuxtv.org/git/dtv-scan-tables.git - git clone $URL "${DIR}" &> /dev/null + git clone $URL "${DIR}" &> /dev/null || exit 1 fi # Note: will not update existing set (if not .git) diff --git a/support/sat_xml_scan.py b/support/sat_xml_scan.py new file mode 100755 index 000000000..815496a46 --- /dev/null +++ b/support/sat_xml_scan.py @@ -0,0 +1,102 @@ +#!/usr/bin/env python +# +# Convert XML files from http://satellites-xml.eu/ to scanfile format +# + +import os +import sys +import xml.etree.ElementTree as ET +import re, unicodedata + +FLAG_NETWORK_SCAN = 1 +FLAG_USE_BAT = 2 +FLAG_USE_ONOT = 4 +FLAG_SKIP_NIT = 8 + +POLARIZATION = { + '0': 'H', + '1': 'V', + '2': 'L', + '3': 'R' +} + +FEC = { + '0': 'AUTO', + '1': '1/2', + '2': '2/3', + '3': '3/4', + '4': '5/6', + '5': '7/8', + '6': '8/9', + '7': '3/5', + '8': '4/5', + '9': '9/10', + '15': 'NONE' +} + +MODULATION = { + '0': 'AUTO', + '1': 'QPSK', + '2': '8PSK' +} + +SYSTEM = { + '0': 'S', + '1': 'S2' +} + +def inspect(node): + print(' tag=%s attrib=%s' % (repr(node.tag), repr(node.attrib))) + +def asciize(str): + if type(str) != type(u''): + str = unicode(str, 'UTF-8') + str = unicodedata.normalize('NFKD', str).encode('ascii', 'ignore') + str = re.sub('\s\s+', ' ', str) + str = str.strip().replace(' ', '-') + return str + +def parse_sat(node): + + position = node.attrib['position'] + flags = node.attrib['flags'] + name = node.attrib['name'] + + assert(flags == '0') + + filename = name.replace('(', '').replace(')', '').replace('/', '+') + filename = DIR + '/' + asciize(filename) + + fp = open(filename, "w+") + fp.write('# Generated by tvheadend from satellites.xml\n') + + for child in node: + if child.tag == 'transponder': + polarization = POLARIZATION[child.attrib['polarization']] + fec = FEC[child.attrib['fec_inner']] + freq = child.attrib['frequency'] + rate = child.attrib['symbol_rate'] + modulation = MODULATION[child.attrib['modulation']] + system = SYSTEM[child.attrib['system']] + if system == 'S' and modulation == 'QPSK': + fp.write('%s %s %s %s %s\n' % + (system, freq, polarization, rate, fec)) + else: + fp.write('%s %s %s %s %s %s %s\n' % + (system, freq, polarization, rate, fec, 'AUTO', modulation)) + + fp.close() + +if len(sys.argv) < 3: + print('Usage: %s satellite.xml /output/directory/path') + sys.exit(0) + +DIR = sys.argv[2] +if not os.path.isdir(DIR): + raise ValueError, "Second argument must be the output directory" +tree = ET.parse(sys.argv[1]) +root = tree.getroot() +if root.tag == 'satellites': + for child in root: + if child.tag == 'sat': + parse_sat(child)