Skip to content

Commit

Permalink
[DsayersCustomMixImporter] Allow user to select different sources
Browse files Browse the repository at this point in the history
  • Loading branch information
Huevos committed Sep 10, 2017
1 parent 52b1b0a commit 1212765
Show file tree
Hide file tree
Showing 9 changed files with 101 additions and 16 deletions.
2 changes: 1 addition & 1 deletion DsayersCustomMixImporter/Makefile.am
@@ -1 +1 @@
SUBDIRS = meta po src
SUBDIRS = meta po src mixes
3 changes: 3 additions & 0 deletions DsayersCustomMixImporter/mixes/Makefile.am
@@ -0,0 +1,3 @@
installdir = $(libdir)/enigma2/python/Plugins/SystemPlugins/DsayersCustomMixImporter/mixes

install_DATA = *.xml
@@ -0,0 +1,5 @@
<custommiximport>
<name>Dsayers: Sky UK free to air channels into Virgin Media UK</name>
<provider>cable_uk_virgin</provider>
<url>https://raw.githubusercontent.com/davesayers2014/AutoBouquetsMaker/master/AutoBouquetsMaker/custom/cable_uk_virgin_CustomMix.xml</url>
</custommiximport>
5 changes: 5 additions & 0 deletions DsayersCustomMixImporter/mixes/dsayers_vmuk_into_skyuk.xml
@@ -0,0 +1,5 @@
<custommiximport>
<name>Dsayers: Virgin Media UK channels into Sky UK</name>
<provider>sat_282_sky_uk</provider>
<url>https://raw.githubusercontent.com/davesayers2014/AutoBouquetsMaker/master/AutoBouquetsMaker/custom/sat_282_sky_uk_CustomMix.xml</url>
</custommiximport>
@@ -0,0 +1,5 @@
<custommiximport>
<name>Jawz: Virgin Media IE and Sky IE channels into Sky UK</name>
<provider>sat_282_sky_uk</provider>
<url>https://raw.githubusercontent.com/jawz86/Jawz-CustomMix/master/sat_282_sky_uk_CustomMix.xml</url>
</custommiximport>
62 changes: 62 additions & 0 deletions DsayersCustomMixImporter/src/mixes.py
@@ -0,0 +1,62 @@
import os
import xml.dom.minidom

class Mixes():
MIXES_DIR = os.path.dirname(__file__) + "/mixes"

def parseXML(self, filename):
try:
mix = open(filename, "r")
except Exception, e:
print "[DsayersCustomMixImporter][Mixes] Cannot open %s: %s" % (filename, e)
return None

try:
dom = xml.dom.minidom.parse(mix)
except Exception, e:
print "[DsayersCustomMixImporter][Mixes] XML parse error (%s): %s" % (filename, e)
mix.close()
return None

mix.close()
return dom

def read(self):
mixes = {}
for filename in os.listdir(self.MIXES_DIR):
if filename[-4:] != ".xml":
continue

dom = self.parseXML(self.MIXES_DIR + "/" + filename)
if dom is None:
continue

mix = {}
mix["key"] = filename[:-4]
if dom.documentElement.nodeType == dom.documentElement.ELEMENT_NODE and dom.documentElement.tagName == "custommiximport":
for node in dom.documentElement.childNodes:
if node.nodeType != node.ELEMENT_NODE:
continue

if node.tagName == "name":
node.normalize()
if len(node.childNodes) == 1 and node.childNodes[0].nodeType == node.TEXT_NODE:
mix["name"] = node.childNodes[0].data.encode("utf-8")
elif node.tagName == "provider":
node.normalize()
if len(node.childNodes) == 1 and node.childNodes[0].nodeType == node.TEXT_NODE:
mix["provider"] = node.childNodes[0].data.encode("utf-8")
elif node.tagName == "url":
node.normalize()
if len(node.childNodes) == 1 and node.childNodes[0].nodeType == node.TEXT_NODE:
mix["url"] = node.childNodes[0].data.encode("utf-8")

if not ("name" in mix and "provider" in mix and "url" in mix):

print "[DsayersCustomMixImporter][Mixes] Incomplete XML %s" % filename
continue

mixes[mix["key"]] = mix

return mixes

29 changes: 16 additions & 13 deletions DsayersCustomMixImporter/src/plugin.py
Expand Up @@ -26,13 +26,16 @@

#Plugins
from Plugins.Plugin import PluginDescriptor
from mixes import Mixes

defaultFileLocation = "https://raw.githubusercontent.com/davesayers2014/AutoBouquetsMaker/master/AutoBouquetsMaker/custom/sat_282_sky_uk_CustomMix.xml"
mixes = Mixes().read()
choices = sorted([(mixes[x]["key"], mixes[x]["name"]) for x in mixes], key=lambda listItem: listItem[1])

default_mix = "dsayers_vmuk_into_skyuk"
ABMpath = "/usr/lib/enigma2/python/Plugins/SystemPlugins/AutoBouquetsMaker/custom/"
ABMfile = "sat_282_sky_uk_CustomMix.xml"

config.plugins.dsayersImporter = ConfigSubsection()
config.plugins.dsayersImporter.fileLocation = ConfigText(default = defaultFileLocation, fixed_size = False)
config.plugins.dsayersImporter.mix = ConfigSelection(default = default_mix, choices = choices)
config.plugins.dsayersImporter.enableImporter = ConfigYesNo(default = True)
config.plugins.dsayersImporter.leadTime = ConfigSelection(default = "5", choices = [("1", _("1 minute")), ("2", _("2 minutes")), ("3", _("3 minutes")), ("5", _("5 minutes")), ("10", _("10 minutes")), ("20", _("20 minutes")), ("30", _("30 minutes"))])

Expand Down Expand Up @@ -79,14 +82,14 @@ def __init__(self, session, setup, plugin=None, menu_path=None, PluginLanguageDo
self.onLayoutFinish.append(self.updatebuttontext)

def updatebuttontext(self):
if fileExists(ABMpath + ABMfile, "w"):
if fileExists(ABMpath + mixes[config.plugins.dsayersImporter.mix.value]["provider"] + "_CustomMix.xml", "w"):
self["key_blue"].setText(_("Delete file"))
else:
self["key_blue"].setText("")

def keyDelete(self):
if fileExists(ABMpath + ABMfile, "w"):
os.remove(ABMpath + ABMfile)
if fileExists(ABMpath + mixes[config.plugins.dsayersImporter.mix.value]["provider"] + "_CustomMix.xml", "w"):
os.remove(ABMpath + mixes[config.plugins.dsayersImporter.mix.value]["provider"] + "_CustomMix.xml")
self.updatebuttontext()

def keySave(self):
Expand Down Expand Up @@ -151,7 +154,7 @@ def firstExec(self):
if not inStandby:
self["action"].setText(_('Saving CustomMix file'))
self["status"] = Label("")
with open(ABMpath + ABMfile,"w") as f:
with open(ABMpath + mixes[config.plugins.dsayersImporter.mix.value]["provider"] + "_CustomMix.xml", "w") as f:
f.write(CustomMix)
f.close()
if not inStandby:
Expand All @@ -165,7 +168,7 @@ def firstExec(self):

def fetchURL(self):
try:
req = urllib2.Request(config.plugins.dsayersImporter.fileLocation.value)
req = urllib2.Request(mixes[config.plugins.dsayersImporter.mix.value]["url"])
response = urllib2.urlopen(req)
print '[DsayersCustomMixImporter][fetchURL] Response: %d' % response.getcode()
if int(response.getcode()) == 200:
Expand Down Expand Up @@ -201,7 +204,7 @@ def __init__(self, session):
self.justBootedOrConfigChanged = True
self.enableImporter = config.plugins.dsayersImporter.enableImporter.value
self.leadTime = config.plugins.dsayersImporter.leadTime.value
self.fileLocation = config.plugins.dsayersImporter.fileLocation.value
self.mix = config.plugins.dsayersImporter.mix.value
try:
self.enableSchedule = config.autobouquetsmaker.schedule.value
self.clock = [config.autobouquetsmaker.scheduletime.value[0], config.autobouquetsmaker.scheduletime.value[1]]
Expand Down Expand Up @@ -229,7 +232,7 @@ def __onClose(self):
def configChecker(self):
if self.enableImporter != config.plugins.dsayersImporter.enableImporter.value or \
self.leadTime != config.plugins.dsayersImporter.leadTime.value or \
self.fileLocation != config.plugins.dsayersImporter.fileLocation.value or \
self.mix != config.plugins.dsayersImporter.mix.value or \
self.enableSchedule != config.autobouquetsmaker.schedule.value or \
self.clock[0] != config.autobouquetsmaker.scheduletime.value[0] or \
self.clock[1] != config.autobouquetsmaker.scheduletime.value[1] or \
Expand All @@ -238,7 +241,7 @@ def configChecker(self):
print "[DsayersCustomMixImporter][configChecker] config has changed"
self.enableImporter = config.plugins.dsayersImporter.enableImporter.value
self.leadTime = config.plugins.dsayersImporter.leadTime.value
self.fileLocation = config.plugins.dsayersImporter.fileLocation.value
self.mix = config.plugins.dsayersImporter.mix.value
self.enableSchedule = config.autobouquetsmaker.schedule.value
self.clock[0] = config.autobouquetsmaker.scheduletime.value[0]
self.clock[1] = config.autobouquetsmaker.scheduletime.value[1]
Expand Down Expand Up @@ -299,7 +302,7 @@ def taskToSchedule(session, **kwargs):

def pluginManualStart(menuid, **kwargs):
if menuid == "scan":
return [(_("Dsayers CustomMix"), DsayersCustomMixImporterMain, "DsayersCustomMixImporterScreen", 11)]
return [(_("Dsayers CustomMix Importer"), DsayersCustomMixImporterMain, "DsayersCustomMixImporterScreen", 11)]
return []

def DsayersCustomMixImporterMain(session, **kwargs):
Expand All @@ -310,5 +313,5 @@ def Plugins(**kwargs):
pList = []
if ABMisLoaded():
pList.append( PluginDescriptor(where = [PluginDescriptor.WHERE_SESSIONSTART], fnc=pluginAutoStart))
pList.append( PluginDescriptor(name=_("Dsayers CustomMix Importer"), description="Imports Dsayers CustomMix for ABM", where = PluginDescriptor.WHERE_MENU, fnc=pluginManualStart, needsRestart=True) )
pList.append( PluginDescriptor(name=_("Dsayers CustomMix Importer"), description="Imports CustomMix files for ABM", where = PluginDescriptor.WHERE_MENU, fnc=pluginManualStart, needsRestart=True) )
return pList
5 changes: 3 additions & 2 deletions DsayersCustomMixImporter/src/setup.xml
@@ -1,7 +1,8 @@
<!--suppress XmlUnboundNsPrefix -->
<setupxml>
<setup key="dsayerscustommiximporter" title="Dsayers CustomMix">
<item level="2" text="Enable autofetch" description="Allows you automatically fetch the Dsayers CustomMix file.">config.plugins.dsayersImporter.enableImporter</item>
<setup key="dsayerscustommiximporter" title="Dsayers CustomMix Importer">
<item level="2" text="Import" description="Select the CustomMix you want to import">config.plugins.dsayersImporter.mix</item>
<item level="2" text="Enable autofetch" description="Allows you automatically fetch the CustomMix file.">config.plugins.dsayersImporter.enableImporter</item>
<item level="2" text="Lead time" requires="config.plugins.dsayersImporter.enableImporter" description="Number of minutes prior to the ABM scan that the CustomMix file should be fetched">config.plugins.dsayersImporter.leadTime</item>
</setup>
</setupxml>
1 change: 1 addition & 0 deletions configure.ac
Expand Up @@ -240,6 +240,7 @@ DsayersCustomMixImporter/Makefile
DsayersCustomMixImporter/meta/Makefile
DsayersCustomMixImporter/po/Makefile
DsayersCustomMixImporter/src/Makefile
DsayersCustomMixImporter/mixes/Makefile
FirmwareUpgrade/Makefile
FirmwareUpgrade/src/Makefile
Expand Down

0 comments on commit 1212765

Please sign in to comment.