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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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. cur_directory = os.path.dirname(os.path.realpath(__file__))
  65. name = os.path.join(cur_directory,"get_picons.py")
  66. cmd = "python -u %s -f %s %s"%(name,config.plugins.getpicons.folder.value,param,)
  67. #print "[GetPicons] Execute '%s'"%cmd
  68. #os.chmod(name, 493)
  69. if config.plugins.getpicons.folder.value:
  70. self.session.open(Console, "Download picons from lyngsat.com", cmdlist=[cmd])
  71. def cancel(self):
  72. print "\n[GetPicons] cancel\n"
  73. self.close(None)
  74. def options(self):
  75. print "\n[GetPicons] options\n"
  76. self.session.open(ConfigScreen)
  77. def about(self):
  78. txt = """
  79. GetPicons plugin
  80. Download channels picon files from lyngsat.com for all/selected satellites
  81. Could be run from terminal too:
  82. /usr/script/get_picons.sh -h
  83. Version 0.3
  84. (c) 2013-2016 ivars777@gmail.com"""
  85. self.session.open(MessageBox, txt, MessageBox.TYPE_INFO)
  86. #self.session.openWithCallback(self.callMyMsg, MessageBox, _("Do you want to exit the plugin?"), MessageBox.TYPE_INFO)
  87. return
  88. ##########################################################################
  89. from Components.config import config, ConfigSubsection, \
  90. ConfigYesNo, getConfigListEntry, \
  91. ConfigSelection, ConfigNumber, ConfigDirectory,ConfigText
  92. from Components.ConfigList import ConfigListScreen
  93. from Screens.LocationBox import LocationBox
  94. config.plugins.getpicons = ConfigSubsection()
  95. config.plugins.getpicons.folder = ConfigDirectory(default="/media/hdd")
  96. config.plugins.getpicons.size = ConfigSelection({"400x240":"400x240","220x132":"220x132","100x60":"100x60"}, default="220x132")
  97. config.plugins.getpicons.overwrite = ConfigYesNo(default = True)
  98. class ConfigScreen(ConfigListScreen,Screen):
  99. skin = """
  100. <screen position="center,center" size="560,400" title="Options" >
  101. <ePixmap name="red" position="0,0" zPosition="2" size="140,40" pixmap="skin_default/buttons/red.png" transparent="1" alphatest="on" />
  102. <ePixmap name="green" position="140,0" zPosition="2" size="140,40" pixmap="skin_default/buttons/green.png" transparent="1" alphatest="on" />
  103. <ePixmap name="yellow" position="280,0" zPosition="2" size="140,40" pixmap="skin_default/buttons/yellow.png" transparent="1" alphatest="on" />
  104. <ePixmap name="blue" position="420,0" zPosition="2" size="140,40" pixmap="skin_default/buttons/blue.png" transparent="1" alphatest="on" />
  105. <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" />
  106. <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" />
  107. <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" />
  108. <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" />
  109. <widget name="config" position="10,40" size="540,340" scrollbarMode="showOnDemand" />
  110. </screen>"""
  111. def __init__(self, session, args = 0):
  112. self.session = session
  113. self.setup_title = "Options"
  114. Screen.__init__(self, session)
  115. cfg = config.plugins.getpicons
  116. self.list = [
  117. getConfigListEntry(_("Picons folder"), cfg.folder),
  118. getConfigListEntry(_("Picon size"), cfg.size),
  119. getConfigListEntry(_("Overwrite existing picon files"), cfg.overwrite),
  120. ]
  121. ConfigListScreen.__init__(self, self.list, session = self.session)
  122. self["key_red"] = Button(_("Cancel"))
  123. self["key_green"] = Button(_("Save"))
  124. self["key_yellow"] = Button("")
  125. self["key_blue"] = Button("")
  126. self["setupActions"] = ActionMap(["SetupActions", "ColorActions"],
  127. {
  128. "red": self.cancel,
  129. "green": self.save,
  130. "save": self.save,
  131. "cancel": self.cancel,
  132. "ok": self.ok,
  133. }, -2)
  134. def getCurrentEntry(self):
  135. return self["config"].getCurrent()[0]
  136. def getCurrentValue(self):
  137. return str(self["config"].getCurrent()[1].getText())
  138. def ok(self):
  139. if self["config"].getCurrent()[1] == config.plugins.getpicons.folder:
  140. folder = config.plugins.getpicons.folder.value
  141. self.session.openWithCallback(self.change_dir, LocationBox,"Select Folder")
  142. else:
  143. self.save()
  144. def change_dir(self, folder, select=None):
  145. if folder:
  146. #print "change_dir to %s"%folder
  147. config.plugins.getpicons.folder.value = folder
  148. def save(self):
  149. print "saving"
  150. self.saveAll()
  151. self.close(True,self.session)
  152. def cancel(self):
  153. #print "cancel"
  154. self.close(False,self.session)
  155. ###########################################################################
  156. def start(session, **kwargs):
  157. print "\n[GetPicons] start\n"
  158. session.open(MainScreen)
  159. #session.openWithCallback(done_config, Config)
  160. def Plugins(**kwargs):
  161. return PluginDescriptor(
  162. name="Get Picons",
  163. description="Download picons from lyngsat.com",
  164. where = [PluginDescriptor.WHERE_PLUGINMENU,PluginDescriptor.WHERE_EXTENSIONSMENU],
  165. icon="plugin.png",
  166. fnc=start)