示例#1
0
def save_path(local=False):
    path = plugin.get_setting('save-path', unicode)
    if path == plugin.get_setting('temp-path', unicode):
        raise LocalizedError(33032, "Path for downloaded files and temporary path should not be the same",
                             check_settings=True)
    if not direxists(path):
        raise LocalizedError(33031, "Invalid save path", check_settings=True)
    if local:
        path = ensure_path_local(path)
    return ensure_unicode(path)
def get_cookies(force=False):
    realdebrid_storage = plugin.get_storage('realdebrid')
    cookies = realdebrid_storage.get('cookies')
    if not cookies or force:
        username = plugin.get_setting('real_debrid_username')
        password = plugin.get_setting('real_debrid_password')
        req = requests.get('http://real-debrid.com/ajax/login.php', 
            params={
                'user':username,
                'pass':password})
        cookies = req.cookies
        realdebrid_storage['cookies'] = cookies
    return cookies
示例#3
0
def update_library():
    import mediapoisk.container as container
    from plugin import plugin
    from mediapoisk.common import lang, batch, abort_requested
    from xbmcswift2 import xbmcgui
    from contextlib import closing

    log = logging.getLogger(__name__)
    library_manager = container.library_manager()
    scraper = container.scraper()
    media_ids = library_manager.stored_media_ids()
    if media_ids:
        log.info("Starting MediaPoisk.info library update...")
        progress = xbmcgui.DialogProgressBG()
        with closing(progress):
            progress.create(lang(30000), lang(40322))
            processed = 0
            for section, media_ids in media_ids.iteritems():
                for ids in batch(media_ids):
                    all_details = scraper.get_details_bulk(section, ids)
                    all_folders = scraper.get_folders_bulk(section, ids)
                    for media_id, details in all_details.items():
                        if media_id in all_folders:
                            for folder in all_folders[media_id]:
                                if library_manager.has_folder(folder.id):
                                    library_manager.update_folder(details, folder)
                    processed += len(ids)
                    progress.update(processed*100/len(media_ids))
                    if abort_requested():
                        break
        log.info("MediaPoisk.ru library update finished.")
    if plugin.get_setting('update-xbmc-library', bool):
        log.info("Starting XBMC library update...")
        plugin.update_library('video', library_manager.path)
示例#4
0
def batch(iterable, size=None):
    from itertools import islice, chain
    size = size or plugin.get_setting('batch-results', int)
    sourceiter = iter(iterable)
    while True:
        batchiter = islice(sourceiter, size)
        yield list(chain([batchiter.next()], batchiter))
示例#5
0
def purge_temp_dir():
    path = temp_path()
    temp_size = get_dir_size(path)
    max_size = plugin.get_setting('temp-max-size', int)*1024*1024*1024
    log.info("Current temporary folder size / Max size: %d / %d", temp_size, max_size)
    if temp_size > max_size:
        log.info("Purging temporary folder...")
        shutil.rmtree(path, True)
        if not direxists(path):
            # noinspection PyBroadException
            if xbmcvfs.mkdirs(path):
                log.info("New temporary folder size: %d", get_dir_size(path))
示例#6
0
def save_files(files, rename=False, on_finish=None):
    save = plugin.get_setting('save-files', int)
    if not save:
        on_finish()
        return
    src, dst = temp_path(), save_path()
    files_dict = {}
    for old_path in files:
        old_path = ensure_unicode(old_path)
        rel_path = os.path.relpath(old_path, src)
        new_path = os.path.join(dst, rel_path)
        if xbmcvfs.exists(new_path):
            if rename:
                if xbmcvfs.delete(old_path):
                    log.info("File %s deleted.", old_path)
            continue
        files_dict[old_path] = new_path
    if not files_dict:
        if on_finish:
            on_finish()
        return
    files_to_copy = {}
    if save != 2 or xbmcgui.Dialog().yesno(lang(30000), *lang(40318).split("|")):
        for n, old_path in enumerate(files):
            old_path = ensure_unicode(old_path)
            if old_path not in files_dict:
                continue
            new_path = files_dict[old_path]
            xbmcvfs.mkdirs(os.path.dirname(new_path))
            if rename:
                log.info("Renaming %s to %s...", old_path, new_path)
                if not xbmcvfs.rename(old_path, new_path):
                    log.info("Renaming failed. Trying to copy and delete old file...")
                    files_to_copy[old_path] = new_path
                else:
                    log.info("Success.")
            else:
                files_to_copy[old_path] = new_path
    if files_to_copy:
        copy_files(files_to_copy, delete=rename, on_finish=on_finish)
    elif on_finish:
        on_finish()
示例#7
0
def temp_path():
    path = ensure_path_local(plugin.get_setting('temp-path', unicode))
    if not direxists(path) and not xbmcvfs.mkdirs(path):
        raise LocalizedError(33030, "Invalid temporary path", check_settings=True)
    return path