Exemplo n.º 1
0
def test_filter(bangumi_names):
    name = bangumi_names[0]
    main(f"add {name} --episode 0".split())
    main([
        "filter", name, "--subtitle", "", "--exclude", "MKV", "--regex",
        "720p|720P"
    ])
    f = Filter.get(bangumi_name=name, exclude="MKV", regex="720p|720P")
    assert not f.include
    assert not f.subtitle
Exemplo n.º 2
0
Arquivo: cli.py Projeto: RicterZ/BGmi
def filter_wrapper(ret):
    result = filter_(name=ret.name,
                     subtitle=ret.subtitle,
                     include=ret.include,
                     exclude=ret.exclude,
                     regex=ret.regex)
    if 'data' not in result:
        globals()["print_{}".format(result['status'])](result['message'])
    else:
        print_info('Usable subtitle group: {0}'.format(', '.join(result['data']['subtitle_group'])))
        followed_filter_obj = Filter.get(bangumi_name=ret.name)
        print_filter(followed_filter_obj)
    return result['data']
Exemplo n.º 3
0
def filter_wrapper(ret):
    result = filter_(name=ret.name,
                     subtitle=ret.subtitle,
                     include=ret.include,
                     exclude=ret.exclude,
                     regex=ret.regex)
    if 'data' not in result:
        globals()["print_{}".format(result['status'])](result['message'])
    else:
        print_info('Usable subtitle group: {0}'.format(', '.join(
            result['data']['subtitle_group'])))
        followed_filter_obj = Filter.get(bangumi_name=ret.name)
        print_filter(followed_filter_obj)
    return result['data']
Exemplo n.º 4
0
def filter_wrapper(ret: Any) -> None:
    result = filter_(
        name=ret.name,
        subtitle=ret.subtitle,
        include=ret.include,
        exclude=ret.exclude,
        regex=ret.regex,
    )
    if "data" not in result:
        globals()["print_{}".format(result["status"])](result["message"])
    else:
        print_info("Usable subtitle group: {}".format(", ".join(
            result["data"]["subtitle_group"])))
        followed_filter_obj = Filter.get(bangumi_name=result["data"]["name"])
        print_filter(followed_filter_obj)
Exemplo n.º 5
0
Arquivo: cli.py Projeto: RicterZ/BGmi
def fetch_(ret):
    try:
        bangumi_obj = Bangumi.get(name=ret.name)
    except Bangumi.DoesNotExist:
        print_error('Bangumi {0} not exist'.format(ret.name))
        return

    try:
        Followed.get(bangumi_name=bangumi_obj.name)
    except Followed.DoesNotExist:
        print_error('Bangumi {0} is not followed'.format(ret.name))
        return

    followed_filter_obj = Filter.get(bangumi_name=ret.name)
    print_filter(followed_filter_obj)

    print_info('Fetch bangumi {0} ...'.format(bangumi_obj.name))
    _, data = website.get_maximum_episode(bangumi_obj, ignore_old_row=False if ret.not_ignore else True)

    if not data:
        print_warning('Nothing.')
    for i in data:
        print_success(i['title'])
Exemplo n.º 6
0
def fetch_(ret):
    try:
        bangumi_obj = Bangumi.get(name=ret.name)
    except Bangumi.DoesNotExist:
        print_error('Bangumi {0} not exist'.format(ret.name))
        return

    try:
        Followed.get(bangumi_name=bangumi_obj.name)
    except Followed.DoesNotExist:
        print_error('Bangumi {0} is not followed'.format(ret.name))
        return

    followed_filter_obj = Filter.get(bangumi_name=ret.name)
    print_filter(followed_filter_obj)

    print_info('Fetch bangumi {0} ...'.format(bangumi_obj.name))
    _, data = website.get_maximum_episode(
        bangumi_obj, ignore_old_row=False if ret.not_ignore else True)

    if not data:
        print_warning('Nothing.')
    for i in data:
        print_success(i['title'])
Exemplo n.º 7
0
def fetch_(ret: Any) -> None:
    try:
        bangumi_obj = Bangumi.get(name=ret.name)
    except Bangumi.DoesNotExist:
        print_error(f"Bangumi {ret.name} not exist")
        return

    try:
        Followed.get(bangumi_name=bangumi_obj.name)
    except Followed.DoesNotExist:
        print_error(f"Bangumi {ret.name} is not followed")
        return

    followed_filter_obj = Filter.get(bangumi_name=ret.name)
    print_filter(followed_filter_obj)

    print_info(f"Fetch bangumi {bangumi_obj.name} ...")
    _, data = website.get_maximum_episode(
        bangumi_obj, ignore_old_row=not bool(ret.not_ignore))

    if not data:
        print_warning("Nothing.")
    for i in data:
        print_success(i.title)
Exemplo n.º 8
0
Arquivo: base.py Projeto: zhkrb/BGmi
    def get_maximum_episode(self,
                            bangumi,
                            subtitle=True,
                            ignore_old_row=True,
                            max_page=MAX_PAGE):
        """

        :type max_page: str
        :param max_page:
        :type bangumi: object
        :type ignore_old_row: bool
        :param ignore_old_row:
        :type bangumi: Bangumi
        :param subtitle:
        :type subtitle: bool
        """
        try:
            followed_filter_obj = Filter.get(bangumi_name=bangumi.name)
        except Filter.DoesNotExist:
            followed_filter_obj = Filter.create(bangumi_name=bangumi.name)

        if followed_filter_obj and subtitle:
            subtitle_group = followed_filter_obj.subtitle
        else:
            subtitle_group = None

        if followed_filter_obj and subtitle:
            include = followed_filter_obj.include
        else:
            include = None

        if followed_filter_obj and subtitle:
            exclude = followed_filter_obj.exclude
        else:
            exclude = None

        if followed_filter_obj and subtitle:
            regex = followed_filter_obj.regex
        else:
            regex = None

        data = [
            i for i in self.fetch_episode(_id=bangumi.keyword,
                                          name=bangumi.name,
                                          subtitle_group=subtitle_group,
                                          include=include,
                                          exclude=exclude,
                                          regex=regex,
                                          max_page=int(max_page))
            if i['episode'] is not None
        ]

        if ignore_old_row:
            data = [
                row for row in data
                if row['time'] > int(time.time()) - 3600 * 24 * 30 * 3
            ]  # three month

        if data:
            bangumi = max(data, key=lambda _i: _i['episode'])
            return bangumi, data
        else:
            return {'episode': 0}, []