Enigma2 plugin to dowload and create channels picons files form lyngsat.com

plugin.py 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. #
  2. # This file is part of GetPicons - enigma2 plugin to download picons from lyngsat.com
  3. # Copyright (c) 2016 ivars777 (ivars777@gmail.com)
  4. # Distributed under the GNU GPL v3. For full terms see http://www.gnu.org/licenses/gpl-3.0.en.html
  5. from Screens.Screen import Screen
  6. from Screens.Console import Console
  7. from Components.MenuList import MenuList
  8. from Components.Sources.StaticText import StaticText
  9. from Components.Button import Button
  10. from Components.ActionMap import ActionMap
  11. from Screens.MessageBox import MessageBox
  12. from Plugins.Plugin import PluginDescriptor
  13. import os,os.path
  14. ###########################################################################
  15. class MainScreen(Screen):
  16. skin = """
  17. <screen position="center,center" size="560,400" title="GetPicons" >
  18. <widget name="content" position="10,40" size="540,350" scrollbarMode="showOnDemand" />
  19. <ePixmap name="red" position="0,0" zPosition="2" size="140,40" pixmap="skin_default/buttons/red.png" transparent="1" alphatest="on" />
  20. <ePixmap name="green" position="140,0" zPosition="2" size="140,40" pixmap="skin_default/buttons/green.png" transparent="1" alphatest="on" />
  21. <ePixmap name="yellow" position="280,0" zPosition="2" size="140,40" pixmap="skin_default/buttons/yellow.png" transparent="1" alphatest="on" />
  22. <ePixmap name="blue" position="420,0" zPosition="2" size="140,40" pixmap="skin_default/buttons/blue.png" transparent="1" alphatest="on" />
  23. <widget name="key_red" position="0,0" size="140,40" valign="center" halign="center" zPosition="4" foregroundColor="white" font="Regular;20" transparent="1" shadowColor="background" shadowOffset="-2,-2" />
  24. <widget name="key_green" position="140,0" size="140,40" valign="center" halign="center" zPosition="4" foregroundColor="white" font="Regular;20" transparent="1" shadowColor="background" shadowOffset="-2,-2" />
  25. <widget name="key_yellow" position="280,0" size="140,40" valign="center" halign="center" zPosition="4" foregroundColor="white" font="Regular;20" transparent="1" shadowColor="background" shadowOffset="-2,-2" />
  26. <widget name="key_blue" position="420,0" size="140,40" valign="center" halign="center" zPosition="4" foregroundColor="white" font="Regular;20" transparent="1" shadowColor="background" shadowOffset="-2,-2" />
  27. </screen>"""
  28. def __init__(self, session, args = 0):
  29. self.session = session
  30. menu_list = [("Download picons for all satellites","all")]
  31. for line in open("/etc/enigma2/settings"):
  32. if not "config.Nims.0.advanced.sat." in line: continue
  33. s = line.strip().split(".")
  34. sat_num = int(s[5])
  35. if sat_num>1800: sat_num = sat_num - 3600
  36. sat_pos = "%s.%s%s"%(abs(sat_num)/10,abs(sat_num)%10,"E" if sat_num>0 else "W")
  37. menu_list.append( ("Download for %s (%s)"%(sat_pos,s[6]), sat_num) )
  38. menu_list.append(("Exit","exit"))
  39. Screen.__init__(self, session)
  40. self["content"] = MenuList(menu_list)
  41. self["key_red"] = Button("Exit")
  42. self["key_green"] = Button("Select")
  43. self["key_yellow"] = Button("Options")
  44. self["key_blue"] = Button("About")
  45. self["action_map"] = ActionMap(["OkCancelActions", "ColorActions"],
  46. {
  47. "ok": self.go,
  48. "cancel": self.cancel,
  49. "green":self.go,
  50. "red":self.cancel,
  51. "yellow":self.options,
  52. "blue":self.about
  53. }, -1)
  54. def go(self):
  55. item = self["content"].l.getCurrentSelection()[1]
  56. if item == "exit":
  57. self.close(None)
  58. else:
  59. print "picon folder = %s size = %s overwrite=%s"%(config.plugins.getpicons.folder.value,config.plugins.getpicons.folder.value,config.plugins.getpicons.overwrite.value)
  60. param = ""
  61. param += " -s %s"%(item) if item <> "all" else ""
  62. param += " -o" if config.plugins.getpicons.overwrite.value else ""
  63. param += " -z %s"%config.plugins.getpicons.size.value if config.plugins.getpicons.size.value else ""
  64. param += " -b %s"%config.plugins.getpicons.background.value if config.plugins.getpicons.background.value else ""
  65. param += " -l" if config.plugins.getpicons.simple.value else ""
  66. param += " -d" if config.plugins.getpicons.debug.value else ""
  67. cur_directory = os.path.dirname(os.path.realpath(__file__))
  68. name = os.path.join(cur_directory,"get_picons.py")
  69. cmd = "python -u %s -f %s %s"%(name,config.plugins.getpicons.folder.value,param,)
  70. #print "[GetPicons] Execute '%s'"%cmd
  71. #os.chmod(name, 493)
  72. if config.plugins.getpicons.folder.value:
  73. self.session.open(Console, "Download picons from lyngsat.com", cmdlist=[cmd])
  74. def cancel(self):
  75. print "\n[GetPicons] cancel\n"
  76. self.close(None)
  77. def options(self):
  78. print "\n[GetPicons] options\n"
  79. self.session.open(ConfigScreen)
  80. def about(self):
  81. txt = """
  82. GetPicons plugin
  83. Download channels picon files from lyngsat.com for all/selected satellites
  84. Could be run from terminal too:
  85. /usr/script/get_picons.sh -h
  86. Version 0.4
  87. (c) 2013-2017 ivars777@gmail.com"""
  88. self.session.open(MessageBox, txt, MessageBox.TYPE_INFO)
  89. #self.session.openWithCallback(self.callMyMsg, MessageBox, _("Do you want to exit the plugin?"), MessageBox.TYPE_INFO)
  90. return
  91. ##########################################################################
  92. from Components.config import config, ConfigSubsection, \
  93. ConfigYesNo, getConfigListEntry, \
  94. ConfigSelection, ConfigNumber, ConfigDirectory,ConfigText
  95. from Components.ConfigList import ConfigListScreen
  96. from Screens.LocationBox import LocationBox
  97. config.plugins.getpicons = ConfigSubsection()
  98. config.plugins.getpicons.folder = ConfigDirectory(default="/media/hdd")
  99. config.plugins.getpicons.size = ConfigSelection({"400x240":"400x240","220x132":"220x132","100x60":"100x60"}, default="220x132")
  100. config.plugins.getpicons.overwrite = ConfigYesNo(default = True)
  101. config.plugins.getpicons.background = ConfigText(default="FFFFFF20")
  102. config.plugins.getpicons.simple = ConfigYesNo(default = False)
  103. config.plugins.getpicons.debug = ConfigYesNo(default = False)
  104. class ConfigScreen(ConfigListScreen,Screen):
  105. skin = """
  106. <screen position="center,center" size="560,400" title="Options" >
  107. <ePixmap name="red" position="0,0" zPosition="2" size="140,40" pixmap="skin_default/buttons/red.png" transparent="1" alphatest="on" />
  108. <ePixmap name="green" position="140,0" zPosition="2" size="140,40" pixmap="skin_default/buttons/green.png" transparent="1" alphatest="on" />
  109. <ePixmap name="yellow" position="280,0" zPosition="2" size="140,40" pixmap="skin_default/buttons/yellow.png" transparent="1" alphatest="on" />
  110. <ePixmap name="blue" position="420,0" zPosition="2" size="140,40" pixmap="skin_default/buttons/blue.png" transparent="1" alphatest="on" />
  111. <widget name="key_red" position="0,0" size="140,40" valign="center" halign="center" zPosition="4" foregroundColor="white" font="Regular;20" transparent="1" shadowColor="background" shadowOffset="-2,-2" />
  112. <widget name="key_green" position="140,0" size="140,40" valign="center" halign="center" zPosition="4" foregroundColor="white" font="Regular;20" transparent="1" shadowColor="background" shadowOffset="-2,-2" />
  113. <widget name="key_yellow" position="280,0" size="140,40" valign="center" halign="center" zPosition="4" foregroundColor="white" font="Regular;20" transparent="1" shadowColor="background" shadowOffset="-2,-2" />
  114. <widget name="key_blue" position="420,0" size="140,40" valign="center" halign="center" zPosition="4" foregroundColor="white" font="Regular;20" transparent="1" shadowColor="background" shadowOffset="-2,-2" />
  115. <widget name="config" position="10,40" size="540,340" scrollbarMode="showOnDemand" />
  116. </screen>"""
  117. def __init__(self, session, args = 0):
  118. self.session = session
  119. self.setup_title = "Options"
  120. Screen.__init__(self, session)
  121. cfg = config.plugins.getpicons
  122. self.list = [
  123. getConfigListEntry(_("Picons folder"), cfg.folder),
  124. getConfigListEntry(_("Picon size"), cfg.size),
  125. getConfigListEntry(_("Overwrite existing picon files"), cfg.overwrite),
  126. getConfigListEntry(_("Background color hex code (HHHHHHHH)"), cfg.background),
  127. getConfigListEntry(_("Simple picon"), cfg.simple),
  128. getConfigListEntry(_("Debug info"), cfg.debug),
  129. ]
  130. ConfigListScreen.__init__(self, self.list, session = self.session)
  131. self["key_red"] = Button(_("Cancel"))
  132. self["key_green"] = Button(_("Save"))
  133. self["key_yellow"] = Button("")
  134. self["key_blue"] = Button("")
  135. self["setupActions"] = ActionMap(["SetupActions", "ColorActions"],
  136. {
  137. "red": self.cancel,
  138. "green": self.save,
  139. "save": self.save,
  140. "cancel": self.cancel,
  141. "ok": self.ok,
  142. }, -2)
  143. def getCurrentEntry(self):
  144. return self["config"].getCurrent()[0]
  145. def getCurrentValue(self):
  146. return str(self["config"].getCurrent()[1].getText())
  147. def ok(self):
  148. if self["config"].getCurrent()[1] == config.plugins.getpicons.folder:
  149. folder = config.plugins.getpicons.folder.value
  150. self.session.openWithCallback(self.change_dir, LocationBox,"Select Folder")
  151. else:
  152. self.save()
  153. def change_dir(self, folder, select=None):
  154. if folder:
  155. #print "change_dir to %s"%folder
  156. config.plugins.getpicons.folder.value = folder
  157. def save(self):
  158. print "saving"
  159. self.saveAll()
  160. self.close(True,self.session)
  161. def cancel(self):
  162. #print "cancel"
  163. self.close(False,self.session)
  164. ###########################################################################
  165. def start(session, **kwargs):
  166. print "\n[GetPicons] start\n"
  167. session.open(MainScreen)
  168. #session.openWithCallback(done_config, Config)
  169. def Plugins(**kwargs):
  170. return PluginDescriptor(
  171. name="Get Picons",
  172. description="Download picons from lyngsat.com",
  173. where = [PluginDescriptor.WHERE_PLUGINMENU,PluginDescriptor.WHERE_EXTENSIONSMENU],
  174. icon="plugin.png",
  175. fnc=start)