예제 #1
0
 def onInit(self):
     """The function that is loaded on Window init"""
     instruction = self.getControl(INSTRUCTION_ID)
     instruction.setLabel(
         get_str(32022).format("[COLOR ffffbf00]" + self.url + "[/COLOR]"))
     self.getControl(PIN_LABEL).setLabel(self.pin)
     t = threading.Thread(target=self.threaded)
     t.start()
예제 #2
0
    def __init__(self):
        self.userSettings = {}
        self.isLoggedIn = False
        self.loginInProgress = False

        self.headers = {"Content-Type": "application-json", "simkl-api-key": APIKEY}
        # set_setting('token', '')
        token = get_setting('token')
        if token:
            self.headers["authorization"] = "Bearer " + token
            r = self.get_user_settings()
            if r:
                notify(get_str(32025).format(self.userSettings["user"]["name"]))
                return
            elif r is None:
                notify(get_str(32027))
                return
        self.login()
예제 #3
0
    def _show_bubble(self, item):
        log("in bubble")
        if "title" in item:
            txt = ''
            title = item["title"]
            if "episode" in item:
                txt = "- S{:02}E{:02}".format(item["season"], item["episode"])
            elif "year" in item:
                title = "".join([title, " (", str(item["year"]), ")"])

            log("Show Bubble")
            notify(get_str(32028).format(txt), title=title)
예제 #4
0
 def _http(self, url, headers={}, body=None, is_json=True):
     try:
         con = http.client.HTTPSConnection("api.simkl.com")
         con.request("GET", url, headers=headers, body=body)
         r = con.getresponse().read().decode("utf-8")
         if r.find('user_token_failed') != -1:
             self.isLoggedIn = False
             set_setting('token', '')
             notify(get_str(32031))
             return False
         return json.loads(r) if is_json else r
     except Exception:
         return None
예제 #5
0
    def _thread_tracker(self):
        log("in tracker thread")
        xbmc.sleep(2000)

        total_time = int(self.getTotalTime())
        total_time_min = int(get_setting("min-length"))
        perc_mark = int(get_setting("scr-pct"))
        self._is_detected = True
        timeout = 1000
        # if total_time set and is lower than total_time_min then we do not start the loop at all and stop the thread,
        if total_time <= 0 or total_time > total_time_min:
            while self._playback_lock.isSet() and not xbmc.Monitor().abortRequested():
                try:
                    # The max() assures that the total time is over two minutes
                    # preventing it from scrobbling while buffering and solving #31
                    if min(99, 100 * self.getTime() / max(120, total_time)) >= perc_mark:
                        success = self._api.mark_as_watched(self._item)
                        if not success:
                            if timeout == 1000:
                                log("Failed to scrobble")
                                notify(get_str(32080))
                                timeout = 30000
                            elif (self.getTime() / total_time) > 0.95:
                                log("Stopped scrobbling")
                                notify(get_str(32081))
                                break
                            else:
                                log("Retrying")

                        elif success and bool(get_setting("bubble")):
                            self._show_bubble(self._item)
                            break
                except:
                    pass
                xbmc.sleep(timeout)
        log('track stop')
예제 #6
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")
예제 #7
0
    def login(self):
        if self.loginInProgress: return
        self.loginInProgress = True

        if not self.isLoggedIn:
            rdic = self._http("/oauth/pin?client_id=" + APIKEY + "&redirect=" + REDIRECT_URI, headers=self.headers)

            if isinstance(rdic, dict) and "error" not in rdic.keys():
                pin = rdic["user_code"]
                url = rdic["verification_url"]

                login = LoginDialog("simkl-LoginDialog.xml", __addon__.getAddonInfo("path"), pin=pin, url=url,
                                    pin_check=self.pin_check, pin_success=self.pin_success)
                login.doModal()
                del login
        else:
            notify(get_str(32025).format(self.userSettings["user"]["name"]))
        self.loginInProgress = False
예제 #8
0
 def pin_success(self):
     notify(get_str(32030).format(self.userSettings["user"]["name"]))