def refreshNewData(self, data):
        printDBG("IPTVDMWidget.refreshNewData")
        if self.iptvclosing: return
        self.tmpData += data
        newFiles = self.tmpData.split('\n')
        if not self.tmpData.endswith('\n'): 
            self.tmpData = newFiles[-1]
            del newFiles[-1]
        else: self.tmpData = ''

        for item in newFiles:
            params = item.split('//')
            if 4 > len(params): continue
            if item.startswith('.'): continue # do not list hidden items
            if len(params[0]) > 3 and params[0].lower()[-4:] in ['.flv', '.mp4']:
                fileName = os_path.join(config.plugins.iptvplayer.NaszaSciezka.value, params[0])
                skip = False
                for item2 in self.currList:  
                    printDBG("AAA:[%s]\nBBB:[%s]" % (item2.fileName, fileName) )
                    if fileName == item2.fileName.replace('//', '/'): 
                        skip = True
                        break
                if skip: continue
                listItem = DMItemBase(url=fileName, fileName=fileName)
                try: listItem.downloadedSize = os_path.getsize(fileName)
                except Exception: listItem.downloadedSize = 0
                listItem.status      = DMHelper.STS.DOWNLOADED
                listItem.downloadIdx = -1
                self.tmpList.append( listItem )
예제 #2
0
    def refreshNewData(self, data):
        printDBG("IPTVDMWidget.refreshNewData")
        if self.iptvclosing:
            return
        self.tmpData += data
        newFiles = self.tmpData.split("\n")
        if not self.tmpData.endswith("\n"):
            self.tmpData = newFiles[-1]
            del newFiles[-1]
        else:
            self.tmpData = ""

        for item in newFiles:
            params = item.split("//")
            if 4 > len(params):
                continue
            if item.startswith("."):
                continue  # do not list hidden items
            if len(params[0]) > 3 and params[0].lower()[-4:] in [".flv", ".mp4"]:
                fileName = os_path.join(config.plugins.iptvplayer.NaszaSciezka.value, params[0])
                skip = False
                for item2 in self.currList:
                    printDBG("AAA:[%s]\nBBB:[%s]" % (item2.fileName, fileName))
                    if fileName == item2.fileName.replace("//", "/"):
                        skip = True
                        break
                if skip:
                    continue
                listItem = DMItemBase(url=fileName, fileName=fileName)
                try:
                    listItem.downloadedSize = os_path.getsize(fileName)
                except:
                    listItem.downloadedSize = 0
                listItem.status = DMHelper.STS.DOWNLOADED
                listItem.downloadIdx = -1
                self.tmpList.append(listItem)
예제 #3
0
    def render(self, req):
        req.setHeader('Content-type', 'text/html')
        req.setHeader('charset', 'UTF-8')
        """ rendering server response """
        extraMeta = '<meta http-equiv="refresh" content="5">'
        key = None
        arg = None
        arg2 = None
        arg3 = None
        DMlist = []
        if len(req.args.keys()) >= 1:
            key = req.args.keys()[0]
            arg = req.args.get(key, None)[0]
            try:
                arg2 = req.args.get(key, None)[1]
            except Exception:
                pass
            try:
                arg3 = req.args.get(key, None)[2]
            except Exception:
                pass
            print 'Received: "%s"="%s","%s","%s"' % (key, arg, arg2, arg3)

        if key is None or arg is None:
            if None != Plugins.Extensions.IPTVPlayer.components.iptvplayerwidget.gDownloadManager:
                DMlist = Plugins.Extensions.IPTVPlayer.components.iptvplayerwidget.gDownloadManager.getList(
                )
        elif key == 'cmd' and arg == 'initDM':
            if None == Plugins.Extensions.IPTVPlayer.components.iptvplayerwidget.gDownloadManager:
                printDBG(
                    '============WebSite.py Initialize Download Manager============'
                )
                Plugins.Extensions.IPTVPlayer.components.iptvplayerwidget.gDownloadManager = IPTVDMApi(
                    2,
                    int(config.plugins.iptvplayer.IPTVDMMaxDownloadItem.value))
                DMlist = Plugins.Extensions.IPTVPlayer.components.iptvplayerwidget.gDownloadManager.getList(
                )
        elif key == 'cmd' and arg == 'runDM':
            if None != Plugins.Extensions.IPTVPlayer.components.iptvplayerwidget.gDownloadManager:
                Plugins.Extensions.IPTVPlayer.components.iptvplayerwidget.gDownloadManager.runWorkThread(
                )
                DMlist = Plugins.Extensions.IPTVPlayer.components.iptvplayerwidget.gDownloadManager.getList(
                )
        elif key == 'cmd' and arg == 'stopDM':
            if None != Plugins.Extensions.IPTVPlayer.components.iptvplayerwidget.gDownloadManager:
                Plugins.Extensions.IPTVPlayer.components.iptvplayerwidget.gDownloadManager.stopWorkThread(
                )
                DMlist = Plugins.Extensions.IPTVPlayer.components.iptvplayerwidget.gDownloadManager.getList(
                )
                extraMeta = '<meta http-equiv="refresh" content="10">'
        elif key == 'cmd' and arg == 'downloadsDM':
            if None != Plugins.Extensions.IPTVPlayer.components.iptvplayerwidget.gDownloadManager:
                DMlist = Plugins.Extensions.IPTVPlayer.components.iptvplayerwidget.gDownloadManager.getList(
                )
        elif key == 'watchMovie' and os.path.exists(arg):
            return util.redirectTo(
                "/file?action=download&file=%s" %
                urllib.quote(arg.decode('utf8', 'ignore').encode('utf-8')),
                req)
        elif key == 'stopDownload' and arg.isdigit():
            if None != Plugins.Extensions.IPTVPlayer.components.iptvplayerwidget.gDownloadManager:
                Plugins.Extensions.IPTVPlayer.components.iptvplayerwidget.gDownloadManager.stopDownloadItem(
                    int(arg))
                DMlist = Plugins.Extensions.IPTVPlayer.components.iptvplayerwidget.gDownloadManager.getList(
                )
        elif key == 'downloadAgain' and arg.isdigit():
            if None != Plugins.Extensions.IPTVPlayer.components.iptvplayerwidget.gDownloadManager:
                Plugins.Extensions.IPTVPlayer.components.iptvplayerwidget.gDownloadManager.continueDownloadItem(
                    int(arg))
                DMlist = Plugins.Extensions.IPTVPlayer.components.iptvplayerwidget.gDownloadManager.getList(
                )
        elif key == 'removeMovie' and arg.isdigit():
            if None != Plugins.Extensions.IPTVPlayer.components.iptvplayerwidget.gDownloadManager:
                Plugins.Extensions.IPTVPlayer.components.iptvplayerwidget.gDownloadManager.removeDownloadItem(
                    int(arg))
                DMlist = Plugins.Extensions.IPTVPlayer.components.iptvplayerwidget.gDownloadManager.getList(
                )

        elif key == 'cmd' and arg == 'arvchiveDM':
            if arg2 == 'deleteMovie' and os.path.exists(arg3):
                os.remove(arg3)
            elif arg2 == 'watchMovie' and os.path.exists(arg3):
                return util.redirectTo(
                    "/file?action=download&file=%s" % urllib.quote(
                        arg3.decode('utf8', 'ignore').encode('utf-8')), req)
            if os.path.exists(
                    config.plugins.iptvplayer.NaszaSciezka.value
            ) and None != Plugins.Extensions.IPTVPlayer.components.iptvplayerwidget.gDownloadManager:
                files = os.listdir(
                    config.plugins.iptvplayer.NaszaSciezka.value)
                files.sort(key=lambda x: x.lower())
                for item in files:
                    if item.startswith('.'):
                        continue  # do not list hidden items
                    if item[-4:].lower() not in ['.flv', '.mp4']: continue
                    fileName = os.path.join(
                        config.plugins.iptvplayer.NaszaSciezka.value, item)
                    skip = False
                    for item2 in Plugins.Extensions.IPTVPlayer.components.iptvplayerwidget.gDownloadManager.getList(
                    ):
                        if fileName == item2.fileName.replace('//', '/'):
                            skip = True
                            break
                    if skip: continue
                    listItem = DMItemBase(url=fileName, fileName=fileName)
                    try:
                        listItem.downloadedSize = os.path.getsize(fileName)
                    except Exception:
                        listItem.downloadedSize = 0
                    listItem.status = DMHelper.STS.DOWNLOADED
                    listItem.downloadIdx = -1
                    DMlist.append(listItem)
                if len(DMlist) == 0:
                    listItem = DMItemBase(
                        _('Nothing has been downloaded yet.'), '')
                    listItem.status = 'INFO'
                    DMlist.append(listItem)

        if len(DMlist) == 0 and arg != 'arvchiveDM':
            listItem = DMItemBase(
                _('No materials waiting in the downloader queue'), '')
            listItem.status = 'INFO'
            DMlist.append(listItem)
            extraMeta = ''
        elif len(DMlist) == 0 and arg in ['arvchiveDM', 'stopDM']:
            extraMeta = ''

        reloadScripts()
        html = '<html lang="%s">' % language.getLanguage()[:2]
        html += webParts.IncludeHEADER(extraMeta)
        html += webParts.Body().downloaderPageContent(
            Plugins.Extensions.IPTVPlayer.components.iptvplayerwidget.
            gDownloadManager, DMlist)
        return html