def authorize(): from windows import signin, background background.setSplash(False) back = signin.Background.create() pre = signin.PreSignInWindow.open() try: if not pre.doSignin: return None finally: del pre try: while True: pinLoginWindow = signin.PinLoginWindow.create() try: pl = myplex.PinLogin() except requests.ConnectionError: util.ERROR() util.messageDialog( util.T(32427, 'Failed'), util.T(32449, 'Sign-in failed. Cound not connect to plex.tv')) return pinLoginWindow.setPin(pl.pin) try: pl.startTokenPolling() while not pl.finished(): if pinLoginWindow.abort: util.DEBUG_LOG('SIGN IN: Pin login aborted') pl.abort() return None xbmc.sleep(100) else: if not pl.expired(): if pl.authenticationToken: pinLoginWindow.setLinking() return pl.authenticationToken else: return None finally: pinLoginWindow.doClose() del pinLoginWindow if pl.expired(): util.DEBUG_LOG('SIGN IN: Pin expired') expiredWindow = signin.ExpiredWindow.open() try: if not expiredWindow.refresh: util.DEBUG_LOG('SIGN IN: Pin refresh aborted') return None finally: del expiredWindow finally: back.doClose() del back
def setFilter(self): terms = xbmcgui.Dialog().input(util.T(32024)) if not terms: return self.clearFilter() self.filter = terms.lower() or None if not self.currentIsLive(): self.current = None if not self.fillChannelList(): self.filter = None xbmcgui.Dialog().ok(util.T(32025),util.T(32026)) return self.showOverlay(from_filter=True) self.setFocusId(201)
def onPlayBackFailed(self): util.setGlobalProperty('playing.dvr','') self.setCurrent() util.DEBUG_LOG('ON PLAYBACK FAILED') self.showProgress() #In case we failed to play video on startup self.showSeekBar(hide=True) if self.fallbackChannel: channel = self.fallbackChannel self.fallbackChannel = None self.playChannel(channel) util.showNotification(util.T(32023),time_ms=5000,header=util.T(32022)) self.windowLoop()
def getLineUpAndGuide(self): self.lastDiscovery = time.time() if not self.updateLineup(): return False self.showProgress(50,util.T(32008)) if self.devices: for d in self.devices.allDevices: util.DEBUG_LOG(d.display()) self.updateGuide() self.showProgress(75,util.T(32009)) return True
def updateGuide(self): newLinup = False if self.devices.isOld(): #1 hour if self.updateLineup(quiet=True): newLinup = True else: util.DEBUG_LOG('Discovery failed!') self.resetNextGuideUpdate(300) #Discovery failed, try again in 5 mins return False err = None guide = None try: guide = hdhr.guide.Guide(self.lineUp) except hdhr.errors.NoDeviceAuthException: err = util.T(32030) except hdhr.errors.NoGuideDataException: err = util.T(32031) except: err = util.ERROR() if err: if not self.guideFetchPreviouslyFailed: #Only show notification the first time. Don't need this every 5 mins if internet is down util.showNotification(err,header=util.T(32013)) self.resetNextGuideUpdate(300) #Could not get guide data. Check again in 5 minutes self.guideFetchPreviouslyFailed = True self.setWinProperties() if self.lineUp.hasGuideData: util.DEBUG_LOG('Next guide update: {0} minutes'.format(int((self.nextGuideUpdate - time.time())/60))) return False guide = guide or hdhr.guide.Guide() self.guideFetchPreviouslyFailed = False #Set guide data for each channel for channel in self.lineUp.channels.values(): guideChan = guide.getChannel(channel.number) channel.setGuide(guideChan) if newLinup: self.fillChannelList(update=True) self.lineUp.hasGuideData = True self.setWinProperties() util.DEBUG_LOG('Next guide update: {0} minutes'.format(int((self.nextGuideUpdate - time.time())/60))) return True
def updateListItem(self,channel,mli=None,filter_=False): guideChan = channel.guide currentShow = guideChan.currentShow() if filter_ and self.filter: if not channel.matchesFilter(self.filter) and not currentShow.matchesFilter(self.filter): return None if not mli: title = channel.name if guideChan.icon: title = CHANNEL_DISPLAY.format(channel.number,title) mli = kodigui.ManagedListItem(title,data_source={'channel': channel, 'slice': [], 'sliceOffset': 0, 'thread': None}) mli.setProperty('channel.icon',guideChan.icon) mli.setProperty('channel.number',channel.number) end = currentShow.end if end and end < self.nextChannelUpdate: self.nextChannelUpdate = end nextShow = guideChan.nextShow() thumb = currentShow.icon mli.setThumbnailImage(thumb) mli.setProperty('show.title',currentShow.title) mli.setProperty('show.synopsis',currentShow.synopsis) mli.setProperty('next.title',u'{0}: {1}'.format(util.T(32004),nextShow.title or util.T(32005))) mli.setProperty('next.icon',nextShow.icon) mli.setProperty('next.start',nextShow.start and time.strftime('%I:%M %p',time.localtime(nextShow.start)) or '') prog = currentShow.progress() if prog != None: prog = int(prog - (prog % 5)) mli.setProperty('show.progress','progress/script-hdhomerun-view-progress_{0}.png'.format(prog)) return mli
def setWinProperties(self): title = '' icon = '' nextTitle = '' progress = None channel = '' if self.currentIsLive(): channel = CHANNEL_DISPLAY.format(self.current.dataSource['channel'].number,self.current.dataSource['channel'].name) if self.current.dataSource['channel'].guide: currentShow = self.current.dataSource['channel'].guide.currentShow() title = currentShow.title icon = currentShow.icon progress = currentShow.progress() nextTitle = u'{0}: {1}'.format(util.T(32004),self.current.dataSource['channel'].guide.nextShow().title or util.T(32005)) elif self.currentIsRecorded(): rec = self.current title = rec.seriesTitle nextTitle = rec.episodeTitle icon = rec.icon channel = rec.channelName progress = rec.progress(self.player.time) self.setProperty('show.title',title) self.setProperty('show.icon',icon) self.setProperty('next.title',nextTitle) self.setProperty('channel.name',channel) if progress != None: self.currentProgress.setPercent(progress) self.currentProgress.setVisible(True) else: self.currentProgress.setPercent(0) self.currentProgress.setVisible(False)
def checkIfUpdated(self): lastAPILevel = util.getSetting('API.LEVEL',0) util.setSetting('API.LEVEL',API_LEVEL) if not lastAPILevel: return self.firstRun() elif lastAPILevel < 2: util.showTextDialog('Info',util.T(32100))
def start(self): if not self.getLineUpAndGuide(): #If we fail to get lineUp, just exit self.doClose() return util.setGlobalProperty('DVR_ENABLED',self.hasDVR() and 'true' or '') self.fillChannelList() self.player = player.HDHRPlayer().init(self,self.devices,self.touchMode) if self.hasDVR() and util.getSetting('dvr.skip.livetv', False): return self.windowLoop() channel = self.getStartChannel() if not channel: xbmcgui.Dialog().ok(util.T(32018),util.T(32017),'',util.T(32012)) self.doClose() return if self.player.isPlayingHDHR(): self.fullscreenVideo() self.showProgress() if self.player.isPlayingRecording(): util.DEBUG_LOG('HDHR video already playing (recorded)') try: url = self.player.url rec = hdhr.storageservers.StorageServers(self.devices).getRecordingByPlayURL(url) self.setCurrent(rec=rec) except: util.ERROR() else: util.DEBUG_LOG('HDHR video already playing (live)') self.setCurrent(self.getListItemByChannel(channel)) else: util.DEBUG_LOG('HDHR video not currently playing. Starting channel...') self.playChannel(channel) self.selectChannel(channel) self.cron.registerReceiver(self) self.setFocusId(210) #Set focus now that dummy list is ready self.checkIfUpdated()
def handlePush(data, from_gui=False): if not from_gui and checkForWindow(): #Do nothing if the window is open return False if data.get('type') == 'link': url = data.get('url', '') if StreamExtractor.mightHaveVideo(url): vid = StreamExtractor.getVideoInfo(url) if vid: if vid.hasMultipleStreams(): vlist = [] for info in vid.streams(): vlist.append(info['title'] or '?') idx = xbmcgui.Dialog().select(util.T(32091), vlist) if idx < 0: return vid.selectStream(idx) util.LOG(vid.streamURL()) #TODO: REMOVE StreamUtils.play(vid.streamURL()) return True if canPlayURL(url): handleURL(url) return True media = getURLMediaType(url) if media == 'video' or media == 'music': StreamUtils.play(url) return True elif media == 'image': import gui gui.showImage(url) return True elif data.get('type') == 'file': if data.get('file_type', '').startswith('image/'): import gui gui.showImage(data.get('file_url', '')) return True elif data.get('file_type', '').startswith('video/') or data.get( 'file_type', '').startswith('audio/'): StreamUtils.play(data.get('file_url', '')) return True elif data.get('type') == 'note': import gui gui.showNote(data.get('body', '')) return True elif data.get('type') == 'list': import gui gui.showList(data) return True elif data.get('type') == 'address': import urllib xbmc.executebuiltin( 'XBMC.RunScript(special://home/addons/service.pushbullet.com/lib/maps.py,service.pushbullet.com,%s,None,)' % urllib.quote(data.get('address', ''))) return True return False
def updateLineup(self,quiet=False): try: if not self.devices: self.devices = hdhr.discovery.Devices() else: self.devices.reDiscover() self.lineUp = hdhr.tuners.LineUp(self.devices) return True except hdhr.errors.NoCompatibleDevicesException: if not quiet: xbmcgui.Dialog().ok(util.T(32016),util.T(32011),'',util.T(32012)) return False except hdhr.errors.NoTunersException: if not quiet: xbmcgui.Dialog().ok(util.T(32016),util.T(32014),'',util.T(32012)) return False except hdhr.errors.EmptyLineupException: if not quiet: xbmcgui.Dialog().ok(util.T(32016),util.T(32034),'',util.T(32012)) return False except: e = util.ERROR() if not quiet: xbmcgui.Dialog().ok(util.T(32016),util.T(32015),e,util.T(32012)) return False
def firstRun(self): util.showTextDialog('Info',util.T(32100))