Ejemplo n.º 1
0
def toggle_language_invoker():
    import xml.etree.ElementTree as ET
    from modules.utils import gen_file_hash
    kodi_utils.close_all_dialog()
    kodi_utils.sleep(100)
    addon_dir = kodi_utils.translate_path(
        'special://home/addons/plugin.video.fen')
    addon_xml = os.path.join(addon_dir, 'addon.xml')
    tree = ET.parse(addon_xml)
    root = tree.getroot()
    try:
        current_value = [
            str(i.text) for i in root.iter('reuselanguageinvoker')
        ][0]
    except:
        return
    current_setting = get_setting('reuse_language_invoker')
    new_value = 'false' if current_value == 'true' else 'true'
    if not kodi_utils.confirm_dialog(
            text=ls(33018) % (current_value.upper(), new_value.upper())):
        return
    if new_value == 'true':
        if not kodi_utils.confirm_dialog(text=33019, top_space=True): return
    for item in root.iter('reuselanguageinvoker'):
        item.text = new_value
        hash_start = gen_file_hash(addon_xml)
        tree.write(addon_xml)
        hash_end = gen_file_hash(addon_xml)
        if hash_start != hash_end:
            set_setting('reuse_language_invoker', new_value)
        else:
            return kodi_utils.ok_dialog(text=32574, top_space=True)
    kodi_utils.ok_dialog(text=33020, top_space=True)
    kodi_utils.execute_builtin('LoadProfile(%s)' %
                               kodi_utils.get_infolabel('system.profilename'))
Ejemplo n.º 2
0
 def _uncached_confirm(item):
     if not kodi_utils.confirm_dialog(text=ls(32831) %
                                      item['debrid'].upper()):
         return None
     else:
         self.caching_confirmed = True
         return item
Ejemplo n.º 3
0
 def run(self):
     logger('FEN', 'ReuseLanguageInvokerCheck Service Starting')
     addon_xml = translate_path(
         'special://home/addons/plugin.video.fen/addon.xml')
     tree = ET.parse(addon_xml)
     root = tree.getroot()
     current_addon_setting = get_setting('reuse_language_invoker', 'true')
     try:
         current_xml_setting = [
             str(i.text) for i in root.iter('reuselanguageinvoker')
         ][0]
     except:
         return logger('FEN', 'ReuseLanguageInvokerCheck Service Finished')
     if current_xml_setting == current_addon_setting:
         return logger('FEN', 'ReuseLanguageInvokerCheck Service Finished')
     for item in root.iter('reuselanguageinvoker'):
         item.text = current_addon_setting
         hash_start = gen_file_hash(addon_xml)
         tree.write(addon_xml)
         hash_end = gen_file_hash(addon_xml)
         logger('FEN', 'ReuseLanguageInvokerCheck Service Finished')
         if hash_start != hash_end:
             if not kodi_utils.confirm_dialog(text='%s\n%s' %
                                              (ls(33021), ls(33020))):
                 return
             current_profile = kodi_utils.get_infolabel(
                 'system.profilename')
             kodi_utils.execute_builtin('LoadProfile(%s)' % current_profile)
         else:
             kodi_utils.ok_dialog(text=32574, top_space=True)
Ejemplo n.º 4
0
def remove_all_history(params):
    db_type = params['db_type']
    if not kodi_utils.confirm_dialog(): return
    all_history = Discover({}).history(db_type, display=False)
    for item in all_history:
        remove_from_history({'data_id': item, 'silent': True})
    kodi_utils.notification(32576)
Ejemplo n.º 5
0
def pm_delete(file_type, file_id):
    if not kodi_utils.confirm_dialog(): return
    result = Premiumize.delete_object(file_type, file_id)
    if result == 'success':
        Premiumize.clear_cache()
        kodi_utils.execute_builtin('Container.Refresh')
    else:
        return kodi_utils.ok_dialog(text=32574, top_space=True)
Ejemplo n.º 6
0
 def confirmDownload(self, mb):
     if self.action not in ('image', 'meta.pack'):
         line = '%s[CR]%s[CR]%s'
         if not kodi_utils.confirm_dialog(
                 text=line % ('[B]%s[/B]' % self.final_name.upper(),
                              ls(32688) % mb, ls(32689))):
             return False
     return True
Ejemplo n.º 7
0
def remove_from_files(item_id):
    if not kodi_utils.confirm_dialog(): return
    response = Furk.file_unlink(item_id)
    if Furk.check_status(response):
        kodi_utils.notification(32576, 3500)
        kodi_utils.execute_builtin('Container.Refresh')
    else:
        kodi_utils.notification(32574, 3500)
    return (None, None)
Ejemplo n.º 8
0
 def delete_cache(self, silent=False):
     try:
         if not path_exists(dbfile): return 'failure'
         if not silent and not confirm_dialog(): return 'cancelled'
         self._execute(FULL_DELETE, ())
         self._vacuum()
         return 'success'
     except:
         return 'failure'
Ejemplo n.º 9
0
def delete_trakt_list(params):
    user = params['user']
    list_slug = params['list_slug']
    if not kodi_utils.confirm_dialog(): return
    url = 'users/%s/lists/%s' % (user, list_slug)
    call_trakt(url, is_delete=True)
    trakt_sync_activities()
    kodi_utils.notification(32576, 3000)
    kodi_utils.execute_builtin('Container.Refresh')
Ejemplo n.º 10
0
def rd_delete(file_id, cache_type):
    if not kodi_utils.confirm_dialog(): return
    if cache_type == 'torrent': result = RealDebrid.delete_torrent(file_id)
    else:
        result = RealDebrid.delete_download(file_id)  # cache_type: 'download'
    if result.status_code in (401, 403, 404):
        return kodi_utils.notification(32574)
    RealDebrid.clear_cache()
    kodi_utils.execute_builtin('Container.Refresh')
Ejemplo n.º 11
0
def delete_meta_cache(silent=False):
    from modules.kodi_utils import confirm_dialog
    try:
        if not silent:
            if not confirm_dialog(): return False
        metacache.delete_all()
        return True
    except:
        return False
Ejemplo n.º 12
0
def remove_from_downloads(item_id):
    if not kodi_utils.confirm_dialog(): return
    response = Furk.download_unlink(item_id)
    if Furk.check_status(response):
        main_cache.set('furk_active_downloads',
                       None,
                       expiration=EXPIRES_1_HOUR)
        kodi_utils.notification(32576, 3500)
    else:
        kodi_utils.notification(32574, 3500)
    return (None, None)
Ejemplo n.º 13
0
def add_uncached_file(item_id):
    if not kodi_utils.confirm_dialog(): return
    try:
        response = Furk.add_uncached(item_id)
        if Furk.check_status(response):
            main_cache.set('furk_active_downloads',
                           None,
                           expiration=EXPIRES_1_HOUR)
            return kodi_utils.ok_dialog(text=32576, top_space=True)
        elif response['status'] == 'error':
            return kodi_utils.ok_dialog(text=32574, top_space=True)
    except:
        return
Ejemplo n.º 14
0
	def clear_favourites(self):
		favorites = ls(32453)
		fl = [('%s %s' % (ls(32028), ls(32453)), 'movie'), ('%s %s' % (ls(32029), ls(32453)), 'tvshow')]
		list_items = [{'line1': item[0]} for item in fl]
		kwargs = {'items': json.dumps(list_items), 'heading': 'Fen', 'enumerate': 'false', 'multi_choice': 'false', 'multi_line': 'false'}
		self.db_type = select_dialog([item[1] for item in fl], **kwargs)
		if self.db_type == None: return
		if not confirm_dialog(): return
		dbcon = database.connect(self.fav_database)
		dbcon.execute("DELETE FROM favourites WHERE db_type=?", (self.db_type,))
		dbcon.commit()
		dbcon.execute('VACUUM')
		dbcon.close()
		notification(32576, 3000)
Ejemplo n.º 15
0
def furk_tfile_audio(params):
    __handle__ = int(argv[1])
    kodi_utils.clear_property('furk_t_files_json')
    excludes = ('', 'cover', 'covers', 'scan', 'scans', 'playlists')
    t_files = Furk.t_files(params.get('item_id'))
    item_path_list = list(
        set([
            clean_file_name(i['path']) for i in t_files
            if clean_file_name(i['path']).lower() not in excludes
        ]))
    item_path_list.sort()
    line = '%s[CR]%s[CR]%s'
    if not item_path_list:
        if kodi_utils.confirm_dialog(text=32763,
                                     ok_label=32652,
                                     cancel_label=32764,
                                     top_space=True):
            return browse_audio_album(t_files, params.get('name'))
        from modules.player import FenPlayer
        FenPlayer().playAudioAlbum(t_files)
        return browse_audio_album(t_files, __handle__)

    def _builder():
        for x in item_path_list:
            try:
                url_params = {
                    'mode': 'furk.browse_audio_album',
                    'item_path': x,
                    'handle': __handle__
                }
                url = build_url(url_params)
                listitem = make_listitem()
                listitem.setLabel(x.upper())
                listitem.setArt({
                    'icon': default_furk_icon,
                    'poster': default_furk_icon,
                    'thumb': default_furk_icon,
                    'fanart': fanart,
                    'banner': default_furk_icon
                })
                yield (url, listitem, True)
            except:
                pass

    t_files_json = json.dumps(t_files)
    kodi_utils.set_property('furk_t_files_json', str(t_files_json))
    kodi_utils.add_items(__handle__, list(_builder()))
    kodi_utils.set_content(__handle__, 'files')
    kodi_utils.end_directory(__handle__)
    kodi_utils.set_view_mode('view.premium')
Ejemplo n.º 16
0
 def _return_failed(message=32574, cancelled=False):
     try:
         progressDialog.close()
     except Exception:
         pass
     hide_busy_dialog()
     sleep(500)
     if cancelled:
         if confirm_dialog(text=32044, top_space=True):
             ok_dialog(heading=32733, text=ls(32732) % ls(32054))
         else:
             self.delete_torrent(torrent_id)
     else:
         ok_dialog(heading=32733, text=message)
     return False
Ejemplo n.º 17
0
 def _return_failed(message=32574, cancelled=False):
     try:
         kodi_utils.progressDialog.close()
     except Exception:
         pass
     kodi_utils.hide_busy_dialog()
     kodi_utils.sleep(500)
     if cancelled:
         if kodi_utils.confirm_dialog(text=32044, top_space=True):
             kodi_utils.ok_dialog(heading=32733,
                                  text=ls(32732) % ls(32063),
                                  top_space=True)
         else:
             self.delete_transfer(transfer_id)
     else:
         kodi_utils.ok_dialog(heading=2733, text=message)
     return False
Ejemplo n.º 18
0
def favorites_choice(params):
    from modules.favourites import Favourites
    favourites = Favourites(params)
    db_type = params['db_type']
    tmdb_id = params['tmdb_id']
    title = params['title']
    current_favourites = favourites.get_favourites(db_type)
    if any(i['tmdb_id'] == tmdb_id for i in current_favourites):
        action = favourites.remove_from_favourites
        text = '%s Fen %s?' % (ls(32603), ls(32453))
    else:
        action = favourites.add_to_favourites
        text = '%s Fen %s?' % (ls(32602), ls(32453))
    if not kodi_utils.confirm_dialog(
            heading='Fen - %s' % title, text=text, top_space=True):
        return
    action()
Ejemplo n.º 19
0
def clear_all_cache():
    if not kodi_utils.confirm_dialog(): return
    line = '[CR]%s....[CR]%s'
    kodi_utils.progressDialog.create('Fen', '')
    caches = (('meta', '%s %s' % (ls(32527), ls(32524))),
              ('internal_scrapers', '%s %s' % (ls(32096), ls(32524))),
              ('external_scrapers', '%s %s' % (ls(32118), ls(32524))),
              ('trakt', ls(32087)), ('imdb', '%s %s' % (ls(32064), ls(32524))),
              ('list', '%s %s' % (ls(32815), ls(32524))),
              ('pm_cloud', '%s %s' % (ls(32061), ls(32524))),
              ('rd_cloud', '%s %s' % (ls(32054), ls(32524))),
              ('ad_cloud', '%s %s' % (ls(32063), ls(32524))))
    for count, cache_type in enumerate(caches, 1):
        kodi_utils.progressDialog.update(
            int(float(count) / float(len(caches)) * 100),
            line % (ls(32816), cache_type[1]))
        clear_cache(cache_type[0], silent=True)
        kodi_utils.sleep(400)
    kodi_utils.progressDialog.close()
    kodi_utils.sleep(250)
    kodi_utils.ok_dialog(text=32576, top_space=True)
Ejemplo n.º 20
0
def refresh_artwork():
    if not kodi_utils.confirm_dialog(): return
    import sqlite3 as database
    for item in ('icon.png', 'fanart.png'):
        try:
            icon_path = kodi_utils.translate_path(
                'special://home/addons/plugin.video.fen/%s' % item)
            thumbs_folder = kodi_utils.translate_path('special://thumbnails')
            TEXTURE_DB = kodi_utils.translate_path(
                'special://database/Textures13.db')
            dbcon = database.connect(TEXTURE_DB)
            dbcur = dbcon.cursor()
            dbcur.execute("SELECT cachedurl FROM texture WHERE url = ?",
                          (icon_path, ))
            image = dbcur.fetchone()[0]
            dbcon.close()
            removal_path = os.path.join(thumbs_folder, image)
            kodi_utils.delete_file(removal_path)
        except:
            pass
    kodi_utils.sleep(200)
    kodi_utils.execute_builtin('ReloadSkin()')
    kodi_utils.sleep(500)
    kodi_utils.notification(32576)
Ejemplo n.º 21
0
def clear_all_trakt_cache_data(silent=False, confirm=True):
    def _process():
        dbcon = _cache.connect_database()
        dbcur = dbcon.cursor()
        for table in ('trakt_data', 'progress', 'watched_status'):
            dbcur.execute(BASE_DELETE % table)
            dbcon.commit()
        dbcur.execute('VACUUM')
        dbcon.close()

    if silent:
        return _process()
    else:
        if confirm:
            if not confirm_dialog(): return False
        from apis.trakt_api import trakt_sync_activities
        close_all_dialog()
        sleep(200)
        try:
            _process()
            trakt_sync_activities()
            return True
        except:
            return False
Ejemplo n.º 22
0
def browse_audio_album(t_files, item_path=None):
    def build_list_object():
        try:
            cm = []
            url_params = {
                'mode': 'media_play',
                'url': item['url_dl'],
                'media_type': 'music'
            }
            url = build_url(url_params)
            track_name = clean_file_name(
                batch_replace(to_utf8(item['name']), formats)).upper()
            listitem = make_listitem()
            listitem.setLabel(track_name)
            down_file_params = {
                'mode': 'downloader',
                'name': item['name'],
                'url': item['url_dl'],
                'action': 'audio',
                'image': default_furk_icon
            }
            cm.append(
                (ls(32747), 'RunPlugin(%s)' % build_url(down_file_params)))
            listitem.addContextMenuItems(cm)
            listitem.setArt({
                'icon': default_furk_icon,
                'poster': default_furk_icon,
                'thumb': default_furk_icon,
                'fanart': fanart,
                'banner': default_furk_icon
            })
            kodi_utils.add_item(__handle__, url, listitem, True)
        except:
            pass

    from modules.utils import batch_replace
    __handle__ = int(argv[1])
    seperate = False
    if not t_files:
        seperate = True
        t_fs = kodi_utils.get_property('furk_t_files_json')
        t_files = json.loads(t_fs)
    t_files = [i for i in t_files if 'audio' in i['ct']]
    line = '%s[CR]%s[CR]%s'
    if seperate:
        if kodi_utils.confirm_dialog(text=32763,
                                     ok_label=32838,
                                     cancel_label=32764,
                                     top_space=True):
            for item in t_files:
                t_path = clean_file_name(item['path'])
                if t_path == item_path:
                    build_list_object()
            kodi_utils.set_content(__handle__, 'files')
            kodi_utils.end_directory(__handle__)
            kodi_utils.set_view_mode('view.premium')
        else:
            from modules.player import FenPlayer
            FenPlayer().playAudioAlbum(t_files, from_seperate=True)
    else:
        for item in t_files:
            build_list_object()
        kodi_utils.set_content(__handle__, 'files')
        kodi_utils.end_directory(__handle__)
        kodi_utils.set_view_mode('view.premium')
Ejemplo n.º 23
0
 def _confirm():
     if not silent and not kodi_utils.confirm_dialog(): return False
     return True
Ejemplo n.º 24
0
def add_to_files(item_id):
    if not kodi_utils.confirm_dialog(text=32580, top_space=True): return
    response = Furk.file_link(item_id)
    if Furk.check_status(response): kodi_utils.notification(32576, 3500)
    else: kodi_utils.notification(32574, 3500)
    return (None, None)
Ejemplo n.º 25
0
def link_folders(service, folder_name, action):
    import json
    from caches.main_cache import main_cache

    def _get_media_type():
        media_type_list = [('movie', ls(32028), 'movies.png'),
                           ('tvshow', ls(32029), 'tv.png')]
        list_items = [{
            'line1': item[1],
            'line2': ls(32693) % item[1],
            'icon': os.path.join(theme_folder, item[2])
        } for item in media_type_list]
        kwargs = {
            'items': json.dumps(list_items),
            'heading': 'Fen',
            'enumerate': 'false',
            'multi_choice': 'false',
            'multi_line': 'true'
        }
        chosen_media_type = kodi_utils.select_dialog(
            [i[0] for i in media_type_list], **kwargs)
        return chosen_media_type

    theme_folder = kodi_utils.translate_path(
        'special://home/addons/script.tikiart/resources/media')
    string = 'FEN_%s_%s' % (service, folder_name)
    current_link = main_cache.get(string)
    if action == 'remove':
        if not current_link: return
        if not kodi_utils.confirm_dialog(text=ls(32694) % current_link,
                                         top_space=True):
            return
        import sqlite3 as database
        cache_file = kodi_utils.translate_path(
            'special://profile/addon_data/plugin.video.fen/maincache.db')
        dbcon = database.connect(cache_file)
        dbcur = dbcon.cursor()
        dbcur.execute("DELETE FROM maincache WHERE id=?", (string, ))
        dbcon.commit()
        dbcon.close()
        kodi_utils.clear_property(string)
        if service == 'FOLDER': clear_cache('folders', silent=True)
        kodi_utils.execute_builtin('Container.Refresh')
        return kodi_utils.ok_dialog(text=32576, top_space=True)
    if current_link:
        if not kodi_utils.confirm_dialog(text='%s[CR][B]%s[/B][CR]%s' %
                                         (ls(32695), current_link, ls(32696))):
            return
    media_type = _get_media_type()
    if media_type == None: return
    title = kodi_utils.dialog.input(ls(32228)).lower()
    if not title: return
    from apis.tmdb_api import tmdb_movies_title_year, tmdb_tv_title_year
    year = kodi_utils.dialog.input('%s (%s)' % (ls(32543), ls(32669)),
                                   type=kodi_utils.numeric_input)
    function = tmdb_movies_title_year if media_type == 'movie' else tmdb_tv_title_year
    results = function(title, year)['results']
    if len(results) == 0:
        return kodi_utils.ok_dialog(text=32490, top_space=True)
    name_key = 'title' if media_type == 'movie' else 'name'
    released_key = 'release_date' if media_type == 'movie' else 'first_air_date'
    function_list = []
    function_list_append = function_list.append

    def _builder():
        for item in results:
            title = item[name_key]
            try:
                year = item[released_key].split('-')[0]
            except:
                year = ''
            if year: rootname = '%s (%s)' % (title, year)
            else: rootname = title
            icon = 'https://image.tmdb.org/t/p/w780%s' % item['poster_path'] if item.get('poster_path') \
                            else kodi_utils.translate_path('special://home/addons/plugin.video.fen/icon.png')
            function_list_append(rootname)
            yield {'line1': rootname, 'line2': item['overview'], 'icon': icon}

    list_items = list(_builder())
    kwargs = {
        'items': json.dumps(list_items),
        'heading': 'Fen',
        'enumerate': 'false',
        'multi_choice': 'false',
        'multi_line': 'true'
    }
    rootname = kodi_utils.select_dialog(function_list, **kwargs)
    if rootname == None: return
    from datetime import timedelta
    main_cache.set(string, rootname, expiration=timedelta(days=365))
    if service == 'FOLDER': clear_cache('folders', silent=True)
    kodi_utils.execute_builtin('Container.Refresh')
    return kodi_utils.ok_dialog(text=32576, top_space=True)
Ejemplo n.º 26
0
def call_trakt(path,
               params={},
               data=None,
               is_delete=False,
               with_auth=True,
               method=None,
               pagination=False,
               page=1,
               suppress_error_notification=False):
    def error_notification(line1, error):
        if suppress_error_notification: return
        return kodi_utils.notification('%s: %s' % (line1, error[0:50]), 3000,
                                       trakt_icon)

    def send_query():
        resp = None
        if with_auth:
            try:
                ma_addon = kodi_utils.ext_addon('script.module.myaccounts')
                expires_at = float(ma_addon.getSetting('trakt.expires'))
                if time.time() > expires_at:
                    trakt_refresh_token()
            except:
                pass
            token = ma_addon.getSetting('trakt.token')
            if token: headers['Authorization'] = 'Bearer ' + token
        try:
            if method:
                if method == 'post':
                    resp = requests.post(API_ENDPOINT % path,
                                         headers=headers,
                                         timeout=timeout)
                elif method == 'delete':
                    resp = requests.delete(API_ENDPOINT % path,
                                           headers=headers,
                                           timeout=timeout)
                elif method == 'sort_by_headers':
                    resp = requests.get(API_ENDPOINT % path,
                                        params,
                                        headers=headers,
                                        timeout=timeout)
            elif data is not None:
                assert not params
                resp = requests.post(API_ENDPOINT % path,
                                     json=data,
                                     headers=headers,
                                     timeout=timeout)
            elif is_delete:
                resp = requests.delete(API_ENDPOINT % path,
                                       headers=headers,
                                       timeout=timeout)
            else:
                resp = requests.get(API_ENDPOINT % path,
                                    params,
                                    headers=headers,
                                    timeout=timeout)
            resp.raise_for_status()
        except requests.exceptions.RequestException as e:
            return error_notification('Trakt Error', str(e))
        except Exception as e:
            return error_notification('', str(e))
        return resp

    params = dict([(k, to_utf8(v)) for k, v in params.items() if v])
    timeout = 15.0
    numpages = 0
    headers = {
        'Content-Type': 'application/json',
        'trakt-api-version': '2',
        'trakt-api-key': CLIENT_ID
    }
    if pagination: params['page'] = page
    response = send_query()
    response.raise_for_status()
    if response.status_code == 401:
        if kodi_utils.player.isPlaying() == False:
            if with_auth and kodi_utils.confirm_dialog(
                    heading='%s %s' %
                (ls(32057), trakt_str), text=32741) and trakt_authenticate():
                response = send_query()
            else:
                pass
        else:
            return
    if response.status_code == 429:
        headers = response.headers
        if 'Retry-After' in headers:
            kodi_utils.sleep(1000 * headers['Retry-After'])
            response = send_query()
    response.encoding = 'utf-8'
    try:
        result = response.json()
    except:
        result = None
    if method == 'sort_by_headers':
        headers = response.headers
        if 'X-Sort-By' in headers and 'X-Sort-How' in headers:
            result = sort_list(headers['X-Sort-By'], headers['X-Sort-How'],
                               result, settings.ignore_articles())
    if pagination: return (result, response.headers['X-Pagination-Page-Count'])
    else: return result