예제 #1
0
def update(ret):
    print_info('marking bangumi status ...')
    now = int(time.time())
    for i in Followed.get_all_followed():
        if i['updated_time'] and int(i['updated_time'] + 86400) < now:
            followed_obj = Followed(bangumi_name=i['bangumi_name'])
            followed_obj.status = STATUS_FOLLOWED
            followed_obj.save()

    print_info('updating bangumi data ...')
    fetch(save=True, group_by_weekday=False)
    print_info('updating subscriptions ...')
    download_queue = []

    if ret.action.update.name is None:
        updated_bangumi_obj = Followed.get_all_followed()
    else:
        updated_bangumi_obj = []
        for i in ret.action.update.name:
            f = Followed(bangumi_name=i)
            f.select_obj()
            updated_bangumi_obj.append(f)

    for subscribe in updated_bangumi_obj:
        print_info('fetching %s ...' % subscribe['bangumi_name'])
        bangumi_obj = Bangumi(name=subscribe['bangumi_name'])
        bangumi_obj.select_obj()

        # filter by subtitle group
        if not bangumi_obj:
            print_error(
                'The bangumi {0} you subscribed does not exists ..'.format(
                    subscribe['bangumi_name']),
                exit_=False)
            continue

        episode, all_episode_data = get_maximum_episode(bangumi=bangumi_obj)
        if episode.get('episode') > subscribe['episode']:
            episode_range = range(subscribe['episode'] + 1,
                                  episode.get('episode'))
            print_success('%s updated, episode: %d' %
                          (subscribe['bangumi_name'], episode['episode']))
            _ = Followed(bangumi_name=subscribe['bangumi_name'])
            _.episode = episode['episode']
            _.status = STATUS_UPDATED
            _.updated_time = int(time.time())
            _.save()
            download_queue.append(episode)
            for i in episode_range:
                for epi in all_episode_data:
                    if epi['episode'] == i:
                        download_queue.append(epi)
                        break

    if ret.action.update and ret.action.update.download:
        download_prepare(download_queue)
        print_info('Re-downloading ...')
        download_prepare(
            Download.get_all_downloads(status=STATUS_NOT_DOWNLOAD))
예제 #2
0
파일: main.py 프로젝트: xxoxx/BGmi
def add(ret):
    # action add
    # add bangumi by a list of bangumi name
    if not Bangumi.get_all_bangumi():
        print_warning('No bangumi data in database, fetching...')
        update(ret)

    for bangumi in ret.action.add.name:
        bangumi_obj = Bangumi(name=bangumi)
        data = bangumi_obj.select(one=True, fields=['id', 'name', 'keyword'])
        if data:
            followed_obj = Followed(bangumi_name=data['name'],
                                    status=STATUS_FOLLOWED)
            followed_obj.select_obj()
            if not followed_obj or followed_obj.status == STATUS_NORMAL:
                if not followed_obj:
                    ret, _ = get_maximum_episode(bangumi_obj, subtitle=False)
                    followed_obj.episode = ret['episode']
                    followed_obj.save()
                else:
                    followed_obj.status = STATUS_FOLLOWED
                    followed_obj.save()
                print_success('{0} has followed'.format(bangumi_obj))
            else:
                print_warning('{0} already followed'.format(bangumi_obj))

        else:
            print_error('{0} not found, please check the name'.format(bangumi))
예제 #3
0
파일: controllers.py 프로젝트: luoxiai/BGmi
def add(name, episode=None):
    """
    ret.name :str
    """
    # action add
    # add bangumi by a list of bangumi name
    # result = {}
    if not Bangumi.get_all_bangumi():
        website.fetch(save=True, group_by_weekday=False)

    bangumi_obj = Bangumi(name=name)
    data = bangumi_obj.select(one=True, fields=['id', 'name', 'keyword'])
    if data:
        followed_obj = Followed(bangumi_name=data['name'],
                                status=STATUS_FOLLOWED)
        followed_obj.select_obj()
        if not followed_obj or followed_obj.status == STATUS_NORMAL:
            if not followed_obj:
                bangumi_data, _ = website.get_maximum_episode(bangumi_obj,
                                                              subtitle=False,
                                                              max_page=1)
                followed_obj.episode = bangumi_data[
                    'episode'] if episode is None else episode
                followed_obj.save()
            else:
                followed_obj.status = STATUS_FOLLOWED
                followed_obj.save()
            result = {
                'status': 'success',
                'message': '{0} has been followed'.format(bangumi_obj)
            }
        else:
            result = {
                'status': 'warning',
                'message': '{0} already followed'.format(bangumi_obj)
            }
    else:
        result = {
            'status': 'error',
            'message': '{0} not found, please check the name'.format(name)
        }
    return result
예제 #4
0
파일: controllers.py 프로젝트: luoxiai/BGmi
def status_(name, status=STATUS_NORMAL):
    result = {'status': 'success', 'message': ''}

    if not status in FOLLOWED_STATUS or not status:
        result['status'] = 'error'
        result['message'] = 'Invalid status: {0}'.format(status)
        return result

    status = int(status)
    followed_obj = Followed(bangumi_name=name)
    followed_obj.select_obj()

    if not followed_obj:
        result['status'] = 'error'
        result['message'] = 'Followed<{0}> does not exists'.format(name)
        return result

    followed_obj.status = status
    followed_obj.save()
    result['message'] = 'Followed<{0}> has been marked as status {1}'.format(
        name, status)
    return result
예제 #5
0
파일: controllers.py 프로젝트: amnek0/BGmi
def update(ret):
    ignore = False if ret.not_ignore else True
    print_info('marking bangumi status ...')
    now = int(time.time())
    for i in Followed.get_all_followed():
        if i['updated_time'] and int(i['updated_time'] + 86400) < now:
            followed_obj = Followed(bangumi_name=i['bangumi_name'])
            followed_obj.status = STATUS_FOLLOWED
            followed_obj.save()

    print_info('updating bangumi data ...')
    fetch(save=True, group_by_weekday=False)
    print_info('updating subscriptions ...')
    download_queue = []

    if ret.download:
        if not ret.name:
            print_warning('No specified bangumi, ignore `--download` option')
        if len(ret.name) > 1:
            print_warning(
                'Multiple specified bangumi, ignore `--download` option')

    if not ret.name:
        updated_bangumi_obj = Followed.get_all_followed()
    else:
        updated_bangumi_obj = []
        for i in ret.name:
            f = Followed(bangumi_name=i)
            f.select_obj()
            updated_bangumi_obj.append(f)

    for subscribe in updated_bangumi_obj:
        print_info('fetching %s ...' % subscribe['bangumi_name'])
        bangumi_obj = Bangumi(name=subscribe['bangumi_name'])
        bangumi_obj.select_obj()

        followed_obj = Followed(bangumi_name=subscribe['bangumi_name'])
        followed_obj.select_obj()

        # filter by subtitle group
        if not bangumi_obj or not followed_obj:
            print_error(
                'Bangumi<{0}> does not exist or not been followed.'.format(
                    subscribe['bangumi_name']),
                exit_=False)
            continue

        episode, all_episode_data = get_maximum_episode(bangumi=bangumi_obj,
                                                        ignore_old_row=ignore,
                                                        max_page=1)

        if (episode.get('episode') > subscribe['episode']) or (len(
                ret.name) == 1 and ret.download):
            if len(ret.name) == 1 and ret.download:
                episode_range = ret.download
            else:
                episode_range = range(subscribe['episode'] + 1,
                                      episode.get('episode', 0) + 1)
                print_success('%s updated, episode: %d' %
                              (subscribe['bangumi_name'], episode['episode']))
                followed_obj.episode = episode['episode']
                followed_obj.status = STATUS_UPDATED
                followed_obj.updated_time = int(time.time())
                followed_obj.save()

            for i in episode_range:
                for epi in all_episode_data:
                    if epi['episode'] == i:
                        download_queue.append(epi)
                        break

    if ret.download is not None:
        download_prepare(download_queue)
        print_info('Re-downloading ...')
        download_prepare(
            Download.get_all_downloads(status=STATUS_NOT_DOWNLOAD))
예제 #6
0
파일: controllers.py 프로젝트: luoxiai/BGmi
def update(name, download=None, not_ignore=False):
    result = {
        'status': 'info',
        'message': '',
        'data': {
            'updated': [],
            'downloaded': []
        }
    }

    ignore = not bool(not_ignore)
    print_info('marking bangumi status ...')
    now = int(time.time())
    for i in Followed.get_all_followed():
        if i['updated_time'] and int(i['updated_time'] + 86400) < now:
            followed_obj = Followed(bangumi_name=i['bangumi_name'])
            followed_obj.status = STATUS_FOLLOWED
            followed_obj.save()

    for script in ScriptRunner().scripts:
        obj = script.Model().obj
        if obj['updated_time'] and int(obj['updated_time'] + 86400) < now:
            obj.status = STATUS_FOLLOWED
            obj.save()

    print_info('updating bangumi data ...')
    website.fetch(save=True, group_by_weekday=False)
    print_info('updating subscriptions ...')
    download_queue = []

    if download:
        if not name:
            print_warning('No specified bangumi, ignore `--download` option')
        if len(name) > 1:
            print_warning(
                'Multiple specified bangumi, ignore `--download` option')

    if not name:
        updated_bangumi_obj = Followed.get_all_followed()
    else:
        updated_bangumi_obj = []
        for i in name:
            f = Followed(bangumi_name=i)
            f.select_obj()
            updated_bangumi_obj.append(f)

    runner = ScriptRunner()
    script_download_queue = runner.run()

    for subscribe in updated_bangumi_obj:
        print_info('fetching %s ...' % subscribe['bangumi_name'])
        bangumi_obj = Bangumi(name=subscribe['bangumi_name'])
        bangumi_obj.select_obj()

        followed_obj = Followed(bangumi_name=subscribe['bangumi_name'])
        followed_obj.select_obj()

        # filter by subtitle group
        if not bangumi_obj or not followed_obj:
            print_error(
                'Bangumi<{0}> does not exist or not been followed.'.format(
                    subscribe['bangumi_name']),
                exit_=False)
            continue

        episode, all_episode_data = website.get_maximum_episode(
            bangumi=bangumi_obj, ignore_old_row=ignore, max_page=1)

        if (episode.get('episode') > subscribe['episode']) or (len(name) == 1
                                                               and download):
            if len(name) == 1 and download:
                episode_range = download
            else:
                episode_range = range(subscribe['episode'] + 1,
                                      episode.get('episode', 0) + 1)
                print_success('%s updated, episode: %d' %
                              (subscribe['bangumi_name'], episode['episode']))
                followed_obj.episode = episode['episode']
                followed_obj.status = STATUS_UPDATED
                followed_obj.updated_time = int(time.time())
                followed_obj.save()
                result['data']['updated'].append({
                    'bangumi':
                    subscribe['bangumi_name'],
                    'episode':
                    episode['episode']
                })

            for i in episode_range:
                for epi in all_episode_data:
                    if epi['episode'] == i:
                        download_queue.append(epi)
                        break

    if download is not None:
        result['data']['downloaded'] = download_queue
        download_prepare(download_queue)
        download_prepare(script_download_queue)
        print_info('Re-downloading ...')
        download_prepare(
            Download.get_all_downloads(status=STATUS_NOT_DOWNLOAD))

    return result