python类Monitor()的实例源码

osd.py 文件源码 项目:plugin.audio.spotify 作者: marcelveldt 项目源码 文件源码 阅读 36 收藏 0 点赞 0 评论 0
def run(self):
        '''Main run loop for the background thread'''
        last_title = ""
        monitor = xbmc.Monitor()
        while not monitor.abortRequested() and self.active:
            cur_playback = self.get_curplayback()
            if cur_playback and cur_playback.get("item"):
                if cur_playback["shuffle_state"] != self.dialog.shuffle_state:
                    self.toggle_shuffle(cur_playback["shuffle_state"])
                if cur_playback["repeat_state"] != self.dialog.repeat_state:
                    self.set_repeat(cur_playback["repeat_state"])
                if cur_playback["is_playing"] != self.dialog.is_playing:
                    self.toggle_playstate(cur_playback["is_playing"])
                cur_title = cur_playback["item"]["uri"]
                if cur_title != last_title:
                    last_title = cur_title
                    trackdetails = cur_playback["item"]
                    self.update_info(trackdetails)
            monitor.waitForAbort(2)

        del monitor
plugin_content.py 文件源码 项目:plugin.audio.spotify 作者: marcelveldt 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def precache_library(self):
        if not self.win.getProperty("Spotify.PreCachedItems"):
            monitor = xbmc.Monitor()
            self.win.setProperty("Spotify.PreCachedItems", "busy")
            userplaylists = self.get_user_playlists(self.userid)
            for playlist in userplaylists:
                self.get_playlist_details(playlist['owner']['id'], playlist["id"])
                if monitor.abortRequested():
                    return
            self.get_savedalbums()
            if monitor.abortRequested():
                return
            self.get_savedartists()
            if monitor.abortRequested():
                return
            self.get_saved_tracks()
            del monitor
            self.win.setProperty("Spotify.PreCachedItems", "done")
thetvdb.py 文件源码 项目:script.module.thetvdb 作者: marcelveldt 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def get_kodishows(self, continuing_only=False):
        '''
            get all tvshows in the kodi library and make sure we have a valid tvdb id
            returns combined tvshow details
        '''
        kodi_series = self._get_kodi_json('VideoLibrary.GetTvShows', '{"properties": [ %s ] }' % KODI_TV_PROPS)
        all_series = []
        monitor = xbmc.Monitor()
        if kodi_series and kodi_series.get("tvshows"):
            for kodi_serie in kodi_series["tvshows"]:
                if monitor.abortRequested() or self._close_called:
                    break
                tvdb_details = self._parse_kodi_show(kodi_serie)
                if tvdb_details and "tvdb_status" in tvdb_details:
                    if not continuing_only or (continuing_only and tvdb_details["tvdb_status"] == "Continuing"):
                        all_series.append(tvdb_details)
        del monitor
        return all_series
thetvdb.py 文件源码 项目:script.module.thetvdb 作者: marcelveldt 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def get_kodishows_airingtoday(self):
        '''
            returns full info for each tvshow in the kodi library that airs today
        '''
        result = []
        monitor = xbmc.Monitor()
        for series_info in self.get_kodishows(continuing_only=True):
            if monitor.abortRequested() or self._close_called:
                break
            details = self.get_kodishow_details(series_info["title"], serie_details=series_info)
            if details and details.get("next_episode"):
                airdate = arrow.get(details["next_episode"]["firstaired"]).date()
                if airdate == date.today():
                    result.append(series_info)
        del monitor
        return sorted(result, key=lambda k: k.get('airtime', ""))
interface.py 文件源码 项目:script.simkl 作者: SIMKL 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def threaded(self):
        """ A loop threaded function, so you can do another things meanwhile """
        log("login thread start = {0}".format(self))
        cnt = 0
        while True:
            log("Still waiting... {0}".format(cnt))
            if self.pin_check(self.pin):
                self.success()
                self.close()
                break
            if self.canceled or cnt >= 220:
                notify(get_str(32031))
                break
            cnt += 1
            xbmc.Monitor().waitForAbort(4)

        log("Stop waiting")
service.py 文件源码 项目:soap4me-proxy 作者: eschava 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def onNotification(self, sender, method, data):
        xbmc.Monitor.onNotification(self, sender, method, data)
        xbmc.log('%s: Notification %s from %s, params: %s' % (ADDONID, method, sender, str(data)))

        if method == 'VideoLibrary.OnUpdate':
            params = json.loads(data)
            if 'item' in params and 'type' in params['item']:
                item_type = params['item']['type']
                if item_type == 'episode' and 'id' in params['item'] and 'playcount' in params:
                    item_id = params['item']['id']
                    playcount = params['playcount']
                    self.watched_status.update_server_status(item_id, playcount > 0)
        elif method == 'Player.OnStop':
            params = json.loads(data)
            if 'item' in params and 'type' in params['item']:
                item_type = params['item']['type']
                if item_type == 'episode' and 'id' in params['item']:
                    item_id = params['item']['id']
                    end = params['end']
                    if end:
                        self.watched_status.update_server_status(item_id, True)
                    else:
                        # resume time is not still updated so need to re-check time later
                        threading.Timer(3.0, self.onPlayerStopped, args=(item_id, )).start()
service.py 文件源码 项目:script.skin.helper.skinbackup 作者: marcelveldt 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def __init__(self):
        '''Init'''
        self.monitor = xbmc.Monitor()
        self.colorthemes = ColorThemes()
        self.backuprestore = BackupRestore()
main_service.py 文件源码 项目:plugin.audio.spotify 作者: marcelveldt 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def __init__(self):
        self.addon = xbmcaddon.Addon(id=ADDON_ID)
        self.kodimonitor = xbmc.Monitor()
        self.spotty = Spotty()

        # spotipy and the webservice are always prestarted in the background
        # the auth key for spotipy will be set afterwards
        # the webserver is also used for the authentication callbacks from spotify api
        self.sp = spotipy.Spotify()
        self.connect_player = ConnectPlayer(sp=self.sp, spotty=self.spotty)

        self.proxy_runner = ProxyRunner(self.spotty)
        self.proxy_runner.start()
        webport = self.proxy_runner.get_port()
        log_msg('started webproxy at port {0}'.format(webport))

        # authenticate
        self.token_info = self.get_auth_token()
        if self.token_info and not self.kodimonitor.abortRequested():

            # initialize spotipy
            self.sp._auth = self.token_info["access_token"]
            me = self.sp.me()
            log_msg("Logged in to Spotify - Username: %s" % me["id"], xbmc.LOGNOTICE)

            # start experimental spotify connect daemon
            if self.addon.getSetting("connect_player") == "true" and self.spotty.playback_supported:
                self.connect_player.start()

        # start mainloop
        self.main_loop()
plugin_content.py 文件源码 项目:plugin.audio.spotify 作者: marcelveldt 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def play_track_radio(self):
        player = SpotifyRadioPlayer()
        player.set_parent(self)
        seed_track = self.sp.track(self.trackid)
        player.set_seed_tracks([seed_track])
        player.play()
        monitor = xbmc.Monitor()
        monitor.waitForAbort()
simplecache.py 文件源码 项目:script.module.simplecache 作者: marcelveldt 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def __init__(self):
        '''Initialize our caching class'''
        self._win = xbmcgui.Window(10000)
        self._monitor = xbmc.Monitor()
        self.check_cleanup()
        self._log_msg("Initialized")
thetvdb.py 文件源码 项目:script.module.thetvdb 作者: marcelveldt 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def get_kodishows_details(self, continuing_only=False):
        '''
            returns full info for each tvshow in the kodi library
            returns both kodi and tvdb info combined, including next-/last episode
        '''
        result = []
        monitor = xbmc.Monitor()
        for series_info in self.get_kodishows(continuing_only=continuing_only):
            if monitor.abortRequested() or self._close_called:
                break
            details = self.get_kodishow_details(series_info["title"], serie_details=series_info)
            if details:
                result.append(series_info)
        del monitor
        return result
simplecache.py 文件源码 项目:plugin.video.stream-cinema 作者: bbaronSVK 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def __init__(self):
        '''Initialize our caching class'''
        self._win = xbmcgui.Window(10000)
        self._monitor = xbmc.Monitor()
        self.check_cleanup()
        self._log_msg("Initialized")
service.py 文件源码 项目:plugin.audio.tidal2 作者: arnesongit 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def __init__(self, *args, **kwargs):
        xbmc.Monitor.__init__(self, *args, **kwargs)
        self.config = TidalConfig2()
        self.setLastSettings()
service.py 文件源码 项目:plugin.audio.tidal2 作者: arnesongit 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def onSettingsChanged(self):
        xbmc.Monitor.onSettingsChanged(self)
        if self.reloginNeeded():
            if xbmcgui.Dialog().yesno(heading=addon.getAddonInfo('name'), line1=_T(30256), line2=_T(30257)):
                xbmc.executebuiltin('XBMC.RunPlugin(plugin://%s/login)' % addon.getAddonInfo('id'))
            pass
utils.py 文件源码 项目:script.module.metadatautils 作者: marcelveldt 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def rate_limiter(rl_params):
    ''' A very basic rate limiter which limits to 1 request per X seconds to the api'''
    # Please respect the parties providing these free api's to us and do not modify this code.
    # If I suspect any abuse I will revoke all api keys and require all users
    # to have a personal api key for all services.
    # Thank you
    if not rl_params:
        return
    monitor = xbmc.Monitor()
    win = xbmcgui.Window(10000)
    rl_name = rl_params[0]
    rl_delay = rl_params[1]
    cur_timestamp = int(time.mktime(datetime.datetime.now().timetuple()))
    prev_timestamp = try_parse_int(win.getProperty("ratelimiter.%s" % rl_name))
    if (prev_timestamp + rl_delay) > cur_timestamp:
        sec_to_wait = (prev_timestamp + rl_delay) - cur_timestamp
        log_msg(
            "Rate limiter active for %s - delaying request with %s seconds - "
            "Configure a personal API key in the settings to get rid of this message and the delay." %
            (rl_name, sec_to_wait), xbmc.LOGNOTICE)
        while sec_to_wait and not monitor.abortRequested():
            monitor.waitForAbort(1)
            # keep setting the timestamp to create some sort of queue
            cur_timestamp = int(time.mktime(datetime.datetime.now().timetuple()))
            win.setProperty("ratelimiter.%s" % rl_name, "%s" % cur_timestamp)
            sec_to_wait -= 1
    # always set the timestamp
    cur_timestamp = int(time.mktime(datetime.datetime.now().timetuple()))
    win.setProperty("ratelimiter.%s" % rl_name, "%s" % cur_timestamp)
    del monitor
    del win
utils.py 文件源码 项目:script.module.metadatautils 作者: marcelveldt 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def get_json(url, params=None, retries=0, ratelimit=None):
    '''get info from a rest api'''
    result = {}
    if not params:
        params = {}
    # apply rate limiting if needed
    rate_limiter(ratelimit)
    try:
        response = requests.get(url, params=params, timeout=20)
        if response and response.content and response.status_code == 200:
            result = json.loads(response.content.decode('utf-8', 'replace'))
            if "results" in result:
                result = result["results"]
            elif "result" in result:
                result = result["result"]
        elif response.status_code in (429, 503, 504):
            raise Exception('Read timed out')
    except Exception as exc:
        result = None
        if "Read timed out" in str(exc) and retries < 5 and not ratelimit:
            # retry on connection error or http server limiting
            monitor = xbmc.Monitor()
            if not monitor.waitForAbort(2):
                result = get_json(url, params, retries + 1)
            del monitor
        else:
            log_exception(__name__, exc)
    # return result
    return result
scrapertools.py 文件源码 项目:plugin.video.streamondemand-pureita 作者: orione7 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def wait_for_internet(wait=30, retry=5):
    import xbmc

    monitor = xbmc.Monitor()
    count = 0
    while True:
        if internet():
            return True
        count += 1
        if count >= retry or monitor.abortRequested():
            return False
        monitor.waitForAbort(wait)
events.py 文件源码 项目:script.simkl 作者: SIMKL 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def __init__(self, api, *args, **kwargs):
        xbmc.Monitor.__init__(self)

        self._api = api
default.py 文件源码 项目:libreelec-addons 作者: linuxserver 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def __init__(self, *args, **kwargs):
      xbmc.Monitor.__init__(self)
      self.id = xbmcaddon.Addon().getAddonInfo('id')
default.py 文件源码 项目:libreelec-addons 作者: linuxserver 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def __init__(self, *args, **kwargs):
      xbmc.Monitor.__init__(self)
      self.id = xbmcaddon.Addon().getAddonInfo('id')
default.py 文件源码 项目:libreelec-addons 作者: linuxserver 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def __init__(self, *args, **kwargs):
      xbmc.Monitor.__init__(self)
      self.id = xbmcaddon.Addon().getAddonInfo('id')
default.py 文件源码 项目:libreelec-addons 作者: linuxserver 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def __init__(self, *args, **kwargs):
      xbmc.Monitor.__init__(self)
      self.id = xbmcaddon.Addon().getAddonInfo('id')
default.py 文件源码 项目:libreelec-addons 作者: linuxserver 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def __init__(self, *args, **kwargs):
      xbmc.Monitor.__init__(self)
      self.id = xbmcaddon.Addon().getAddonInfo('id')
guis.py 文件源码 项目:script.reddit.reader 作者: gedisony 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def busy_execute_sleep(self,executebuiltin, sleep=500, close=True):
        xbmc.executebuiltin("ActivateWindow(busydialog)")
        #RunAddon(script.reddit.reader,mode=listSubReddit&url=https%3A%2F%2Fwww.reddit.com%2Fr%2Fall%2F.json%3F%26nsfw%3Ano%2B%26limit%3D10%26after%3Dt3_4wmiag&name=all&type=)
        xbmc.executebuiltin( executebuiltin  )

        xbmc.Monitor().waitForAbort( int(sleep/1000)   )
        #xbmc.sleep(sleep) #a sleep of 500 is enough for listing subreddit  use about 5000 for executing a link/playing video especially a ytdl video

        if close:
            self.close()
        else:
            xbmc.executebuiltin( "Dialog.Close(busydialog)" )
scrobbler.py 文件源码 项目:service.scrobbler.hatchet 作者: michiwend 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def __init__( self ):
        self._service_setup()
        while (not self.Monitor.abortRequested()) and (not self.Exit):
            xbmc.sleep(1000)
scrobbler.py 文件源码 项目:service.scrobbler.hatchet 作者: michiwend 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def _service_setup( self ):
        self.HatchetURL           = 'https://api.hatchet.is'
        self.ClientId             = 'xbm'
        self.ClientVersion        = '0.2'
        self.ClientProtocol       = '1.2.1'
        self.Exit                 = False
        self.Monitor              = MyMonitor(action = self._get_settings)
        self._get_settings()
scrobbler.py 文件源码 项目:service.scrobbler.hatchet 作者: michiwend 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def __init__( self, *args, **kwargs ):
        xbmc.Monitor.__init__( self )
        self.action = kwargs['action']
default.py 文件源码 项目:script.kodi.lifx.ambilight 作者: sanghviharshit 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def __init__( self, *args, **kwargs ):
    xbmc.Monitor.__init__( self )
service.py 文件源码 项目:soap4me-proxy 作者: eschava 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def onScanStarted(self, library):
        xbmc.Monitor.onScanStarted(self, library)
        xbmc.log('%s: Library scan \'%s\' started' % (ADDONID, library))
service.py 文件源码 项目:soap4me-proxy 作者: eschava 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def onScanFinished(self, library):
        xbmc.Monitor.onScanFinished(self, library)
        xbmc.log('%s: Library scan \'%s\' finished' % (ADDONID, library))
        self.watched_status.sync_status()  # TODO: do in new thread


问题


面经


文章

微信
公众号

扫码关注公众号