Пример #1
0
def config(name=None, value=None):
    if name == 'DATA_SOURCE':
        error_message = "you can't change data source in this way. please use `bgmi source ${data source}` in cli"
        result = {'status': 'error',
                  'message': error_message,
                  'data': write_config()['data']}
        return result
    r = write_config(name, value)
    if name == 'ADMIN_TOKEN':
        r['message'] = 'you need to restart your bgmi_http to make new token work'
    return r
Пример #2
0
def config(name=None, value=None):
    if name == 'DATA_SOURCE':
        error_message = "you can't change data source in this way. please use `bgmi source ${data source}` in cli"
        result = {
            'status': 'error',
            'message': error_message,
            'data': write_config()['data']
        }
        return result
    r = write_config(name, value)
    if name == 'ADMIN_TOKEN':
        r['message'] = 'you need to restart your bgmi_http to make new token work'
    return r
Пример #3
0
def config(name=None, value=None):
    if name == "DATA_SOURCE":
        error_message = "you can't change data source in this way. please use `bgmi source ${data source}` in cli"
        result = {
            "status": "error",
            "message": error_message,
            "data": write_config()["data"],
        }
        return result
    r = write_config(name, value)
    if name == "ADMIN_TOKEN":
        r["message"] = "you need to restart your bgmi_http to make new token work"
    return r
Пример #4
0
def source(data_source):
    result = {}
    if data_source in list(map(lambda x: x['id'], SUPPORT_WEBSITE)):
        recreate_source_relatively_table()
        write_config('DATA_SOURCE', data_source)
        print_success('data source switch succeeds')
        result['status'] = 'success'
        result['message'] = 'you have successfully change your data source to {}'.format(data_source)
    else:
        result['status'] = 'error'
        result['message'] = 'please check input.nata source should be {} or {}'.format(
            *[x['id'] for x in SUPPORT_WEBSITE])
    return result
Пример #5
0
def source(data_source: str) -> ControllerResult:
    result = {}
    if data_source in list(map(itemgetter("id"), SUPPORT_WEBSITE)):
        recreate_source_relatively_table()
        write_config("DATA_SOURCE", data_source)
        print_success("data source switch succeeds")
        result["status"] = "success"
        result[
            "message"] = f"you have successfully change your data source to {data_source}"
    else:
        result["status"] = "error"
        result[
            "message"] = "please check your input. data source should be one of {}".format(
                [x["id"] for x in SUPPORT_WEBSITE])
    return result
Пример #6
0
def source(data_source):
    result = {}
    if data_source in list(map(lambda x: x['id'], SUPPORT_WEBSITE)):
        recreate_source_relatively_table()
        write_config('DATA_SOURCE', data_source)
        print_success('data source switch succeeds')
        result['status'] = 'success'
        result[
            'message'] = 'you have successfully change your data source to {}'.format(
                data_source)
    else:
        result['status'] = 'error'
        result[
            'message'] = 'please check input.nata source should be {} or {}'.format(
                *[x['id'] for x in SUPPORT_WEBSITE])
    return result
Пример #7
0
def source(data_source):
    result = {}
    if data_source in list(map(lambda x: x["id"], SUPPORT_WEBSITE)):
        recreate_source_relatively_table()
        write_config("DATA_SOURCE", data_source)
        print_success("data source switch succeeds")
        result["status"] = "success"
        result[
            "message"] = "you have successfully change your data source to {}".format(
                data_source)
    else:
        result["status"] = "error"
        result[
            "message"] = "please check input.nata source should be {} or {}".format(
                *[x["id"] for x in SUPPORT_WEBSITE])
    return result
Пример #8
0
def source(data_source):
    result = {}
    if data_source in list(map(lambda x: x['id'], SUPPORT_WEBSITE)):
        recreate_source_relatively_table()
        write_config('DATA_SOURCE', data_source)
        print_success('data source switch succeeds')
        from bgmi.fetch import DATA_SOURCE_MAP
        data = DATA_SOURCE_MAP.get(data_source)().bangumi_calendar(
            force_update=True)
        result['status'] = 'success'
        result[
            'message'] = 'you have successfully change your data source to {}'.format(
                data_source)
        result['data'] = data
    else:
        result['status'] = 'error'
        result[
            'message'] = 'please check input.nata source should be {} or {}'.format(
                *[x['id'] for x in SUPPORT_WEBSITE])
    return result
Пример #9
0
Файл: main.py Проект: xxoxx/BGmi
def main():
    c = CommandParser()
    action = c.add_arg_group('action')

    sub_parser_add = action.add_sub_parser(ACTION_ADD,
                                           help='Subscribe bangumi.')
    sub_parser_add.add_argument('name',
                                arg_type='+',
                                required=True,
                                help='Bangumi name to subscribe.')

    sub_parser_filter = action.add_sub_parser(ACTION_FILTER,
                                              help='Set bangumi fetch filter.')
    sub_parser_filter.add_argument('name',
                                   required=True,
                                   help='Bangumi name to set the filter.')
    sub_parser_filter.add_argument('subtitle_group',
                                   help='Subtitle group name.')
    sub_parser_filter.add_argument('--remove',
                                   help='Remove subtitle group filter.')
    sub_parser_filter.add_argument(
        '--remove-all',
        help='Remove all the subtitle group filter.',
        mutex='--remove')

    sub_parser_del = action.add_sub_parser(ACTION_DELETE,
                                           help='Unsubscribe bangumi.')
    sub_parser_del.add_argument('--name',
                                arg_type='+',
                                mutex='--clear-all',
                                help='Bangumi name to unsubscribe.')
    sub_parser_del.add_argument('--clear-all',
                                help='Clear all the subscriptions.')
    sub_parser_del.add_argument('--batch', help='No confirmation.')

    sub_parser_fetch = action.add_sub_parser(ACTION_FETCH,
                                             help='Fetch a specific bangumi.')
    sub_parser_fetch.add_argument('name',
                                  help='Bangumi name to fetch.',
                                  required=True)

    sub_parser_update = action.add_sub_parser(
        ACTION_UPDATE,
        help='Update bangumi calendar and '
        'subscribed bangumi episode.')
    sub_parser_update.add_argument('--download',
                                   help='Download the bangumi when updated.')

    sub_parser_cal = action.add_sub_parser(ACTION_CAL,
                                           help='Print bangumi calendar.')
    sub_parser_cal.add_argument('filter',
                                default='today',
                                choice=FILTER_CHOICES,
                                help='Calendar form filter %s.' %
                                ', '.join(FILTER_CHOICES))
    sub_parser_cal.add_argument('--today',
                                help='Show bangumi calendar for today.')
    sub_parser_cal.add_argument(
        '--force-update', help='Get the newest bangumi calendar from dmhy.')
    sub_parser_cal.add_argument(
        '--no-save', help='Do not save the bangumi data when force update.')

    sub_parser_config = action.add_sub_parser(ACTION_CONFIG,
                                              help='Config BGmi.')
    sub_parser_config.add_argument('name', help='Config name')
    sub_parser_config.add_argument('value', help='Config value')

    sub_parser_followed = action.add_sub_parser(
        ACTION_FOLLOWED, help='Followed bangumi manager.')
    sub_parser_followed.add_sub_parser('list', help='List followed bangumi.')
    followed_mark = sub_parser_followed.add_sub_parser(
        'mark', help='Mark specific bangumi\'s episode.')
    followed_mark.add_argument('name', help='Bangumi name.', required=True)
    followed_mark.add_argument('episode', help='Bangumi episode.')

    sub_parser_download = action.add_sub_parser(ACTION_DOWNLOAD,
                                                help='Download manager.')
    download_list = sub_parser_download.add_sub_parser(
        'list', help='List download queue.')
    download_list.add_argument('status',
                               help='Download status: 0, 1, 2',
                               choice=(0, 1, 2, None))

    download_mark = sub_parser_download.add_sub_parser(
        'mark', help='Mark download status with a specific id.')
    download_mark.add_argument('id', help='Download id')
    download_mark.add_argument('status',
                               help='Status will be marked',
                               choice=(0, 1, 2))

    positional = c.add_arg_group('positional')
    positional.add_argument('install', help='Install xunlei-lixian for BGmi.')

    c.add_argument('-h', help='Print help text.')
    c.add_argument('--version', help='Show the version of BGmi.')
    c.add_argument('--debug', help='Enable DEBUG mode.')

    ret = c.parse_command()

    if ret.version:
        print_version()
        raise SystemExit

    if ret.positional.install == 'install':
        import bgmi.setup
        bgmi.setup.install()
        raise SystemExit

    elif ret.action == ACTION_ADD:
        add(ret)

    elif ret.action == ACTION_FILTER:
        filter_(ret)

    elif ret.action == ACTION_FETCH:
        bangumi_obj = Bangumi(name=ret.action.fetch.name)
        bangumi_obj.select_obj()

        followed_obj = Followed(bangumi_name=bangumi_obj.name)
        followed_obj.select_obj()

        if bangumi_obj:
            print_info('Fetch bangumi {0} ...'.format(bangumi_obj.name))
            _, data = get_maximum_episode(bangumi_obj)
            for i in data:
                print_success(i['title'])

        else:
            print_error('Bangumi {0} not exist'.format(ret.action.fetch.name))

    elif ret.action == ACTION_DELETE:
        delete(ret)

    elif ret.action == ACTION_UPDATE:
        update(ret)

    elif ret.action == ACTION_CAL:
        cal(ret)

    elif ret.action == ACTION_CONFIG:
        write_config(ret.action.config.name, ret.action.config.value)

    elif ret.action == ACTION_FOLLOWED:
        if not ret.action.followed == 'mark' and not ret.action.followed.list:
            c.print_help()
        else:
            followed(ret)

    elif ret.action == ACTION_DOWNLOAD:
        if ret.action.download in DOWNLOAD_ACTION:
            download_manager(ret)
        else:
            c.print_help()
    else:
        c.print_help()
Пример #10
0
def config(ret):
    write_config(ret.name, ret.value)
Пример #11
0
def config_wrapper(ret):
    result = write_config(ret.name, ret.value)
    if (not ret.name) and (not ret.value):
        print(result['message'])
    else:
        globals()["print_{}".format(result['status'])](result['message'])