]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
scanfile: Add satellite.xml database support (enigma2, satellites-xml.eu)
authorJaroslav Kysela <perex@perex.cz>
Fri, 23 May 2014 18:42:28 +0000 (20:42 +0200)
committerJaroslav Kysela <perex@perex.cz>
Mon, 26 May 2014 13:11:27 +0000 (15:11 +0200)
- also improve the linuxdvb scanfile database fetching

Makefile
data/satellites.xml [new file with mode: 0644]
support/apt-update
support/getmuxlist
support/sat_xml_scan.py [new file with mode: 0755]

index 609a5a0bc30aeaadb136660e7c1b5901241f9044..dee8c41222b57d19998c39928bcdfe0dcfea3df9 100644 (file)
--- 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 (file)
index 0000000..e69de29
index a843050bf6c960979e4ff506bddd6c24183a0e86..59c04998caa49f9f77a2de0151dcceaf95b3b29d 100755 (executable)
@@ -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
index c4479c3f6b49592fb2c7d0f858d9effabdedd6b2..0c81a27e26f29d4bb6a63e208b3fe4aef8d38c9c 100755 (executable)
@@ -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 (executable)
index 0000000..815496a
--- /dev/null
@@ -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)