Пример #1
0
    def __init__(self, session):
        Screen.__init__(self, session)
        HelpableScreen.__init__(self)
        self["key_red"] = Button(_("Favorites"))
        self["key_yellow"] = Button("")
        self["key_blue"] = Button(_("Settings"))
        self["currentfolder"] = Label("")
        self["currentfavname"] = Label("")
        self.showiframe = Showiframe()
        self.mvion = False
        self.curfavfolder = -1
        os.system("touch /tmp/bmcmovie")
        self["actions"] = HelpableActionMap(
            self,
            "MC_VideoPlayerActions",
            {
                "ok": (self.KeyOk, "Play selected file"),
                "cancel": (self.Exit, "Exit Video Player"),
                "left": (self.leftUp, "List Top"),
                "right": (self.rightDown, "List Bottom"),
                "up": (self.up, "List up"),
                "down": (self.down, "List down"),
                "menu": (self.KeyMenu, "File / Folder Options"),
                "info": (self.showFileInfo, "Show File Info"),
                "nextBouquet": (self.NextFavFolder, "Next Favorite Folder"),
                "prevBouquet":
                (self.PrevFavFolder, "Previous Favorite Folder"),
                #				"red": (self.FavoriteFolders, "Favorite Folders"),
                "blue": (self.KeySettings, "Settings"),
            },
            -2)

        currDir = config.plugins.mc_vp.lastDir.value
        if not pathExists(currDir):
            currDir = "/"
        self["currentfolder"].setText(str(currDir))
        sort = config.plugins.mc_vp_sortmode.enabled.value
        self.filelist = []
        self["filelist"] = []
        inhibitDirs = [
            "/bin", "/boot", "/dev", "/dev.static", "/etc", "/lib", "/proc",
            "/ram", "/root", "/sbin", "/sys", "/tmp", "/usr", "/var"
        ]
        self.filelist = FileList(
            currDir,
            useServiceRef=True,
            showDirectories=True,
            showFiles=True,
            matchingPattern=
            "(?i)^.*\.(ts|vob|mpg|mpeg|avi|mkv|dat|iso|img|mp4|wmv|flv|divx|mov|ogm|m2ts)",
            additionalExtensions=None,
            sort=sort)
        self["filelist"] = self.filelist
        self["filelist"].show()
 def __init__(self, session):
     global currDir
     Screen.__init__(self, session)
     HelpableScreen.__init__(self)
     self['key_red'] = Button(_('Delete Movie'))
     self['key_yellow'] = Button('')
     self['key_blue'] = Button(_('Settings'))
     self['currentfolder'] = Label('')
     self['currentfavname'] = Label('')
     self.showiframe = Showiframe()
     self.mvion = False
     self.curfavfolder = -1
     os.system('touch /tmp/bmcmovie')
     self['actions'] = HelpableActionMap(self, 'MC_VideoPlayerActions', {'ok': (self.KeyOk, 'Play selected file'),
      'cancel': (self.Exit, 'Exit Video Player'),
      'left': (self.leftUp, 'List Top'),
      'right': (self.rightDown, 'List Bottom'),
      'up': (self.up, 'List up'),
      'down': (self.down, 'List down'),
      'menu': (self.KeyMenu, 'File / Folder Options'),
      'info': (self.showFileInfo, 'Show File Info'),
      'nextBouquet': (self.NextFavFolder, 'Next Favorite Folder'),
      'prevBouquet': (self.PrevFavFolder, 'Previous Favorite Folder'),
      'red': (self.SelDelete, 'Delete Movie'),
      'blue': (self.KeySettings, 'Settings')}, -2)
     currDir = config.plugins.mc_vp.lastDir.value
     if not pathExists(currDir):
         currDir = '/'
     self['currentfolder'].setText(str(currDir))
     sort = config.plugins.mc_vp_sortmode.enabled.value
     self.filelist = []
     self['filelist'] = []
     inhibitDirs = ['/bin',
      '/boot',
      '/dev',
      '/dev.static',
      '/etc',
      '/lib',
      '/proc',
      '/ram',
      '/root',
      '/sbin',
      '/sys',
      '/tmp',
      '/usr',
      '/var']
     self.filelist = FileList(currDir, useServiceRef=True, showDirectories=True, showFiles=True, matchingPattern='(?i)^.*\\.(ts|vob|mpg|mpeg|avi|mkv|dat|iso|img|mp4|wmv|flv|divx|mov|ogm|m2ts)', additionalExtensions=None, sort=sort)
     self['filelist'] = self.filelist
     self['filelist'].show()
     return
Пример #3
0
    def __init__(self, session):
        Screen.__init__(self, session)
        self["actions"] = ActionMap(
            ["WizardActions", "DirectionActions", "ColorActions"], {
                "back": self.exit,
                "blue": self.config,
                "right": self.nextItem,
                "left": self.previousItem
            }, -1)
        self["statustext"] = StaticText()
        self["currenticon"] = WeatherIcon()
        self["CurrentCity"] = StaticText()
        self["currentTemp"] = StaticText()
        self["condition"] = StaticText()
        self["wind_condition"] = StaticText()
        self["humidity"] = StaticText()
        self["observationtime"] = StaticText()
        self["observationpoint"] = StaticText()
        self["feelsliketemp"] = StaticText()
        self.showiframe = Showiframe()
        self.mvion = False

        i = 1
        while i <= 5:
            self["weekday%s" % i] = StaticText()
            self["weekday%s_icon" % i] = WeatherIcon()
            self["weekday%s_temp" % i] = StaticText()
            self["weekday%s_tempname" % i] = StaticText()
            i += 1
        del i

        self.appdir = eEnv.resolve(
            "${libdir}/enigma2/python/Plugins/Extensions/BMediaCenter/icons/70x70/"
        )
        self.weatherPluginEntryIndex = -1
        self.weatherPluginEntryCount = config.plugins.mc_wi.entrycount.value
        if self.weatherPluginEntryCount >= 1:
            self.weatherPluginEntry = config.plugins.mc_wi.Entry[0]
            self.weatherPluginEntryIndex = 1
        else:
            self.weatherPluginEntry = None
        self.language = config.osd.language.value.replace("_", "-")
        if self.language == "en-EN":  # hack
            self.language = "en-US"
        self.webSite = ""
        self.onLayoutFinish.append(self.startRun)
Пример #4
0
    def __init__(self, session):
        Screen.__init__(self, session)
        self['actions'] = ActionMap(
            ['WizardActions', 'DirectionActions', 'ColorActions'], {
                'back': self.exit,
                'blue': self.config,
                'right': self.nextItem,
                'left': self.previousItem
            }, -1)
        self['statustext'] = StaticText()
        self['currenticon'] = WeatherIcon()
        self['CurrentCity'] = StaticText()
        self['currentTemp'] = StaticText()
        self['condition'] = StaticText()
        self['wind_condition'] = StaticText()
        self['humidity'] = StaticText()
        self['observationtime'] = StaticText()
        self['observationpoint'] = StaticText()
        self['feelsliketemp'] = StaticText()
        self.showiframe = Showiframe()
        self.mvion = False
        i = 1
        while i <= 5:
            self['weekday%s' % i] = StaticText()
            self['weekday%s_icon' % i] = WeatherIcon()
            self['weekday%s_temp' % i] = StaticText()
            self['weekday%s_tempname' % i] = StaticText()
            i += 1

        del i
        self.appdir = eEnv.resolve(
            '${libdir}/enigma2/python/Plugins/Extensions/BMediaCenter/icons/70x70/'
        )
        self.weatherPluginEntryIndex = -1
        self.weatherPluginEntryCount = config.plugins.mc_wi.entrycount.value
        if self.weatherPluginEntryCount >= 1:
            self.weatherPluginEntry = config.plugins.mc_wi.Entry[0]
            self.weatherPluginEntryIndex = 1
        else:
            self.weatherPluginEntry = None
        self.language = config.osd.language.value.replace('_', '-')
        if self.language == 'en-EN':
            self.language = 'en-US'
        self.webSite = ''
        self.onLayoutFinish.append(self.startRun)
        return
Пример #5
0
	def __init__(self, session):
		Screen.__init__(self, session)
		self["actions"] = ActionMap(["WizardActions", "DirectionActions", "ColorActions"],
		{
			"back": self.exit,
			"blue": self.config,
			"right": self.nextItem,
			"left": self.previousItem
		}, -1)
		self["statustext"] = StaticText()
		self["currenticon"] = WeatherIcon()
		self["CurrentCity"] = StaticText()
		self["currentTemp"] = StaticText()
		self["condition"] = StaticText()
		self["wind_condition"] = StaticText()
		self["humidity"] = StaticText()
		self["observationtime"] = StaticText()
		self["observationpoint"] = StaticText()
		self["feelsliketemp"] = StaticText()
		self.showiframe = Showiframe()
		self.mvion = False

		i = 1
		while i <= 5:
			self["weekday%s" % i] = StaticText()
			self["weekday%s_icon" %i] = WeatherIcon()
			self["weekday%s_temp" % i] = StaticText()
			self["weekday%s_tempname" % i] = StaticText()
			i += 1
		del i

		self.appdir = eEnv.resolve("${libdir}/enigma2/python/Plugins/Extensions/BMediaCenter/icons/70x70/")
		self.weatherPluginEntryIndex = -1
		self.weatherPluginEntryCount = config.plugins.mc_wi.entrycount.value
		if self.weatherPluginEntryCount >= 1:
			self.weatherPluginEntry = config.plugins.mc_wi.Entry[0]
			self.weatherPluginEntryIndex = 1
		else:
			self.weatherPluginEntry = None
		self.language = config.osd.language.value.replace("_","-")
		if self.language == "en-EN": # hack
			self.language = "en-US"
		self.webSite = ""
		self.onLayoutFinish.append(self.startRun)
	def __init__(self, session):
		Screen.__init__(self, session)
		HelpableScreen.__init__(self)
		self["key_red"] = Button(_("Delete Movie"))
		self["key_yellow"] = Button("")
		self["key_blue"] = Button(_("Settings"))
		self["currentfolder"] = Label("")
		self["currentfavname"] = Label("")
		self.showiframe = Showiframe()
		self.mvion = False
		self.curfavfolder = -1
		os.system("touch /tmp/bmcmovie")
		self["actions"] = HelpableActionMap(self, "MC_VideoPlayerActions", 
			{
				"ok": (self.KeyOk, "Play selected file"),
				"cancel": (self.Exit, "Exit Video Player"),
				"left": (self.leftUp, "List Top"),
				"right": (self.rightDown, "List Bottom"),
				"up": (self.up, "List up"),
				"down": (self.down, "List down"),
				"menu": (self.KeyMenu, "File / Folder Options"),
				"info": (self.showFileInfo, "Show File Info"),
				"nextBouquet": (self.NextFavFolder, "Next Favorite Folder"),
				"prevBouquet": (self.PrevFavFolder, "Previous Favorite Folder"),
				"red": (self.SelDelete, "Delete Movie"),
				"blue": (self.KeySettings, "Settings"),
			}, -2)
                global currDir
		currDir = config.plugins.mc_vp.lastDir.value
		if not pathExists(currDir):
			currDir = "/"
		self["currentfolder"].setText(str(currDir))
		sort = config.plugins.mc_vp_sortmode.enabled.value
		self.filelist = []
		self["filelist"] = []
		inhibitDirs = ["/bin", "/boot", "/dev", "/dev.static", "/etc", "/lib" , "/proc", "/ram", "/root" , "/sbin", "/sys", "/tmp", "/usr", "/var"]
		self.filelist = FileList(currDir, useServiceRef = True, showDirectories = True, showFiles = True, matchingPattern = "(?i)^.*\.(ts|vob|mpg|mpeg|avi|mkv|dat|iso|img|mp4|wmv|flv|divx|mov|ogm|m2ts)", additionalExtensions = None, sort = sort)
		self["filelist"] = self.filelist
		self["filelist"].show()
Пример #7
0
class MC_VideoPlayer(Screen, HelpableScreen):
    def __init__(self, session):
        Screen.__init__(self, session)
        HelpableScreen.__init__(self)
        self["key_red"] = Button(_("Delete Movie"))
        self["key_yellow"] = Button("")
        self["key_blue"] = Button(_("Settings"))
        self["currentfolder"] = Label("")
        self["currentfavname"] = Label("")
        self.showiframe = Showiframe()
        self.mvion = False
        self.curfavfolder = -1
        os.system("touch /tmp/bmcmovie")
        self["actions"] = HelpableActionMap(
            self, "MC_VideoPlayerActions", {
                "ok": (self.KeyOk, "Play selected file"),
                "cancel": (self.Exit, "Exit Video Player"),
                "left": (self.leftUp, "List Top"),
                "right": (self.rightDown, "List Bottom"),
                "up": (self.up, "List up"),
                "down": (self.down, "List down"),
                "menu": (self.KeyMenu, "File / Folder Options"),
                "info": (self.showFileInfo, "Show File Info"),
                "nextBouquet": (self.NextFavFolder, "Next Favorite Folder"),
                "prevBouquet":
                (self.PrevFavFolder, "Previous Favorite Folder"),
                "red": (self.SelDelete, "Delete Movie"),
                "blue": (self.KeySettings, "Settings"),
            }, -2)
        global currDir
        currDir = config.plugins.mc_vp.lastDir.value
        if not pathExists(currDir):
            currDir = "/"
        self["currentfolder"].setText(str(currDir))
        sort = config.plugins.mc_vp_sortmode.enabled.value
        self.filelist = []
        self["filelist"] = []
        inhibitDirs = [
            "/bin", "/boot", "/dev", "/dev.static", "/etc", "/lib", "/proc",
            "/ram", "/root", "/sbin", "/sys", "/tmp", "/usr", "/var"
        ]
        self.filelist = FileList(
            currDir,
            useServiceRef=True,
            showDirectories=True,
            showFiles=True,
            matchingPattern=
            "(?i)^.*\.(ts|vob|mpg|mpeg|avi|mkv|dat|iso|img|mp4|wmv|flv|divx|mov|ogm|m2ts)",
            additionalExtensions=None,
            sort=sort)
        self["filelist"] = self.filelist
        self["filelist"].show()

    def up(self):
        self["filelist"].up()
        if self.mvion == True:
            self.showiframe.finishStillPicture()
        if self["filelist"].canDescent():
            return
        else:
            self.cover()

    def down(self):
        self["filelist"].down()
        if self.mvion == True:
            self.showiframe.finishStillPicture()
        if self["filelist"].canDescent():
            return
        else:
            self.cover()

    def leftUp(self):
        self["filelist"].pageUp()
        if self.mvion == True:
            self.showiframe.finishStillPicture()
        if self["filelist"].canDescent():
            return
        else:
            if self.mvion == True:
                self.showiframe.finishStillPicture()
            self.cover()

    def rightDown(self):
        self["filelist"].pageDown()
        if self.mvion == True:
            self.showiframe.finishStillPicture()
        if self["filelist"].canDescent():
            if self.mvion == True:
                self.showiframe.finishStillPicture()
        else:
            self.cover()

    def NextFavFolder(self):
        return

    def SelDelete(self):
        self.filename = self.filelist.getFilename()
        path = self.filename
        self.session.openWithCallback(
            self.selremove, MessageBox,
            _("Do you really want to delete\n%s ?") % path,
            MessageBox.TYPE_YESNO)

    def selremove(self, ret):
        if ret is True:
            self.filename = self.filelist.getFilename()
            if self.filename.endswith('.ts'):
                path = self.filename.replace('.ts', "")
                for fdelete in glob(path + ".*"):
                    os.remove(fdelete)
            elif self.filename.endswith('.vob'):
                path = self.filename.replace('.vob', "")
                print "path:", path
                for fdelete in glob(path + ".*"):
                    print "fdelete:", fdelete
                    os.remove(fdelete)
            else:
                path = self.filename
                os.remove(path)
            self.updd()

        else:
            pass

    def PrevFavFolder(self):
        return

    def showFileInfo(self):
        if self["filelist"].canDescent():
            return
        else:
            self.session.open(
                MC_VideoInfoView, self["filelist"].getCurrentDirectory() +
                self["filelist"].getFilename(), self["filelist"].getFilename(),
                self["filelist"].getServiceRef())

    def KeyOk(self):
        self.filename = self.filelist.getFilename()
        print self.filename
        try:
            if self.filename.endswith('.img') or self.filename.endswith(
                    '.iso'
            ) or self.filename.endswith(
                    'VIDEO_TS/') and config.plugins.mc_vp.dvd.value == "dvd":
                self.showiframe.finishStillPicture()
                from Screens import DVD
                if self.filename.endswith('VIDEO_TS/'):
                    path = os.path.split(self.filename.rstrip('/'))[0]
                else:
                    path = self.filename
                self.session.open(DVD.DVDPlayer, dvd_filelist=[path])
                return
        except Exception, e:
            print "DVD Player error:", e
        if self.filelist.canDescent():
            self.filelist.descent()
        else:
            self.showiframe.finishStillPicture()
            self.session.open(MoviePlayer,
                              self["filelist"].getServiceRef(),
                              slist=None,
                              lastservice=None)
Пример #8
0
class MC_WeatherInfo(Screen):
    def __init__(self, session):
        Screen.__init__(self, session)
        self["actions"] = ActionMap(
            ["WizardActions", "DirectionActions", "ColorActions"], {
                "back": self.exit,
                "blue": self.config,
                "right": self.nextItem,
                "left": self.previousItem
            }, -1)
        self["statustext"] = StaticText()
        self["currenticon"] = WeatherIcon()
        self["CurrentCity"] = StaticText()
        self["currentTemp"] = StaticText()
        self["condition"] = StaticText()
        self["wind_condition"] = StaticText()
        self["humidity"] = StaticText()
        self["observationtime"] = StaticText()
        self["observationpoint"] = StaticText()
        self["feelsliketemp"] = StaticText()
        self.showiframe = Showiframe()
        self.mvion = False

        i = 1
        while i <= 5:
            self["weekday%s" % i] = StaticText()
            self["weekday%s_icon" % i] = WeatherIcon()
            self["weekday%s_temp" % i] = StaticText()
            self["weekday%s_tempname" % i] = StaticText()
            i += 1
        del i

        self.appdir = eEnv.resolve(
            "${libdir}/enigma2/python/Plugins/Extensions/BMediaCenter/icons/70x70/"
        )
        self.weatherPluginEntryIndex = -1
        self.weatherPluginEntryCount = config.plugins.mc_wi.entrycount.value
        if self.weatherPluginEntryCount >= 1:
            self.weatherPluginEntry = config.plugins.mc_wi.Entry[0]
            self.weatherPluginEntryIndex = 1
        else:
            self.weatherPluginEntry = None
        self.language = config.osd.language.value.replace("_", "-")
        if self.language == "en-EN":  # hack
            self.language = "en-US"
        self.webSite = ""
        self.onLayoutFinish.append(self.startRun)

    def exit(self):
        self.showiframe.finishStillPicture()
        self.close()

    def startRun(self):
        if self.weatherPluginEntry is not None:
            self["statustext"].text = _("Loading information...")
            url = "http://weather.service.msn.com/data.aspx?weadegreetype=%s&culture=%s&wealocations=%s" % (
                self.weatherPluginEntry.degreetype.value, self.language,
                self.weatherPluginEntry.weatherlocationcode.value)
            getPage(url).addCallback(self.xmlCallback).addErrback(self.error)
        else:
            self["statustext"].text = _(
                "No locations defined...\nPress 'Blue' to do that.")

    def mvidown(self, stadt):
        downlink = "http://www.meinestadt.de/" + stadt + "/bilder"
        downname = "/tmp/.stadtindex"
        stadd = stadt
        if fileExists(downname):
            os.system("rm -rf " + downname)
        downloadPage(downlink,
                     downname).addCallback(self.jpgdown,
                                           stadd).addErrback(self.error)

    def jpgdown(self, value, stadd):
        downlink = commands.getoutput(
            "cat /tmp/.stadtindex | grep \"background-image:url('http://mytown.de/\" | cut -d \"'\" -f2"
        )
        stadt = stadd
        downname = "/tmp/" + stadt + ".jpg"
        downloadPage(downlink,
                     downname).addCallback(self.makemvi,
                                           stadt).addErrback(self.error)

    def makemvi(self, value, stadt):
        mviname = "/tmp/" + stadt + ".m1v"
        if fileExists(mviname) is False:
            import subprocess
            if fileExists("/sbin/ffmpeg"):
                ffmpeg = "/sbin/ffmpeg"
            else:
                ffmpeg = "/usr/bin/ffmpeg"
            if fileExists("/sbin/ffmpeg") or fileExists("/sbin/ffmpeg"):
                cmd = [
                    ffmpeg, "-f", "image2", "-i", "/tmp/" + stadt + ".jpg",
                    mviname
                ]
                subprocess.Popen(cmd).wait()
            if fileExists(mviname):
                self.showiframe.showStillpicture(mviname)

    def nextItem(self):
        if self.weatherPluginEntryCount != 0:
            if self.weatherPluginEntryIndex < self.weatherPluginEntryCount:
                self.weatherPluginEntryIndex = self.weatherPluginEntryIndex + 1
            else:
                self.weatherPluginEntryIndex = 1
            self.setItem()

    def previousItem(self):
        if self.weatherPluginEntryCount != 0:
            if self.weatherPluginEntryIndex >= 2:
                self.weatherPluginEntryIndex = self.weatherPluginEntryIndex - 1
            else:
                self.weatherPluginEntryIndex = self.weatherPluginEntryCount
            self.setItem()

    def setItem(self):
        self.weatherPluginEntry = config.plugins.mc_wi.Entry[
            self.weatherPluginEntryIndex - 1]
        self.clearFields()
        self.startRun()

    def clearFields(self):
        self["CurrentCity"].text = ""
        self["currentTemp"].text = ""
        self["condition"].text = ""
        self["wind_condition"].text = ""
        self["humidity"].text = ""
        self["observationtime"].text = ""
        self["observationpoint"].text = ""
        self["feelsliketemp"].text = ""
        self["currenticon"].hide()
        self.webSite = ""
        i = 1
        while i <= 5:
            self["weekday%s" % i].text = ""
            self["weekday%s_icon" % i].hide()
            self["weekday%s_temp" % i].text = ""
            self["weekday%s_tempname" % i].text = ""
            i += 1

    def errorIconDownload(self, error=None, item=None):
        item.error = True

    def finishedIconDownload(self, result, item):
        if not item.error:
            self.showIcon(item.index, item.filename)

    def showIcon(self, index, filename):
        if index <> -1:
            self["weekday%s_icon" % index].updateIcon(filename)
            self["weekday%s_icon" % index].show()
        else:
            self["currenticon"].updateIcon(filename)
            self["currenticon"].show()

    def xmlCallback(self, xmlstring):
        self["statustext"].text = ""
        IconDownloadList = []
        root = cet_fromstring(xmlstring)
        index = 0
        degreetype = "C"
        imagerelativeurl = ""
        errormessage = ""
        for childs in root:
            if childs.tag == "weather":

                errormessage = childs.attrib.get("errormessage")
                if errormessage:
                    self["statustext"].text = errormessage.encode(
                        "utf-8", 'ignore')
                    break
                self[
                    "CurrentCity"].text = self.weatherPluginEntry.city.value  #childs.attrib.get("weatherlocationname").encode("utf-8", 'ignore')
                degreetype = childs.attrib.get("degreetype").encode(
                    "utf-8", 'ignore')
                imagerelativeurl = "%slaw/" % childs.attrib.get(
                    "imagerelativeurl").encode("utf-8", 'ignore')
                self.webSite = childs.attrib.get("url").encode(
                    "utf-8", 'ignore')
            for items in childs:
                if items.tag == "current":
                    self["currentTemp"].text = "%s°%s" % (items.attrib.get(
                        "temperature").encode("utf-8", 'ignore'), degreetype)
                    self["condition"].text = items.attrib.get(
                        "skytext").encode("utf-8", 'ignore')
                    self["humidity"].text = _(
                        "Humidity: %s %%") % items.attrib.get(
                            "humidity").encode("utf-8", 'ignore')
                    self["wind_condition"].text = items.attrib.get(
                        "winddisplay").encode("utf-8", 'ignore')
                    c = time.strptime(
                        items.attrib.get("observationtime").encode(
                            "utf-8", 'ignore'), "%H:%M:%S")
                    self["observationtime"].text = _(
                        "Observation time: %s") % time.strftime("%H:%M", c)
                    self["observationpoint"].text = _(
                        "Observation point: %s") % items.attrib.get(
                            "observationpoint").encode("utf-8", 'ignore')
                    self["feelsliketemp"].text = _(
                        "Feels like %s") % items.attrib.get(
                            "feelslike").encode("utf-8",
                                                'ignore') + "°" + degreetype
                    skycode = "%s.gif" % items.attrib.get("skycode").encode(
                        "utf-8", 'ignore')
                    filename = path + "icons/" + skycode
                    skycodepng = "%s.png" % items.attrib.get("skycode").encode(
                        "utf-8", 'ignore')
                    filenamepng = path + "icons/" + skycodepng
                    if not pathExists(filenamepng):
                        if not pathExists(filename):
                            url = "%s%s" % (imagerelativeurl, skycode)
                            IconDownloadList.append(
                                WeatherIconItem(url=url,
                                                filename=filename,
                                                index=-1))
                    else:
                        self.showIcon(-1, filenamepng)
                elif items.tag == "forecast" and index <= 4:
                    index += 1
                    c = time.strptime(
                        items.attrib.get("date").encode("utf-8", 'ignore'),
                        "%Y-%m-%d")
                    self["weekday%s" % index].text = "%s\n%s" % (
                        items.attrib.get("day").encode(
                            "utf-8", 'ignore'), time.strftime("%d. %b", c))
                    lowTemp = items.attrib.get("low").encode("utf-8", 'ignore')
                    highTemp = items.attrib.get("high").encode(
                        "utf-8", 'ignore')
                    self["weekday%s_temp" %
                         index].text = "Min: %s°%s \n Max: %s°%s" % (
                             lowTemp, degreetype, highTemp, degreetype)
                    self["weekday%s_tempname" %
                         index].text = "%s" % (items.attrib.get(
                             "skytextday").encode("utf-8", 'ignore'))
                    skycodeday = "%s.gif" % items.attrib.get(
                        "skycodeday").encode("utf-8", 'ignore')
                    skycodedaypng = "%s.png" % items.attrib.get(
                        "skycodeday").encode("utf-8", 'ignore')
                    filename = self.appdir + skycodeday
                    filenamepng = self.appdir + skycodedaypng
                    if not pathExists(filenamepng):
                        if not pathExists(filename):
                            url = "%s%s" % (imagerelativeurl, skycodeday)
                            IconDownloadList.append(
                                WeatherIconItem(url=url,
                                                filename=filename,
                                                index=index))
                    else:
                        self.showIcon(index, filenamepng)
        if len(IconDownloadList) != 0:
            ds = defer.DeferredSemaphore(tokens=len(IconDownloadList))
            downloads = [
                ds.run(download,
                       item).addErrback(self.errorIconDownload,
                                        item).addCallback(
                                            self.finishedIconDownload, item)
                for item in IconDownloadList
            ]
            finished = defer.DeferredList(downloads).addErrback(self.error)
        stadt = config.plugins.mc_wi.Entry[self.weatherPluginEntryIndex -
                                           1].city.value
        stadt = stadt.split(",")[0]
        stadt = stadt.replace('Ä', 'Ae')
        stadt = stadt.replace('ä', 'ae')
        stadt = stadt.replace('Ö', 'Oe')
        stadt = stadt.replace('ö', 'oe')
        stadt = stadt.replace('Ü', 'Ue')
        stadt = stadt.replace('ü', 'ue')
        stadt = stadt.replace('ß', 'ss')
        stadt = stadt.lower()
        if self.mvion == True:
            self.showiframe.finishStillPicture()
        bild = "/tmp/" + stadt + ".m1v"
        if fileExists(bild):
            self.showiframe.showStillpicture(bild)
            self.mvion = True
        else:
            self.mvidown(stadt)

    def config(self):
        self.session.openWithCallback(self.setupFinished, WeatherSetup)

    def setupFinished(self, index, entry=None):
        self.weatherPluginEntryCount = config.plugins.mc_wi.entrycount.value
        if self.weatherPluginEntryCount >= 1:
            if entry is not None:
                self.weatherPluginEntry = entry
                self.weatherPluginEntryIndex = index + 1
            if self.weatherPluginEntry is None:
                self.weatherPluginEntry = config.plugins.mc_wi.Entry[0]
                self.weatherPluginEntryIndex = 1
        else:
            self.weatherPluginEntry = None
            self.weatherPluginEntryIndex = -1
        self.clearFields()
        self.startRun()

    def error(self, error=None):
        self.mvion = False
        self.showiframe.showStillpicture("/usr/share/enigma2/black.mvi")
        if error is not None:
            self.clearFields()
            self["statustext"].text = str(error.getErrorMessage())
class MC_VideoPlayer(Screen, HelpableScreen):
	def __init__(self, session):
		Screen.__init__(self, session)
		HelpableScreen.__init__(self)
		self["key_red"] = Button(_("Delete Movie"))
		self["key_yellow"] = Button("")
		self["key_blue"] = Button(_("Settings"))
		self["currentfolder"] = Label("")
		self["currentfavname"] = Label("")
		self.showiframe = Showiframe()
		self.mvion = False
		self.curfavfolder = -1
		os.system("touch /tmp/bmcmovie")
		self["actions"] = HelpableActionMap(self, "MC_VideoPlayerActions", 
			{
				"ok": (self.KeyOk, "Play selected file"),
				"cancel": (self.Exit, "Exit Video Player"),
				"left": (self.leftUp, "List Top"),
				"right": (self.rightDown, "List Bottom"),
				"up": (self.up, "List up"),
				"down": (self.down, "List down"),
				"menu": (self.KeyMenu, "File / Folder Options"),
				"info": (self.showFileInfo, "Show File Info"),
				"nextBouquet": (self.NextFavFolder, "Next Favorite Folder"),
				"prevBouquet": (self.PrevFavFolder, "Previous Favorite Folder"),
				"red": (self.SelDelete, "Delete Movie"),
				"blue": (self.KeySettings, "Settings"),
			}, -2)
                global currDir
		currDir = config.plugins.mc_vp.lastDir.value
		if not pathExists(currDir):
			currDir = "/"
		self["currentfolder"].setText(str(currDir))
		sort = config.plugins.mc_vp_sortmode.enabled.value
		self.filelist = []
		self["filelist"] = []
		inhibitDirs = ["/bin", "/boot", "/dev", "/dev.static", "/etc", "/lib" , "/proc", "/ram", "/root" , "/sbin", "/sys", "/tmp", "/usr", "/var"]
		self.filelist = FileList(currDir, useServiceRef = True, showDirectories = True, showFiles = True, matchingPattern = "(?i)^.*\.(ts|vob|mpg|mpeg|avi|mkv|dat|iso|img|mp4|wmv|flv|divx|mov|ogm|m2ts)", additionalExtensions = None, sort = sort)
		self["filelist"] = self.filelist
		self["filelist"].show()
	def up(self):
		self["filelist"].up()
		if self.mvion == True:
			self.showiframe.finishStillPicture()
		if self["filelist"].canDescent():
			return
		else:
			self.cover()
	def down(self):
		self["filelist"].down()
		if self.mvion == True:
			self.showiframe.finishStillPicture()
		if self["filelist"].canDescent():
			return
		else:
			self.cover()
	def leftUp(self):
		self["filelist"].pageUp()
		if self.mvion == True:
			self.showiframe.finishStillPicture()
		if self["filelist"].canDescent():
			return
		else:
			if self.mvion == True:
				self.showiframe.finishStillPicture()
			self.cover()
	def rightDown(self):
		self["filelist"].pageDown()
		if self.mvion == True:
			self.showiframe.finishStillPicture()
		if self["filelist"].canDescent():
			if self.mvion == True:
				self.showiframe.finishStillPicture()
		else:
			self.cover()
	def NextFavFolder(self):
		return
		
	def SelDelete(self):
		self.filename = self.filelist.getFilename()
		path = self.filename
		self.session.openWithCallback(self.selremove, MessageBox, _("Do you really want to delete\n%s ?") % path, MessageBox.TYPE_YESNO)

	def selremove(self, ret):
		if ret is True:
		        self.filename = self.filelist.getFilename()
		        if self.filename.endswith('.ts'):
		                path = self.filename.replace('.ts', "")
		                for fdelete in glob(path + ".*"):
		                        os.remove (fdelete)
		        elif self.filename.endswith('.vob'):
		                path = self.filename.replace('.vob', "")
		                print "path:", path
		                for fdelete in glob(path + ".*"):
		                        print "fdelete:", fdelete
		                        os.remove (fdelete)	                        
		        else:
                                path = self.filename
			        os.remove(path)
                        self.updd()
                        
		else:
			pass
		
	def PrevFavFolder(self):
		return
	def showFileInfo(self):
		if self["filelist"].canDescent():
			return
		else:
			self.session.open(MC_VideoInfoView, self["filelist"].getCurrentDirectory() + self["filelist"].getFilename() , self["filelist"].getFilename(), self["filelist"].getServiceRef())
	def KeyOk(self):
		self.filename = self.filelist.getFilename()
		print self.filename
		try:
			if self.filename.endswith('.img') or self.filename.endswith('.iso') or self.filename.endswith('VIDEO_TS/') and config.plugins.mc_vp.dvd.value == "dvd":
				self.showiframe.finishStillPicture()
				from Screens import DVD
				if self.filename.endswith('VIDEO_TS/'):
					path = os.path.split(self.filename.rstrip('/'))[0]
				else:
					path = self.filename
				self.session.open(DVD.DVDPlayer, dvd_filelist=[path])
				return
		except Exception, e:
			print "DVD Player error:", e
		if self.filelist.canDescent():
			self.filelist.descent()
		else:
			self.showiframe.finishStillPicture()
			self.session.open(MoviePlayer, self["filelist"].getServiceRef(), slist = None, lastservice = None)
Пример #10
0
class MC_VideoPlayer(Screen, HelpableScreen):
	def __init__(self, session):
		Screen.__init__(self, session)
		HelpableScreen.__init__(self)
		self["key_red"] = Button(_("Favorites"))
		self["key_yellow"] = Button("")
		self["key_blue"] = Button(_("Settings"))
		self["currentfolder"] = Label("")
		self["currentfavname"] = Label("")
		self.showiframe = Showiframe()
		self.mvion = False
		self.curfavfolder = -1
		os.system("touch /tmp/bmcmovie")
		self["actions"] = HelpableActionMap(self, "MC_VideoPlayerActions",
			{
				"ok": (self.KeyOk, "Play selected file"),
				"cancel": (self.Exit, "Exit Video Player"),
				"left": (self.leftUp, "List Top"),
				"right": (self.rightDown, "List Bottom"),
				"up": (self.up, "List up"),
				"down": (self.down, "List down"),
				"menu": (self.KeyMenu, "File / Folder Options"),
				"info": (self.showFileInfo, "Show File Info"),
				"nextBouquet": (self.NextFavFolder, "Next Favorite Folder"),
				"prevBouquet": (self.PrevFavFolder, "Previous Favorite Folder"),
#				"red": (self.FavoriteFolders, "Favorite Folders"),
				"blue": (self.KeySettings, "Settings"),
			}, -2)

		currDir = config.plugins.mc_vp.lastDir.value
		if not pathExists(currDir):
			currDir = "/"
		self["currentfolder"].setText(str(currDir))
		sort = config.plugins.mc_vp_sortmode.enabled.value
		self.filelist = []
		self["filelist"] = []
		inhibitDirs = ["/bin", "/boot", "/dev", "/dev.static", "/etc", "/lib", "/proc", "/ram", "/root", "/sbin", "/sys", "/tmp", "/usr", "/var"]
		self.filelist = FileList(currDir, useServiceRef=True, showDirectories=True, showFiles=True, matchingPattern="(?i)^.*\.(ts|vob|mpg|mpeg|avi|mkv|dat|iso|img|mp4|wmv|flv|divx|mov|ogm|m2ts)", additionalExtensions=None, sort=sort)
		self["filelist"] = self.filelist
		self["filelist"].show()

	def up(self):
		self["filelist"].up()
		if self.mvion == True:
			self.showiframe.finishStillPicture()
		if self["filelist"].canDescent():
			return
		else:
			self.cover()

	def down(self):
		self["filelist"].down()
		if self.mvion == True:
			self.showiframe.finishStillPicture()
		if self["filelist"].canDescent():
			return
		else:
			self.cover()

	def leftUp(self):
		self["filelist"].pageUp()
		if self.mvion == True:
			self.showiframe.finishStillPicture()
		if self["filelist"].canDescent():
			return
		else:
			if self.mvion == True:
				self.showiframe.finishStillPicture()
			self.cover()

	def rightDown(self):
		self["filelist"].pageDown()
		if self.mvion == True:
			self.showiframe.finishStillPicture()
		if self["filelist"].canDescent():
			if self.mvion == True:
				self.showiframe.finishStillPicture()
		else:
			self.cover()

	def NextFavFolder(self):
		return

	def PrevFavFolder(self):
		return

	def showFileInfo(self):
		if self["filelist"].canDescent():
			return
		else:
			self.session.open(MC_VideoInfoView, self["filelist"].getCurrentDirectory() + self["filelist"].getFilename(), self["filelist"].getFilename(), self["filelist"].getServiceRef())

	def KeyOk(self):
		self.filename = self.filelist.getFilename()
		print(self.filename)
		try:
			if self.filename.endswith('.img') or self.filename.endswith('.iso') or self.filename.endswith('VIDEO_TS/') and config.plugins.mc_vp.dvd.value == "dvd":
				self.showiframe.finishStillPicture()
				from Screens import DVD
				if self.filename.endswith('VIDEO_TS/'):
					path = os.path.split(self.filename.rstrip('/'))[0]
				else:
					path = self.filename
				self.session.open(DVD.DVDPlayer, dvd_filelist=[path])
				return
		except Exception as e:
			print("DVD Player error:", e)
		if self.filelist.canDescent():
			self.filelist.descent()
		else:
			self.showiframe.finishStillPicture()
			self.session.open(MoviePlayer, self["filelist"].getServiceRef(), slist=None, lastservice=None)

	def cover(self):
		filename = self["filelist"].getName()
		short = shortname(filename)
		newshort = short.lower()
		newshort = newshort.replace(" ", "")
		movienameserie = re.sub("e[0-9]{2}", "", newshort.lower())
		covername = "/hdd/bmcover/" + str(movienameserie) + "/backcover.mvi"
		if fileExists(covername):
			self.showiframe.showStillpicture(covername)
			self.mvion = True
		else:
			if self.mvion == True:
				self.showiframe.showStillpicture("/usr/share/enigma2/black.mvi")
				self.mvion = False

	def KeyMenu(self):
#		if self["filelist"].canDescent():
#			if self.filelist.getCurrent()[0][1]:
#				self.currentDirectory = self.filelist.getCurrent()[0][0]
#				if self.currentDirectory is not None:
#					foldername = self.currentDirectory.split('/')
#					foldername = foldername[-2]
#					self.session.open(MC_FolderOptions,self.currentDirectory, foldername)
		return

	def updd(self):
		sort = config.plugins.mc_vp_sortmode.enabled.value
		self.filelist.refresh(sort)

	def KeySettings(self):
		self.session.openWithCallback(self.updd, VideoPlayerSettings)

	def Exit(self):
		if self.filelist.getCurrentDirectory() is None:
			config.plugins.mc_vp.lastDir.value = "/"
		else:
			config.plugins.mc_vp.lastDir.value = self.filelist.getCurrentDirectory()
		config.plugins.mc_vp.save()
		try:
			os.remove("/tmp/bmcmovie")
		except:
			pass
		self.showiframe.finishStillPicture()
		self.close()
class MC_VideoPlayer(Screen, HelpableScreen):

    def __init__(self, session):
        global currDir
        Screen.__init__(self, session)
        HelpableScreen.__init__(self)
        self['key_red'] = Button(_('Delete Movie'))
        self['key_yellow'] = Button('')
        self['key_blue'] = Button(_('Settings'))
        self['currentfolder'] = Label('')
        self['currentfavname'] = Label('')
        self.showiframe = Showiframe()
        self.mvion = False
        self.curfavfolder = -1
        os.system('touch /tmp/bmcmovie')
        self['actions'] = HelpableActionMap(self, 'MC_VideoPlayerActions', {'ok': (self.KeyOk, 'Play selected file'),
         'cancel': (self.Exit, 'Exit Video Player'),
         'left': (self.leftUp, 'List Top'),
         'right': (self.rightDown, 'List Bottom'),
         'up': (self.up, 'List up'),
         'down': (self.down, 'List down'),
         'menu': (self.KeyMenu, 'File / Folder Options'),
         'info': (self.showFileInfo, 'Show File Info'),
         'nextBouquet': (self.NextFavFolder, 'Next Favorite Folder'),
         'prevBouquet': (self.PrevFavFolder, 'Previous Favorite Folder'),
         'red': (self.SelDelete, 'Delete Movie'),
         'blue': (self.KeySettings, 'Settings')}, -2)
        currDir = config.plugins.mc_vp.lastDir.value
        if not pathExists(currDir):
            currDir = '/'
        self['currentfolder'].setText(str(currDir))
        sort = config.plugins.mc_vp_sortmode.enabled.value
        self.filelist = []
        self['filelist'] = []
        inhibitDirs = ['/bin',
         '/boot',
         '/dev',
         '/dev.static',
         '/etc',
         '/lib',
         '/proc',
         '/ram',
         '/root',
         '/sbin',
         '/sys',
         '/tmp',
         '/usr',
         '/var']
        self.filelist = FileList(currDir, useServiceRef=True, showDirectories=True, showFiles=True, matchingPattern='(?i)^.*\\.(ts|vob|mpg|mpeg|avi|mkv|dat|iso|img|mp4|wmv|flv|divx|mov|ogm|m2ts)', additionalExtensions=None, sort=sort)
        self['filelist'] = self.filelist
        self['filelist'].show()
        return

    def up(self):
        self['filelist'].up()
        if self.mvion == True:
            self.showiframe.finishStillPicture()
        if self['filelist'].canDescent():
            return
        self.cover()

    def down(self):
        self['filelist'].down()
        if self.mvion == True:
            self.showiframe.finishStillPicture()
        if self['filelist'].canDescent():
            return
        self.cover()

    def leftUp(self):
        self['filelist'].pageUp()
        if self.mvion == True:
            self.showiframe.finishStillPicture()
        if self['filelist'].canDescent():
            return
        if self.mvion == True:
            self.showiframe.finishStillPicture()
        self.cover()

    def rightDown(self):
        self['filelist'].pageDown()
        if self.mvion == True:
            self.showiframe.finishStillPicture()
        if self['filelist'].canDescent():
            if self.mvion == True:
                self.showiframe.finishStillPicture()
        else:
            self.cover()

    def NextFavFolder(self):
        pass

    def SelDelete(self):
        self.filename = self.filelist.getFilename()
        path = self.filename
        self.session.openWithCallback(self.selremove, MessageBox, _('Do you really want to delete\n%s ?') % path, MessageBox.TYPE_YESNO)

    def selremove(self, ret):
        if ret is True:
            self.filename = self.filelist.getFilename()
            if self.filename.endswith('.ts'):
                path = self.filename.replace('.ts', '')
                for fdelete in glob(path + '.*'):
                    os.remove(fdelete)

            elif self.filename.endswith('.vob'):
                path = self.filename.replace('.vob', '')
                print 'path:', path
                for fdelete in glob(path + '.*'):
                    print 'fdelete:', fdelete
                    os.remove(fdelete)

            else:
                path = self.filename
                os.remove(path)
            self.updd()

    def PrevFavFolder(self):
        pass

    def showFileInfo(self):
        if self['filelist'].canDescent():
            return
        self.session.open(MC_VideoInfoView, self['filelist'].getCurrentDirectory() + self['filelist'].getFilename(), self['filelist'].getFilename(), self['filelist'].getServiceRef())

    def KeyOk(self):
        self.filename = self.filelist.getFilename()
        print self.filename
        try:
            if self.filename.endswith('.img') or self.filename.endswith('.iso') or self.filename.endswith('VIDEO_TS/') and config.plugins.mc_vp.dvd.value == 'dvd':
                self.showiframe.finishStillPicture()
                from Screens import DVD
                if self.filename.endswith('VIDEO_TS/'):
                    path = os.path.split(self.filename.rstrip('/'))[0]
                else:
                    path = self.filename
                self.session.open(DVD.DVDPlayer, dvd_filelist=[path])
                return
        except Exception as e:
            print 'DVD Player error:', e

        if self.filelist.canDescent():
            self.filelist.descent()
        else:
            self.showiframe.finishStillPicture()
            self.session.open(MoviePlayer, self['filelist'].getServiceRef(), slist=None, lastservice=None)
        return

    def cover(self):
        filename = self['filelist'].getName()
        short = shortname(filename)
        newshort = short.lower()
        newshort = newshort.replace(' ', '')
        movienameserie = re.sub('e[0-9]{2}', '', newshort.lower())
        covername = '/hdd/bmcover/' + str(movienameserie) + '/backcover.mvi'
        if fileExists(covername):
            self.showiframe.showStillpicture(covername)
            self.mvion = True
        elif self.mvion == True:
            self.showiframe.showStillpicture('/usr/share/enigma2/black.mvi')
            self.mvion = False

    def KeyMenu(self):
        pass

    def updd(self):
        sort = config.plugins.mc_vp_sortmode.enabled.value
        self.filelist.refresh(sort)

    def KeySettings(self):
        self.session.openWithCallback(self.updd, VideoPlayerSettings)

    def Exit(self):
        if self.filelist.getCurrentDirectory() is None:
            config.plugins.mc_vp.lastDir.value = '/'
        else:
            config.plugins.mc_vp.lastDir.value = self.filelist.getCurrentDirectory()
        config.plugins.mc_vp.save()
        try:
            os.remove('/tmp/bmcmovie')
        except:
            pass

        self.showiframe.finishStillPicture()
        self.close()
        return
Пример #12
0
class MC_WeatherInfo(Screen):
	def __init__(self, session):
		Screen.__init__(self, session)
		self["actions"] = ActionMap(["WizardActions", "DirectionActions", "ColorActions"],
		{
			"back": self.exit,
			"blue": self.config,
			"right": self.nextItem,
			"left": self.previousItem
		}, -1)
		self["statustext"] = StaticText()
		self["currenticon"] = WeatherIcon()
		self["CurrentCity"] = StaticText()
		self["currentTemp"] = StaticText()
		self["condition"] = StaticText()
		self["wind_condition"] = StaticText()
		self["humidity"] = StaticText()
		self["observationtime"] = StaticText()
		self["observationpoint"] = StaticText()
		self["feelsliketemp"] = StaticText()
		self.showiframe = Showiframe()
		self.mvion = False

		i = 1
		while i <= 5:
			self["weekday%s" % i] = StaticText()
			self["weekday%s_icon" %i] = WeatherIcon()
			self["weekday%s_temp" % i] = StaticText()
			self["weekday%s_tempname" % i] = StaticText()
			i += 1
		del i

		self.appdir = eEnv.resolve("${libdir}/enigma2/python/Plugins/Extensions/BMediaCenter/icons/70x70/")
		self.weatherPluginEntryIndex = -1
		self.weatherPluginEntryCount = config.plugins.mc_wi.entrycount.value
		if self.weatherPluginEntryCount >= 1:
			self.weatherPluginEntry = config.plugins.mc_wi.Entry[0]
			self.weatherPluginEntryIndex = 1
		else:
			self.weatherPluginEntry = None
		self.language = config.osd.language.value.replace("_","-")
		if self.language == "en-EN": # hack
			self.language = "en-US"
		self.webSite = ""
		self.onLayoutFinish.append(self.startRun)

	def exit(self):
		self.showiframe.finishStillPicture()
		self.close()
	def startRun(self):
		if self.weatherPluginEntry is not None:
			self["statustext"].text = _("Loading information...")
			url = "http://weather.service.msn.com/data.aspx?src=vista&weadegreetype=%s&culture=%s&wealocations=%s" % (self.weatherPluginEntry.degreetype.value, self.language, self.weatherPluginEntry.weatherlocationcode.value)
			getPage(url).addCallback(self.xmlCallback).addErrback(self.error)
		else:
			self["statustext"].text = _("No locations defined...Press 'Blue' to do that.")
	def mvidown(self, stadt):
		downlink = "http://www.meinestadt.de/"+ stadt +"/bilder"
		downname = "/tmp/.stadtindex"
		stadd = stadt
		if fileExists(downname):
			os.system("rm -rf "+ downname)
		downloadPage(downlink, downname).addCallback(self.jpgdown, stadd).addErrback(self.error)
	def jpgdown(self, value, stadd):
		downlink = commands.getoutput("cat /tmp/.stadtindex | grep \"background-image:url('http://mytown.de/\" | cut -d \"'\" -f2")
		stadt = stadd
		downname = "/tmp/"+ stadt +".jpg"
		downloadPage(downlink, downname).addCallback(self.makemvi, stadt).addErrback(self.error)
	def makemvi(self, value, stadt):
		mviname = "/tmp/"+ stadt +".m1v"
		if fileExists(mviname) is False:
			import subprocess
			if fileExists("/sbin/ffmpeg"):
				ffmpeg="/sbin/ffmpeg"
			else:
				ffmpeg="/usr/bin/ffmpeg"
			if fileExists("/sbin/ffmpeg") or fileExists("/sbin/ffmpeg"):	
				cmd = [ffmpeg, "-f", "image2", "-i", "/tmp/"+ stadt +".jpg", mviname]
				subprocess.Popen(cmd).wait()
			if fileExists(mviname):
				self.showiframe.showStillpicture(mviname)
	def nextItem(self):
		if self.weatherPluginEntryCount != 0:
			if self.weatherPluginEntryIndex < self.weatherPluginEntryCount:
				self.weatherPluginEntryIndex = self.weatherPluginEntryIndex + 1
			else:
				self.weatherPluginEntryIndex = 1
			self.setItem()
	def previousItem(self):
		if self.weatherPluginEntryCount != 0:
			if self.weatherPluginEntryIndex >= 2:
				self.weatherPluginEntryIndex = self.weatherPluginEntryIndex - 1
			else:
				self.weatherPluginEntryIndex = self.weatherPluginEntryCount
			self.setItem()
	def setItem(self):
		self.weatherPluginEntry = config.plugins.mc_wi.Entry[self.weatherPluginEntryIndex-1]
		self.clearFields()
		self.startRun()
	def clearFields(self):
		self["CurrentCity"].text = ""
		self["currentTemp"].text = ""
		self["condition"].text = ""
		self["wind_condition"].text = ""
		self["humidity"].text = ""
		self["observationtime"].text = ""
		self["observationpoint"].text = ""
		self["feelsliketemp"].text = ""
		self["currenticon"].hide()
		self.webSite = ""
		i = 1
		while i <= 5:
			self["weekday%s" % i].text = ""
			self["weekday%s_icon" %i].hide()
			self["weekday%s_temp" % i].text = ""
			self["weekday%s_tempname" % i].text = ""
			i += 1

	def errorIconDownload(self, error = None, item = None):
		item.error = True

	def finishedIconDownload(self, result, item):
		if not item.error:
			self.showIcon(item.index,item.filename)

	def showIcon(self,index, filename):
		if index <> -1:
			self["weekday%s_icon" % index].updateIcon(filename)
			self["weekday%s_icon" % index].show()
		else:
			self["currenticon"].updateIcon(filename)
			self["currenticon"].show()

	def xmlCallback(self, xmlstring):
		self["statustext"].text = ""
		IconDownloadList = []
		root = cet_fromstring(xmlstring)
		index = 0
		degreetype = "C"
		imagerelativeurl = ""
		errormessage = ""
		for childs in root:
			if childs.tag == "weather":
				
				errormessage = childs.attrib.get("errormessage")
				if errormessage:
					self["statustext"].text = errormessage.encode("utf-8", 'ignore')
					break
				self["CurrentCity"].text = self.weatherPluginEntry.city.value #childs.attrib.get("weatherlocationname").encode("utf-8", 'ignore')
				degreetype = childs.attrib.get("degreetype").encode("utf-8", 'ignore')
				imagerelativeurl = "%slaw/" % childs.attrib.get("imagerelativeurl").encode("utf-8", 'ignore')
				self.webSite = childs.attrib.get("url").encode("utf-8", 'ignore')
			for items in childs:
				if items.tag == "current":
					self["currentTemp"].text = "%s°%s" % (items.attrib.get("temperature").encode("utf-8", 'ignore') , degreetype)
					self["condition"].text = items.attrib.get("skytext").encode("utf-8", 'ignore')
					self["humidity"].text = _("Humidity: %s %%") % items.attrib.get("humidity").encode("utf-8", 'ignore')
					self["wind_condition"].text = items.attrib.get("winddisplay").encode("utf-8", 'ignore')
					c =  time.strptime(items.attrib.get("observationtime").encode("utf-8", 'ignore'), "%H:%M:%S")
					self["observationtime"].text = _("Observation time: %s") %  time.strftime("%H:%M",c)
					self["observationpoint"].text = _("Observation point: %s") % items.attrib.get("observationpoint").encode("utf-8", 'ignore')
					self["feelsliketemp"].text = _("Feels like %s") % items.attrib.get("feelslike").encode("utf-8", 'ignore') + "°" +  degreetype
					skycode = "%s.gif" % items.attrib.get("skycode").encode("utf-8", 'ignore')
					filename = path +"icons/" + skycode
					skycodepng = "%s.png" % items.attrib.get("skycode").encode("utf-8", 'ignore')
					filenamepng = path +"icons/" + skycodepng
					if not pathExists(filenamepng):
						if not pathExists(filename):
							url = "%s%s" % (imagerelativeurl, skycode)
							IconDownloadList.append(WeatherIconItem(url = url,filename = filename, index = -1))
					else:
						self.showIcon(-1,filenamepng)
				elif items.tag == "forecast" and index <= 4:
					index +=1
					c = time.strptime(items.attrib.get("date").encode("utf-8", 'ignore'),"%Y-%m-%d")
					self["weekday%s" % index].text = "%s\n%s" % (items.attrib.get("day").encode("utf-8", 'ignore'), time.strftime("%d. %b",c))
					lowTemp = items.attrib.get("low").encode("utf-8", 'ignore')
					highTemp = items.attrib.get("high").encode("utf-8", 'ignore')
					self["weekday%s_temp" % index].text = "Min: %s°%s \n Max: %s°%s" % (lowTemp, degreetype, highTemp, degreetype)
					self["weekday%s_tempname" % index].text = "%s" % (items.attrib.get("skytextday").encode("utf-8", 'ignore'))
					skycodeday = "%s.gif" % items.attrib.get("skycodeday").encode("utf-8", 'ignore')
					skycodedaypng = "%s.png" % items.attrib.get("skycodeday").encode("utf-8", 'ignore')
					filename = self.appdir + skycodeday
					filenamepng = self.appdir + skycodedaypng
					if not pathExists(filenamepng):
						if not pathExists(filename):
							url = "%s%s" % (imagerelativeurl, skycodeday)
							IconDownloadList.append(WeatherIconItem(url = url,filename = filename, index = index))
					else:
						self.showIcon(index,filenamepng)
		if len(IconDownloadList) != 0:
			ds = defer.DeferredSemaphore(tokens=len(IconDownloadList))
			downloads = [ds.run(download,item ).addErrback(self.errorIconDownload, item).addCallback(self.finishedIconDownload,item) for item in IconDownloadList]
			finished = defer.DeferredList(downloads).addErrback(self.error)
		stadt = config.plugins.mc_wi.Entry[self.weatherPluginEntryIndex - 1].city.value
		stadt = stadt.split(",")[0]
		stadt = stadt.replace('Ä', 'Ae')
		stadt = stadt.replace('ä', 'ae')
		stadt = stadt.replace('Ö', 'Oe')
		stadt = stadt.replace('ö', 'oe')
		stadt = stadt.replace('Ü', 'Ue')
		stadt = stadt.replace('ü', 'ue')
		stadt = stadt.replace('ß', 'ss')
		stadt = stadt.lower()
		if self.mvion == True:
			self.showiframe.finishStillPicture()
		bild = "/tmp/"+ stadt +".m1v"
		if fileExists(bild):
			self.showiframe.showStillpicture(bild)
			self.mvion = True
		else:
			self.mvidown(stadt)
	def config(self):
		self.session.openWithCallback(self.setupFinished, WeatherSetup)
	def setupFinished(self, index, entry = None):
		self.weatherPluginEntryCount = config.plugins.mc_wi.entrycount.value
		if self.weatherPluginEntryCount >= 1:
			if entry is not None:
				self.weatherPluginEntry = entry
				self.weatherPluginEntryIndex = index + 1
			if self.weatherPluginEntry is None:
				self.weatherPluginEntry = config.plugins.mc_wi.Entry[0]
				self.weatherPluginEntryIndex = 1
		else:
			self.weatherPluginEntry = None
			self.weatherPluginEntryIndex = -1
		self.clearFields()
		self.startRun()
	def error(self, error = None):
		self.mvion = False
		self.showiframe.showStillpicture("/usr/share/enigma2/black.mvi")
		if error is not None:
			self.clearFields()
			self["statustext"].text = str(error.getErrorMessage())
Пример #13
0
class MC_WeatherInfo(Screen):
    def __init__(self, session):
        Screen.__init__(self, session)
        self['actions'] = ActionMap(
            ['WizardActions', 'DirectionActions', 'ColorActions'], {
                'back': self.exit,
                'blue': self.config,
                'right': self.nextItem,
                'left': self.previousItem
            }, -1)
        self['statustext'] = StaticText()
        self['currenticon'] = WeatherIcon()
        self['CurrentCity'] = StaticText()
        self['currentTemp'] = StaticText()
        self['condition'] = StaticText()
        self['wind_condition'] = StaticText()
        self['humidity'] = StaticText()
        self['observationtime'] = StaticText()
        self['observationpoint'] = StaticText()
        self['feelsliketemp'] = StaticText()
        self.showiframe = Showiframe()
        self.mvion = False
        i = 1
        while i <= 5:
            self['weekday%s' % i] = StaticText()
            self['weekday%s_icon' % i] = WeatherIcon()
            self['weekday%s_temp' % i] = StaticText()
            self['weekday%s_tempname' % i] = StaticText()
            i += 1

        del i
        self.appdir = eEnv.resolve(
            '${libdir}/enigma2/python/Plugins/Extensions/BMediaCenter/icons/70x70/'
        )
        self.weatherPluginEntryIndex = -1
        self.weatherPluginEntryCount = config.plugins.mc_wi.entrycount.value
        if self.weatherPluginEntryCount >= 1:
            self.weatherPluginEntry = config.plugins.mc_wi.Entry[0]
            self.weatherPluginEntryIndex = 1
        else:
            self.weatherPluginEntry = None
        self.language = config.osd.language.value.replace('_', '-')
        if self.language == 'en-EN':
            self.language = 'en-US'
        self.webSite = ''
        self.onLayoutFinish.append(self.startRun)
        return

    def exit(self):
        self.showiframe.finishStillPicture()
        self.close()

    def startRun(self):
        if self.weatherPluginEntry is not None:
            self['statustext'].text = _('Loading information...')
            url = 'http://weather.service.msn.com/data.aspx?weadegreetype=%s&culture=%s&wealocations=%s' % (
                self.weatherPluginEntry.degreetype.value, self.language,
                self.weatherPluginEntry.weatherlocationcode.value)
            getPage(url).addCallback(self.xmlCallback).addErrback(self.error)
        else:
            self['statustext'].text = _(
                "No locations defined...\nPress 'Blue' to do that.")
        return

    def mvidown(self, stadt):
        downlink = 'http://www.meinestadt.de/' + stadt + '/bilder'
        downname = '/tmp/.stadtindex'
        stadd = stadt
        if fileExists(downname):
            os.system('rm -rf ' + downname)
        downloadPage(downlink,
                     downname).addCallback(self.jpgdown,
                                           stadd).addErrback(self.error)

    def jpgdown(self, value, stadd):
        downlink = commands.getoutput(
            'cat /tmp/.stadtindex | grep "background-image:url(\'http://mytown.de/" | cut -d "\'" -f2'
        )
        stadt = stadd
        downname = '/tmp/' + stadt + '.jpg'
        downloadPage(downlink,
                     downname).addCallback(self.makemvi,
                                           stadt).addErrback(self.error)

    def makemvi(self, value, stadt):
        mviname = '/tmp/' + stadt + '.m1v'
        if fileExists(mviname) is False:
            import subprocess
            if fileExists('/sbin/ffmpeg'):
                ffmpeg = '/sbin/ffmpeg'
            else:
                ffmpeg = '/usr/bin/ffmpeg'
            if fileExists('/sbin/ffmpeg') or fileExists('/sbin/ffmpeg'):
                cmd = [
                    ffmpeg, '-f', 'image2', '-i', '/tmp/' + stadt + '.jpg',
                    mviname
                ]
                subprocess.Popen(cmd).wait()
            if fileExists(mviname):
                self.showiframe.showStillpicture(mviname)

    def nextItem(self):
        if self.weatherPluginEntryCount != 0:
            if self.weatherPluginEntryIndex < self.weatherPluginEntryCount:
                self.weatherPluginEntryIndex = self.weatherPluginEntryIndex + 1
            else:
                self.weatherPluginEntryIndex = 1
            self.setItem()

    def previousItem(self):
        if self.weatherPluginEntryCount != 0:
            if self.weatherPluginEntryIndex >= 2:
                self.weatherPluginEntryIndex = self.weatherPluginEntryIndex - 1
            else:
                self.weatherPluginEntryIndex = self.weatherPluginEntryCount
            self.setItem()

    def setItem(self):
        self.weatherPluginEntry = config.plugins.mc_wi.Entry[
            self.weatherPluginEntryIndex - 1]
        self.clearFields()
        self.startRun()

    def clearFields(self):
        self['CurrentCity'].text = ''
        self['currentTemp'].text = ''
        self['condition'].text = ''
        self['wind_condition'].text = ''
        self['humidity'].text = ''
        self['observationtime'].text = ''
        self['observationpoint'].text = ''
        self['feelsliketemp'].text = ''
        self['currenticon'].hide()
        self.webSite = ''
        i = 1
        while i <= 5:
            self['weekday%s' % i].text = ''
            self['weekday%s_icon' % i].hide()
            self['weekday%s_temp' % i].text = ''
            self['weekday%s_tempname' % i].text = ''
            i += 1

    def errorIconDownload(self, error=None, item=None):
        item.error = True

    def finishedIconDownload(self, result, item):
        if not item.error:
            self.showIcon(item.index, item.filename)

    def showIcon(self, index, filename):
        if index != -1:
            self['weekday%s_icon' % index].updateIcon(filename)
            self['weekday%s_icon' % index].show()
        else:
            self['currenticon'].updateIcon(filename)
            self['currenticon'].show()

    def xmlCallback(self, xmlstring):
        self['statustext'].text = ''
        IconDownloadList = []
        root = cet_fromstring(xmlstring)
        index = 0
        degreetype = 'C'
        imagerelativeurl = ''
        errormessage = ''
        for childs in root:
            if childs.tag == 'weather':
                errormessage = childs.attrib.get('errormessage')
                if errormessage:
                    self['statustext'].text = errormessage.encode(
                        'utf-8', 'ignore')
                    break
                self['CurrentCity'].text = self.weatherPluginEntry.city.value
                degreetype = childs.attrib.get('degreetype').encode(
                    'utf-8', 'ignore')
                imagerelativeurl = '%slaw/' % childs.attrib.get(
                    'imagerelativeurl').encode('utf-8', 'ignore')
                self.webSite = childs.attrib.get('url').encode(
                    'utf-8', 'ignore')
            for items in childs:
                if items.tag == 'current':
                    self['currentTemp'].text = '%s\xc2\xb0%s' % (
                        items.attrib.get('temperature').encode(
                            'utf-8', 'ignore'), degreetype)
                    self['condition'].text = items.attrib.get(
                        'skytext').encode('utf-8', 'ignore')
                    self['humidity'].text = _(
                        'Humidity: %s %%') % items.attrib.get(
                            'humidity').encode('utf-8', 'ignore')
                    self['wind_condition'].text = items.attrib.get(
                        'winddisplay').encode('utf-8', 'ignore')
                    c = time.strptime(
                        items.attrib.get('observationtime').encode(
                            'utf-8', 'ignore'), '%H:%M:%S')
                    self['observationtime'].text = _(
                        'Observation time: %s') % time.strftime('%H:%M', c)
                    self['observationpoint'].text = _(
                        'Observation point: %s') % items.attrib.get(
                            'observationpoint').encode('utf-8', 'ignore')
                    self['feelsliketemp'].text = _(
                        'Feels like %s') % items.attrib.get(
                            'feelslike').encode(
                                'utf-8', 'ignore') + '\xc2\xb0' + degreetype
                    skycode = '%s.gif' % items.attrib.get('skycode').encode(
                        'utf-8', 'ignore')
                    filename = path + 'icons/' + skycode
                    skycodepng = '%s.png' % items.attrib.get('skycode').encode(
                        'utf-8', 'ignore')
                    filenamepng = path + 'icons/' + skycodepng
                    if not pathExists(filenamepng):
                        if not pathExists(filename):
                            url = '%s%s' % (imagerelativeurl, skycode)
                            IconDownloadList.append(
                                WeatherIconItem(url=url,
                                                filename=filename,
                                                index=-1))
                    else:
                        self.showIcon(-1, filenamepng)
                elif items.tag == 'forecast' and index <= 4:
                    index += 1
                    c = time.strptime(
                        items.attrib.get('date').encode('utf-8', 'ignore'),
                        '%Y-%m-%d')
                    self['weekday%s' % index].text = '%s\n%s' % (
                        items.attrib.get('day').encode(
                            'utf-8', 'ignore'), time.strftime('%d. %b', c))
                    lowTemp = items.attrib.get('low').encode('utf-8', 'ignore')
                    highTemp = items.attrib.get('high').encode(
                        'utf-8', 'ignore')
                    self[
                        'weekday%s_temp' %
                        index].text = 'Min: %s\xc2\xb0%s \n Max: %s\xc2\xb0%s' % (
                            lowTemp, degreetype, highTemp, degreetype)
                    self['weekday%s_tempname' %
                         index].text = '%s' % items.attrib.get(
                             'skytextday').encode('utf-8', 'ignore')
                    skycodeday = '%s.gif' % items.attrib.get(
                        'skycodeday').encode('utf-8', 'ignore')
                    skycodedaypng = '%s.png' % items.attrib.get(
                        'skycodeday').encode('utf-8', 'ignore')
                    filename = self.appdir + skycodeday
                    filenamepng = self.appdir + skycodedaypng
                    if not pathExists(filenamepng):
                        if not pathExists(filename):
                            url = '%s%s' % (imagerelativeurl, skycodeday)
                            IconDownloadList.append(
                                WeatherIconItem(url=url,
                                                filename=filename,
                                                index=index))
                    else:
                        self.showIcon(index, filenamepng)

        if len(IconDownloadList) != 0:
            ds = defer.DeferredSemaphore(tokens=len(IconDownloadList))
            downloads = [
                ds.run(download,
                       item).addErrback(self.errorIconDownload,
                                        item).addCallback(
                                            self.finishedIconDownload, item)
                for item in IconDownloadList
            ]
            finished = defer.DeferredList(downloads).addErrback(self.error)
        stadt = config.plugins.mc_wi.Entry[self.weatherPluginEntryIndex -
                                           1].city.value
        stadt = stadt.split(',')[0]
        stadt = stadt.replace('\xc3\x84', 'Ae')
        stadt = stadt.replace('\xc3\xa4', 'ae')
        stadt = stadt.replace('\xc3\x96', 'Oe')
        stadt = stadt.replace('\xc3\xb6', 'oe')
        stadt = stadt.replace('\xc3\x9c', 'Ue')
        stadt = stadt.replace('\xc3\xbc', 'ue')
        stadt = stadt.replace('\xc3\x9f', 'ss')
        stadt = stadt.lower()
        if self.mvion == True:
            self.showiframe.finishStillPicture()
        bild = '/tmp/' + stadt + '.m1v'
        if fileExists(bild):
            self.showiframe.showStillpicture(bild)
            self.mvion = True
        else:
            self.mvidown(stadt)

    def config(self):
        self.session.openWithCallback(self.setupFinished, WeatherSetup)

    def setupFinished(self, index, entry=None):
        self.weatherPluginEntryCount = config.plugins.mc_wi.entrycount.value
        if self.weatherPluginEntryCount >= 1:
            if entry is not None:
                self.weatherPluginEntry = entry
                self.weatherPluginEntryIndex = index + 1
            if self.weatherPluginEntry is None:
                self.weatherPluginEntry = config.plugins.mc_wi.Entry[0]
                self.weatherPluginEntryIndex = 1
        else:
            self.weatherPluginEntry = None
            self.weatherPluginEntryIndex = -1
        self.clearFields()
        self.startRun()
        return

    def error(self, error=None):
        self.mvion = False
        self.showiframe.showStillpicture('/usr/share/enigma2/black.mvi')
        if error is not None:
            self.clearFields()
            self['statustext'].text = str(error.getErrorMessage())
        return