def torrent_cache_clear():
    confirmation = control.yesno_dialog(
        g.ADDON_NAME, "Are you sure you wish to clear the cache?")
    if not confirmation:
        return
    try:
        migrate_db_lock.acquire()
        cursor = _get_connection_cursor(g.TORRENT_SCRAPE_CACHE)
        for t in [cache_table, 'rel_list', 'rel_lib']:
            try:
                cursor.execute("DROP TABLE IF EXISTS %s" % t)
                cursor.execute("VACUUM")
                cursor.connection.commit()
            except:
                pass
    except:
        try:
            cursor.close()
        except:
            pass
        import traceback
        traceback.print_exc()
    finally:
        control.try_release_lock(migrate_db_lock)

    control.showDialog.notification('{}: {}'.format(g.ADDON_NAME,
                                                    g.lang(30200)),
                                    g.lang(30202),
                                    time=5000)
    def auth(self):
        self.ClientSecret = ''
        self.ClientID = 'X245A4XAIBGVM'
        url = ("client_id=%s&new_credentials=yes" % self.ClientID)
        url = self.OauthUrl + self.DeviceCodeUrl % url
        response = json.loads(requests.get(url).text)
        control.copy2clip(response['user_code'])
        control.progressDialog.create(
            'Real-Debrid Auth',
            control.create_multiline_message(
                line1=g.lang(30100).format(
                    g.color_string('https://real-debrid.com/device')),
                line2=g.lang(30101).format(
                    g.color_string(response['user_code'])),
                line3=g.lang(30102),
            ),
        )
        self.OauthTimeout = int(response['expires_in'])
        self.OauthTimeStep = int(response['interval'])
        self.DeviceCode = response['device_code']

        while self.ClientSecret == '':
            self.auth_loop()

        self.token_request()

        user_information = self.get_url(
            'https://api.real-debrid.com/rest/1.0/user')
        if user_information['type'] != 'premium':
            control.ok_dialog(g.ADDON_NAME, g.lang(30104))
Exemple #3
0
    def keepAlive(self):
        for i in range(0, 480):
            if self.isPlayingVideo():
                break
            xbmc.sleep(250)


##        for i in range(0, 480):
##            if self.AVStarted:
##                break

        g.close_all_dialogs()

        try:
            audio_lang = self.getAvailableAudioStreams()
            if len(audio_lang) > 1:
                try:
                    preferred_audio = int(g.get_setting('general.audio'))
                    audio_int = audio_lang.index(g.lang(preferred_audio))
                    self.setAudioStream(audio_int)
                except:
                    pass
                try:
                    if preferred_audio == 40315:
                        self.setSubtitleStream(1)
                except:
                    pass
        except:
            pass

        if self.media_type == 'movie':
            return self.onWatchedPercent()

        if g.get_setting('smartplay.skipintrodialog') == 'true':
            while self.isPlaying():
                time_ = int(self.getTime())
                if time_ > 240:
                    break
                elif time_ >= 1:
                    PlayerDialogs()._show_skip_intro()
                    break
                else:
                    xbmc.sleep(250)

        scrobble = self.onWatchedPercent()

        if g.get_setting('smartplay.playingnextdialog') == 'true':
            endpoint = int(g.get_setting('playingnext.time'))
        else:
            endpoint = False

        if endpoint:
            while self.isPlaying():
                if int(self.getTotalTime()) - int(self.getTime()) <= endpoint:
                    xbmc.executebuiltin(
                        'RunPlugin("plugin://plugin.video.kaito/run_player_dialogs")'
                    )
                    break
                else:
                    xbmc.sleep(1000)
Exemple #4
0
def SEARCH(payload, params):
    query = control.keyboard(g.lang(30010))
    if not query:
        return False

    # TODO: Better logic here, maybe move functionatly into router?
    if "Yes" in g.get_setting('searchhistory'):
        database.addSearchHistory(query, 'show')
        history = database.getSearchHistory('show')

    return g.draw_items(_ANILIST_BROWSER.get_search(query))
def cache_clear():
    try:
        migrate_db_lock.acquire()
        cursor = _get_connection_cursor(g.CACHE_DB_PATH)

        for t in [cache_table, 'rel_list', 'rel_lib']:
            try:
                cursor.execute("DROP TABLE IF EXISTS %s" % t)
                cursor.execute("VACUUM")
                cursor.connection.commit()
            except:
                pass
        control.showDialog.notification('{}: {}'.format(
            g.ADDON_NAME, g.lang(30200)),
                                        g.lang(30201),
                                        time=5000)
    except:
        pass
    finally:
        control.try_release_lock(migrate_db_lock)
    def auth(self):
        resp = self.get_json('pin/get')
        expiry = pin_ttl = int(resp['expires_in'])
        auth_complete = False
        control.copy2clip(resp['pin'])
        control.progressDialog.create(
            g.ADDON_NAME + ': AllDebrid Auth',
            control.create_multiline_message(
                line1=g.lang(30100).format(g.color_string(resp['base_url'])),
                line2=g.lang(30101).format(g.color_string(resp['pin'])),
                line3=g.lang(30102),
            ),
        )

        # Seems the All Debrid servers need some time do something with the pin before polling
        # Polling to early will cause an invalid pin error
        control.kodi.sleep(5 * 1000)
        control.progressDialog.update(100)
        while not auth_complete and not expiry <= 0 and not control.progressDialog.iscanceled(
        ):
            auth_complete, expiry = self.poll_auth(check=resp['check'],
                                                   pin=resp['pin'])
            progress_percent = 100 - int(
                (float(pin_ttl - expiry) / pin_ttl) * 100)
            control.progressDialog.update(progress_percent)
            control.kodi.sleep(1 * 1000)
        try:
            control.progressDialog.close()
        except:
            pass

        self.store_user_info()

        if auth_complete:
            control.ok_dialog(g.ADDON_NAME,
                              'AllDebrid {}'.format(g.lang(30103)))
        else:
            return
Exemple #7
0
def _add_last_watched():
    anilist_id = g.get_setting("addon.last_watched")
    if not anilist_id:
        return

    try:
        last_watched = ast.literal_eval(
            database.get_show(anilist_id)['kodi_meta'])
    except:
        return

    MENU_ITEMS.insert(
        0, ("%s[I]%s[/I]" %
            (g.lang(30000), control.decode_py2(last_watched['name'])),
            "animes/%s/null/" % anilist_id, last_watched['poster']))
 def auth_loop(self):
     if control.progressDialog.iscanceled():
         control.progressDialog.close()
         return
     time.sleep(self.OauthTimeStep)
     url = "client_id=%s&code=%s" % (self.ClientID, self.DeviceCode)
     url = self.OauthUrl + self.DeviceCredUrl % url
     response = json.loads(requests.get(url).text)
     if 'error' in response:
         return
     else:
         try:
             control.progressDialog.close()
             g.set_setting('rd.client_id', response['client_id'])
             g.set_setting('rd.secret', response['client_secret'])
             self.ClientSecret = response['client_secret']
             self.ClientID = response['client_id']
         except:
             control.ok_dialog(g.ADDON_NAME, g.lang(30105))
         return
def wipe_install():
    """
    Destroys kaito's user_data folder for current user resetting addon to default
    :return: None
    :rtype: None
    """
    confirm = xbmcgui.Dialog().yesno(g.ADDON_NAME, g.lang(30025))
    if confirm == 0:
        return

    # confirm = xbmcgui.Dialog().yesno(
    #     g.ADDON_NAME,
    #     g.lang(30035)
    #     + "{}".format(g.color_string(g.lang(30036))),
    # )
    # if confirm == 0:
    #     return

    path = control.validate_path(g.ADDON_USERDATA_PATH)
    if xbmcvfs.exists(path):
        xbmcvfs.rmdir(path, True)
    xbmcvfs.mkdir(g.ADDON_USERDATA_PATH)
Exemple #10
0
def TOOLS_MENU(payload, params):
    TOOLS_ITEMS = [
        (g.lang(30020), "settings", ''),
        (g.lang(30021), "clear_cache", ''),
        (g.lang(30022), "clear_torrent_cache", ''),
        (g.lang(30023), "clear_history", ''),
        (g.lang(30026), "rebuild_database", ''),
        (g.lang(30024), "wipe_addon_data", ''),
    ]

    return g.draw_items(
        [
            g.allocate_item(name, url, False, image)
            for name, url, image in TOOLS_ITEMS
        ],
        contentType=g.get_setting("contenttype.menu"),
    )
    def re_build_database(self, silent=False):
        if not silent:
            confirm = control.yesno_dialog(g.ADDON_NAME, g.lang(30203))
            if confirm == 0:
                return

        path = g.ANILIST_SYNC_DB_PATH
        xbmcvfs.delete(path)
        file = open(path, 'a+')
        file.close()

        self._build_show_table()
        self._build_episode_table()
        self._build_sync_activities()
        self._build_season_table()

        self._set_base_activites()
        self._refresh_activites()

        g.close_busy_dialog()
        control.showDialog.notification(g.ADDON_NAME,
                                        "Database rebuilt",
                                        time=5000)
    def token_request(self):
        if self.ClientSecret is '':
            return

        postData = {
            'client_id': self.ClientID,
            'client_secret': self.ClientSecret,
            'code': self.DeviceCode,
            'grant_type': 'http://oauth.net/grant_type/device/1.0'
        }

        url = self.OauthUrl + self.TokenUrl
        response = requests.post(url, data=postData).text
        response = json.loads(response)
        g.set_setting('rd.auth', response['access_token'])
        g.set_setting('rd.refresh', response['refresh_token'])
        self.token = response['access_token']
        self.refresh = response['refresh_token']
        g.set_setting('rd.expiry',
                      str(time.time() + int(response['expires_in'])))
        username = self.get_url(
            'https://api.real-debrid.com/rest/1.0/user')['username']
        g.set_setting('rd.username', username)
        control.ok_dialog(g.ADDON_NAME, 'Real Debrid ' + g.lang(30103))
Exemple #13
0
    def set_settings(self):
        res = {}
        dialog = xbmcgui.Dialog()
        if self.flavor == 'anilist':
            dialog.textviewer(
                g.ADDON_NAME + ': AniList', '{}\n{}\n{}'.format(
                    g.lang(40105),
                    g.lang(40106).replace(
                        'below',
                        'in the input dialog that will popup once you close this'
                    ), g.lang(40110)))

            res['username'] = dialog.input('Enter AniList username',
                                           type=xbmcgui.INPUT_ALPHANUM)
            res['token'] = dialog.input('Enter AniList token',
                                        type=xbmcgui.INPUT_ALPHANUM)
        else:
            dialog.textviewer(
                g.ADDON_NAME + ': MyAnimeList', '{}\n{}\n{}'.format(
                    g.lang(40100),
                    g.lang(40101).replace(
                        'below',
                        'in the input dialog that will popup once you close this'
                    ), g.lang(40110)))

            res['authvar'] = dialog.input('Enter MAL auth url',
                                          type=xbmcgui.INPUT_ALPHANUM)

        try:
            for _id, value in list(res.items()):
                if not value:
                    raise Exception

                g.set_setting('%s.%s' % (self.flavor, _id), value)
                self.authorized = True
        except:
            pass

        return self.authorized
Exemple #14
0
def genre_dialog(genre_display_list):
    return control.multiselect_dialog(g.lang(30009), genre_display_list)
Exemple #15
0
def on_stopped():
    return control.yesno_dialog(g.lang(30200), g.lang(30201), g.lang(30202))
Exemple #16
0
# -*- coding: utf-8 -*-
from resources.lib.ui import control
from resources.lib.ui import player
from resources.lib.ui import database
from resources.lib.ui.globals import g
from resources.lib.ui.router import on_param, route, router_process
from resources.lib.KaitoBrowser import KaitoBrowser
from resources.lib.AniListBrowser import AniListBrowser
from resources.lib.WatchlistIntegration import set_browser, add_watchlist, watchlist_update
import ast
import sys

g.init_globals(sys.argv)

MENU_ITEMS = [
    (g.lang(30001), "anilist_airing", ''),
    (g.lang(30002), "airing_dub", ''),
    (g.lang(30003), "latest", ''),
    (g.lang(30004), "latest_dub", ''),
    (g.lang(30005), "anilist_trending", ''),
    (g.lang(30006), "anilist_popular", ''),
    (g.lang(30007), "anilist_upcoming", ''),
    (g.lang(30008), 'anilist_all_time_popular', ''),
    (g.lang(30009), "anilist_genres", ''),
    (g.lang(30010), "search_history", ''),
    (g.lang(30011), "tools", ''),
]

_TITLE_LANG = g.get_setting("titlelanguage")

_BROWSER = KaitoBrowser()