Example #1
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)
Example #2
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
Example #3
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
Example #4
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()
Example #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')
Example #6
0
if __name__ == "__main__":
    xbmc.log("Simkl dir: " + str(xbmc.translatePath("special://home")))
    xbmc.log("Simkl | Python Version: " + str(sys.version))
    xbmc.log("Simkl | " + str(sys.argv), level=xbmc.LOGDEBUG)
    xbmc.log("Simkl | compdate: {0}".format(__compdate__))
    monitor = xbmc.Monitor()

    player = engine.Player()
    player.addon = __addon__
    eng = engine.Engine(API.api, player)
    #Remember: if getTime() is more than x% scrobble file

    #Testing:
    #API.api.login()

    if API.api.internet == False:
        interface.notify(getstr(32027))
    elif not API.api.is_user_logged():
        API.api.login()  #Add "remind me tomorrow button"
        #interface.notify(getstr(32026))
    else:
        interface.notify(
            getstr(32025).format(API.api.USERSETTINGS["user"]["name"]))

    #__addon__.openSettings()
    while not monitor.abortRequested():
        if monitor.waitForAbort(90):
            break
        elif player.isPlaying():
            player.onPlayBackStopped()
Example #7
0
 def pin_success(self):
     notify(get_str(32030).format(self.userSettings["user"]["name"]))