Esempio n. 1
0
    def install():
        # install xunlei-lixian
        import tarfile
        import requests
        print_info('Downloading xunlei-lixian from https://github.com/iambus/xunlei-lixian/')
        r = requests.get('https://github.com/iambus/xunlei-lixian/tarball/master', stream=True,
                         headers={'Accept-Encoding': ''})
        f = NamedTemporaryFile(delete=False)

        with f:
            for chunk in r.iter_content(chunk_size=1024):
                if chunk:
                    f.write(chunk)
        f.close()
        print_success('Download successfully, save at %s, extracting ...' % f.name)
        zip_file = tarfile.open(f.name, 'r:gz')
        zip_file.extractall(os.path.join(BGMI_PATH, 'tools/xunlei-lixian'))
        dir_name = zip_file.getnames()[0]

        print_info('Create link file ...')

        if not os.path.exists(XUNLEI_LX_PATH):
            os.symlink(os.path.join(BGMI_PATH, 'tools/xunlei-lixian/{0}/lixian_cli.py'.format(dir_name)),
                       XUNLEI_LX_PATH)
        else:
            print_warning('{0} already exists'.format(XUNLEI_LX_PATH))

        print_success('All done')
        print_info('Please run command \'{0} config\' to configure your lixian-xunlei '
                   '(Notice: only for Thunder VIP)'.format(XUNLEI_LX_PATH))
Esempio n. 2
0
def create_dir():
    path_to_create = (
        BGMI_PATH,
        SAVE_PATH,
        TMP_PATH,
        SCRIPT_PATH,
        TOOLS_PATH,
        FRONT_STATIC_PATH,
    )

    if not os.environ.get("HOME", os.environ.get("USERPROFILE", "")):
        print_warning("$HOME not set, use '/tmp/'")

    # bgmi home dir
    try:
        for path in path_to_create:
            if not os.path.exists(path):
                os.makedirs(path)
                print_success("%s created successfully" % path)
        OLD = os.path.join(BGMI_PATH, "old")
        # create OLD if not exist oninstall
        if not os.path.exists(OLD):
            with open(OLD, "w") as f:
                f.write(__version__)
    except OSError as e:
        print_error("Error: {}".format(str(e)))
Esempio n. 3
0
    def __new__(cls, *args, **kwargs):
        if cls._defined is None:

            script_files = glob.glob('{}{}*.py'.format(SCRIPT_PATH,
                                                       os.path.sep))
            for i in script_files:
                try:
                    s = imp.load_source('script', os.path.join(SCRIPT_PATH, i))
                    script_class = getattr(s, 'Script')()

                    if cls.check(script_class):
                        cls.scripts.append(script_class)
                        print_success('Load script {} successfully.'.format(i))

                except:
                    print_warning('Load script {} failed, ignored'.format(i))
                    if os.getenv('DEBUG_SCRIPT'):
                        traceback.print_exc()
                    # self.scripts = filter(self._check_followed, self.scripts)
                    # self.scripts = filter(self._check_bangumi, self.scripts)

            cls._defined = super(ScriptRunner,
                                 cls).__new__(cls, *args, **kwargs)

        return cls._defined
Esempio n. 4
0
File: cli.py Progetto: canbion/BGmi
def search_wrapper(ret):
    data = search(keyword=ret.keyword, count=ret.count, regex=ret.regex_filter)

    for i in data:
        print_success(i['title'])
    if ret.download:
        download_prepare(data)
Esempio n. 5
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
Esempio n. 6
0
def download_manager(ret: Any) -> None:
    if ret.id:
        # 没有入口..
        download_id = ret.id
        status = ret.status
        if download_id is None or status is None:
            print_error("No id or status specified.")
        print_success("Download status has been marked as {}".format(
            DOWNLOAD_CHOICE_LIST_DICT.get(int(status))))
    else:
        status = ret.status
        status = int(status) if status is not None else None
        delegate = get_download_class()
        delegate.download_status(status=status)
Esempio n. 7
0
def search_wrapper(ret):
    result = search(keyword=ret.keyword,
                    count=ret.count,
                    regex=ret.regex_filter,
                    dupe=ret.dupe,
                    min_episode=ret.min_episode,
                    max_episode=ret.max_episode)
    if result['status'] != 'success':
        globals()["print_{}".format(result['status'])](result['message'])
    data = result['data']
    for i in data:
        print_success(i['title'])
    if ret.download:
        download_prepare(data)
Esempio n. 8
0
File: cli.py Progetto: RicterZ/BGmi
def search_wrapper(ret):
    result = search(keyword=ret.keyword,
                    count=ret.count,
                    regex=ret.regex_filter,
                    dupe=ret.dupe,
                    min_episode=ret.min_episode,
                    max_episode=ret.max_episode)
    if result['status'] != 'success':
        globals()["print_{}".format(result['status'])](result['message'])
    data = result['data']
    for i in data:
        print_success(i['title'])
    if ret.download:
        download_prepare(data)
Esempio n. 9
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
Esempio n. 10
0
def create_dir():
    path_to_create = (BGMI_PATH, SAVE_PATH, TMP_PATH, SCRIPT_PATH, TOOLS_PATH,
                      FRONT_STATIC_PATH)

    if not os.environ.get('HOME', os.environ.get('USERPROFILE', '')):
        print_warning('$HOME not set, use \'/tmp/\'')

    # bgmi home dir
    try:
        for path in path_to_create:
            if not os.path.exists(path):
                os.makedirs(path)
                print_success('%s created successfully' % path)
    except OSError as e:
        print_error('Error: {0}'.format(str(e)))
Esempio n. 11
0
def search_wrapper(ret):
    result = search(
        keyword=ret.keyword,
        count=ret.count,
        regex=ret.regex_filter,
        dupe=ret.dupe,
        min_episode=ret.min_episode,
        max_episode=ret.max_episode,
    )
    if result["status"] != "success":
        globals()["print_{}".format(result["status"])](result["message"])
    data = result["data"]
    for i in data:
        print_success(i["title"])
    if ret.download:
        download_prepare(data)
Esempio n. 12
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
Esempio n. 13
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
Esempio n. 14
0
def create_dir():
    if not os.environ.get('HOME', ''):
        print_warning('$HOME not set, use \'/tmp/\'')

    tools_path = os.path.join(BGMI_PATH, 'tools')
    # bgmi home dir
    path_to_create = (BGMI_PATH, SAVE_PATH, TMP_PATH, SCRIPT_PATH, tools_path,
                      FRONT_STATIC_PATH)

    try:
        for path in path_to_create:
            if not os.path.exists(path):
                print_success('%s created successfully' % path)
                os.mkdir(path)
            else:
                print_warning('%s already exists' % path)
    except OSError as e:
        print_error('Error: {0}'.format(str(e)))
Esempio n. 15
0
    def install():
        # install xunlei-lixian
        import tarfile
        import requests

        print_info(
            "Downloading xunlei-lixian from https://github.com/iambus/xunlei-lixian/"
        )
        r = requests.get(
            "https://github.com/iambus/xunlei-lixian/tarball/master",
            stream=True,
            headers={"Accept-Encoding": ""},
        )
        f = NamedTemporaryFile(delete=False)

        with f:
            for chunk in r.iter_content(chunk_size=1024):
                if chunk:
                    f.write(chunk)
        f.close()
        print_success("Download successfully, save at %s, extracting ..." % f.name)
        zip_file = tarfile.open(f.name, "r:gz")
        zip_file.extractall(os.path.join(BGMI_PATH, "tools/xunlei-lixian"))
        dir_name = zip_file.getnames()[0]

        print_info("Create link file ...")

        if not os.path.exists(XUNLEI_LX_PATH):
            os.symlink(
                os.path.join(
                    BGMI_PATH, "tools/xunlei-lixian/{}/lixian_cli.py".format(dir_name)
                ),
                XUNLEI_LX_PATH,
            )
        else:
            print_warning("{} already exists".format(XUNLEI_LX_PATH))

        print_success("All done")
        print_info(
            "Please run command '{} config' to configure your lixian-xunlei "
            "(Notice: only for Thunder VIP)".format(XUNLEI_LX_PATH)
        )
Esempio n. 16
0
    def run(self,
            return_: bool = True,
            download: bool = False) -> List[Episode]:
        for script in self.scripts:
            print_info(f"fetching {script.bangumi_name} ...")
            download_item = self.make_dict(script)

            script_obj = script.Model().obj

            if not download_item:
                print_info(f"Got nothing, quit script {script}.")
                continue

            max_episode = max(download_item, key=itemgetter("episode"))
            episode = max_episode["episode"]
            episode_range = range(script_obj.episode + 1, episode + 1)

            if episode <= script_obj.episode:
                continue

            print_success(f"{script.bangumi_name} updated, episode: {episode}")
            script_obj.episode = episode
            script_obj.status = STATUS_UPDATED
            script_obj.updated_time = int(time.time())
            script_obj.save()

            download_queue = []
            for i in episode_range:
                for e in download_item:
                    if i == e["episode"]:
                        download_queue.append(e)

            if return_:
                self.download_queue.extend(
                    Episode(**x) for x in download_queue)
                continue

            if download:
                print_success(f"Start downloading of {script}")
                download_prepare([Episode(**x) for x in download_queue])

        return self.download_queue
Esempio n. 17
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
Esempio n. 18
0
def create_dir():
    path_to_create = (BGMI_PATH, SAVE_PATH, TMP_PATH, SCRIPT_PATH, TOOLS_PATH,
                      FRONT_STATIC_PATH)

    if not os.environ.get('HOME', os.environ.get('USERPROFILE', '')):
        print_warning('$HOME not set, use \'/tmp/\'')

    # bgmi home dir
    try:
        for path in path_to_create:
            if not os.path.exists(path):
                os.makedirs(path)
                print_success('%s created successfully' % path)
        OLD = os.path.join(BGMI_PATH, 'old')
        # create OLD if not exist oninstall
        if not os.path.exists(OLD):
            with open(OLD, 'w') as f:
                f.write(__version__)
    except OSError as e:
        print_error('Error: {0}'.format(str(e)))
Esempio n. 19
0
def create_dir():
    path_to_create = (BGMI_PATH, SAVE_PATH, TMP_PATH,
                      SCRIPT_PATH, TOOLS_PATH, FRONT_STATIC_PATH)

    if not os.environ.get('HOME', os.environ.get('USERPROFILE', '')):
        print_warning('$HOME not set, use \'/tmp/\'')

    # bgmi home dir
    try:
        for path in path_to_create:
            if not os.path.exists(path):
                os.makedirs(path)
                print_success('%s created successfully' % path)
        OLD = os.path.join(BGMI_PATH, 'old')
        # create OLD if not exist oninstall
        if not os.path.exists(OLD):
            with open(OLD, 'w') as f:
                f.write(__version__)
    except OSError as e:
        print_error('Error: {0}'.format(str(e)))
Esempio n. 20
0
File: cli.py Progetto: RicterZ/BGmi
def download_manager(ret):
    if ret.id:
        # 没有入口..
        download_id = ret.id
        status = ret.status
        if download_id is None or status is None:
            print_error('No id or status specified.')
        # download_obj = NeoDownload.get(_id=download_id)
        # if not download_obj:
        #     print_error('Download object does not exist.')
        # print_info('Download Object <{0} - {1}>, Status: {2}'.format(download_obj.name, download_obj.episode,
        #                                                              download_obj.status))
        # download_obj.status = status
        # download_obj.save()
        print_success('Download status has been marked as {0}'.format(
            DOWNLOAD_CHOICE_LIST_DICT.get(int(status))))
    else:
        status = ret.status
        status = int(status) if status is not None else None
        delegate = get_download_class(instance=False)
        delegate.download_status(status=status)
Esempio n. 21
0
def fetch_(ret):
    bangumi_obj = Bangumi(name=ret.name)
    bangumi_obj.select_obj()

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

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

    if bangumi_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'])
    else:
        print_error('Bangumi {0} not exist'.format(ret.name))
Esempio n. 22
0
File: base.py Progetto: RicterZ/BGmi
    def download_status(status=None):
        last_status = -1
        for download_data in Download.get_all_downloads(status=status):
            latest_status = download_data['status']
            name = '  {0}. <{1}: {2}>'.format(download_data['id'], download_data['name'],
                                              download_data['episode'])
            if latest_status != last_status:
                if latest_status == STATUS_DOWNLOADING:
                    print('Downloading items:')
                elif latest_status == STATUS_NOT_DOWNLOAD:
                    print('Not downloaded items:')
                elif latest_status == STATUS_DOWNLOADED:
                    print('Downloaded items:')

            if download_data['status'] == STATUS_NOT_DOWNLOAD:
                print_info(name, indicator=False)
            elif download_data['status'] == STATUS_DOWNLOADING:
                print_warning(name, indicator=False)
            elif download_data['status'] == STATUS_DOWNLOADED:
                print_success(name, indicator=False)
            last_status = download_data['status']
Esempio n. 23
0
File: cli.py Progetto: canbion/BGmi
def download_manager(ret):
    if ret.id:
        # 没有入口..
        download_id = ret.id
        status = ret.status
        if download_id is None or status is None:
            print_error('No id or status specified.')
        # download_obj = NeoDownload.get(_id=download_id)
        # if not download_obj:
        #     print_error('Download object does not exist.')
        # print_info('Download Object <{0} - {1}>, Status: {2}'.format(download_obj.name, download_obj.episode,
        #                                                              download_obj.status))
        # download_obj.status = status
        # download_obj.save()
        print_success('Download status has been marked as {0}'.format(
            DOWNLOAD_CHOICE_LIST_DICT.get(int(status))))
    else:
        status = ret.status
        status = int(status) if status is not None else None
        delegate = get_download_class(instance=False)
        delegate.download_status(status=status)
Esempio n. 24
0
    def run(self, return_=True, download=False):
        for script in self.scripts:
            print_info('fetching {} ...'.format(script.bangumi_name))
            download_item = self.make_dict(script)

            script_obj = script.Model().obj

            if not download_item:
                print_info('Got nothing, quit script {}.'.format(script))
                continue

            max_episode = max(download_item, key=lambda d: d['episode'])
            episode = max_episode['episode']
            episode_range = range(script_obj.episode + 1, episode + 1)

            if episode <= script_obj.episode:
                continue

            print_success('{} updated, episode: {}'.format(
                script.bangumi_name, episode))
            script_obj.episode = episode
            script_obj.status = STATUS_UPDATED
            script_obj.updated_time = int(time.time())
            script_obj.save()

            download_queue = []
            for i in episode_range:
                for e in download_item:
                    if i == e['episode']:
                        download_queue.append(e)

            if return_:
                self.download_queue.extend(download_queue)
                continue

            if download:
                print_success('Start downloading of {}'.format(script))
                download_prepare(download_queue)

        return self.download_queue
Esempio n. 25
0
    def run(self, return_=True, download=False):
        for script in self.scripts:
            print_info('fetching {} ...'.format(script.bangumi_name))
            download_item = self.make_dict(script)

            script_obj = script.Model().obj

            if not download_item:
                print_info('Got nothing, quit script {}.'.format(script))
                continue

            max_episode = max(download_item, key=lambda d: d['episode'])
            episode = max_episode['episode']
            episode_range = range(script_obj.episode + 1, episode + 1)

            if episode <= script_obj.episode:
                continue

            print_success('{} updated, episode: {}'.format(script.bangumi_name, episode))
            script_obj.episode = episode
            script_obj.status = STATUS_UPDATED
            script_obj.updated_time = int(time.time())
            script_obj.save()

            download_queue = []
            for i in episode_range:
                for e in download_item:
                    if i == e['episode']:
                        download_queue.append(e)

            if return_:
                self.download_queue.extend(download_queue)
                continue

            if download:
                print_success('Start downloading of {}'.format(script))
                download_prepare(download_queue)

        return self.download_queue
Esempio n. 26
0
    def install():
        # install xunlei-lixian
        import tarfile
        import requests
        print_info(
            'Downloading xunlei-lixian from https://github.com/iambus/xunlei-lixian/'
        )
        r = requests.get(
            'https://github.com/iambus/xunlei-lixian/tarball/master',
            stream=True,
            headers={'Accept-Encoding': ''})
        f = NamedTemporaryFile(delete=False)

        with f:
            for chunk in r.iter_content(chunk_size=1024):
                if chunk:
                    f.write(chunk)
        f.close()
        print_success('Download successfully, save at %s, extracting ...' %
                      f.name)
        zip_file = tarfile.open(f.name, 'r:gz')
        zip_file.extractall(os.path.join(BGMI_PATH, 'tools/xunlei-lixian'))
        dir_name = zip_file.getnames()[0]

        print_info('Create link file ...')

        if not os.path.exists(XUNLEI_LX_PATH):
            os.symlink(
                os.path.join(
                    BGMI_PATH,
                    'tools/xunlei-lixian/{0}/lixian_cli.py'.format(dir_name)),
                XUNLEI_LX_PATH)
        else:
            print_warning('{0} already exists'.format(XUNLEI_LX_PATH))

        print_success('All done')
        print_info(
            'Please run command \'{0} config\' to configure your lixian-xunlei '
            '(Notice: only for Thunder VIP)'.format(XUNLEI_LX_PATH))
Esempio n. 27
0
    def download_status(status=None):
        last_status = -1
        for download_data in Download.get_all_downloads(status=status):
            latest_status = download_data['status']
            name = '  {0}. <{1}: {2}>'.format(download_data['id'],
                                              download_data['name'],
                                              download_data['episode'])
            if latest_status != last_status:
                if latest_status == STATUS_DOWNLOADING:
                    print('Downloading items:')
                elif latest_status == STATUS_NOT_DOWNLOAD:
                    print('Not downloaded items:')
                elif latest_status == STATUS_DOWNLOADED:
                    print('Downloaded items:')

            if download_data['status'] == STATUS_NOT_DOWNLOAD:
                print_info(name, indicator=False)
            elif download_data['status'] == STATUS_DOWNLOADING:
                print_warning(name, indicator=False)
            elif download_data['status'] == STATUS_DOWNLOADED:
                print_success(name, indicator=False)
            last_status = download_data['status']
Esempio n. 28
0
File: base.py Progetto: scjtqs/BGmi
    def download_status(status=None):
        last_status = -1
        for download_data in Download.get_all_downloads(status=status):
            latest_status = download_data["status"]
            name = "  {}. <{}: {}>".format(
                download_data["id"], download_data["name"], download_data["episode"]
            )
            if latest_status != last_status:
                if latest_status == STATUS_DOWNLOADING:
                    print("Downloading items:")
                elif latest_status == STATUS_NOT_DOWNLOAD:
                    print("Not downloaded items:")
                elif latest_status == STATUS_DOWNLOADED:
                    print("Downloaded items:")

            if download_data["status"] == STATUS_NOT_DOWNLOAD:
                print_info(name, indicator=False)
            elif download_data["status"] == STATUS_DOWNLOADING:
                print_warning(name, indicator=False)
            elif download_data["status"] == STATUS_DOWNLOADED:
                print_success(name, indicator=False)
            last_status = download_data["status"]
Esempio n. 29
0
    def download_status(status=None):
        Aria2DownloadRPC.check_aria2c_version()

        print_info("Print download status in database")
        BaseDownloadService.download_status(status=status)
        print()
        print_info("Print download status in aria2c-rpc")
        try:
            server = xmlrpc.client.ServerProxy(config.ARIA2_RPC_URL)
            # self.server.aria2
            status_dict = {
                STATUS_DOWNLOADING: ["tellActive"],
                STATUS_NOT_DOWNLOAD: ["tellWaiting"],
                STATUS_DOWNLOADED: ["tellStopped"],
                None: ["tellStopped", "tellWaiting", "tellActive"],
            }
            for method in status_dict.get(status):
                if method not in ("tellActive",):
                    params = (0, 1000)
                else:
                    params = ()
                if Aria2DownloadRPC.old_version:
                    data = getattr(server.aria2, method)(*params)
                else:
                    data = getattr(server.aria2, method)(
                        config.ARIA2_RPC_TOKEN, *params
                    )

                if data:
                    print_warning(f"RPC {method}:", indicator=False)

                for row in data:
                    print_success("- {}".format(row["dir"]), indicator=False)
                    for file_ in row["files"]:
                        print_info("    * {}".format(file_["path"]), indicator=False)

        except Exception:
            print_error("Cannot connect to aria2-rpc server")
Esempio n. 30
0
File: cli.py Progetto: 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'])
Esempio n. 31
0
    def download_status(status=None):
        Aria2DownloadRPC.check_aria2c_version()

        print_info('Print download status in database')
        DownloadService.download_status(status=status)
        print()
        print_info('Print download status in aria2c-rpc')
        try:
            server = PatchedServerProxy(ARIA2_RPC_URL)
            # self.server.aria2
            status_dict = {
                STATUS_DOWNLOADING: ['tellActive'],
                STATUS_NOT_DOWNLOAD: ['tellWaiting'],
                STATUS_DOWNLOADED: ['tellStopped'],
                None: ['tellStopped', 'tellWaiting', 'tellActive'],
            }
            for method in status_dict.get(status):
                if method not in ('tellActive', ):
                    params = (0, 1000)
                else:
                    params = ()
                if Aria2DownloadRPC.old_version:
                    data = server.aria2[method](*params)
                else:
                    data = server.aria2[method](ARIA2_RPC_TOKEN, *params)

                if data:
                    print_warning('RPC {0}:'.format(method), indicator=False)

                for row in data:
                    print_success('- {0}'.format(row['dir']), indicator=False)
                    for file_ in row['files']:
                        print_info('    * {0}'.format(file_['path']),
                                   indicator=False)

        except Exception as e:
            print_error('Cannot connect to aria2-rpc server')
Esempio n. 32
0
    def download_status(status=None):
        Aria2DownloadRPC.check_aria2c_version()

        print_info('Print download status in database')
        BaseDownloadService.download_status(status=status)
        print()
        print_info('Print download status in aria2c-rpc')
        try:
            server = PatchedServerProxy(ARIA2_RPC_URL)
            # self.server.aria2
            status_dict = {
                STATUS_DOWNLOADING: ['tellActive'],
                STATUS_NOT_DOWNLOAD: ['tellWaiting'],
                STATUS_DOWNLOADED: ['tellStopped'],
                None: ['tellStopped', 'tellWaiting', 'tellActive'],
            }
            for method in status_dict.get(status):
                if method not in ('tellActive', ):
                    params = (0, 1000)
                else:
                    params = ()
                if Aria2DownloadRPC.old_version:
                    data = server.aria2[method](*params)
                else:
                    data = server.aria2[method](ARIA2_RPC_TOKEN, *params)

                if data:
                    print_warning('RPC {0}:'.format(method), indicator=False)

                for row in data:
                    print_success('- {0}'.format(row['dir']), indicator=False)
                    for file_ in row['files']:
                        print_info('    * {0}'.format(file_['path']), indicator=False)

        except Exception as e:
            print_error('Cannot connect to aria2-rpc server')
Esempio n. 33
0
File: cli.py Progetto: canbion/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 Bangumi.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'])
Esempio n. 34
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)
Esempio n. 35
0
def update(name, download=None, not_ignore=False):
    logger.debug(
        'updating bangumi info with args: download: {}'.format(download))
    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'] + 60 * 60 * 24) < now:
            followed_obj = Followed.get(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 + 60 * 60 * 24) < 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:
            try:
                f = Followed.get(bangumi_name=i)
                f = model_to_dict(f)
                updated_bangumi_obj.append(f)
            except DoesNotExist:
                pass

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

    for subscribe in updated_bangumi_obj:
        print_info('fetching %s ...' % subscribe['bangumi_name'])
        try:
            bangumi_obj = Bangumi.get(name=subscribe['bangumi_name'])
        except Bangumi.DoesNotExist:
            print_error('Bangumi<{0}> does not exists.'.format(
                subscribe['bangumi_name']),
                        exit_=False)
            continue
        try:
            followed_obj = Followed.get(bangumi_name=subscribe['bangumi_name'])
        except Followed.DoesNotExist:
            print_error('Bangumi<{0}> is not 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
Esempio n. 36
0
def update(name, download=None, not_ignore=False):
    logger.debug('updating bangumi info with args: download: {}'.format(download))
    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'] + 60 * 60 * 24) < now:
            followed_obj = Followed.get(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 + 60 * 60 * 24) < now:
            obj.status = STATUS_FOLLOWED
            obj.save()

    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:
            try:
                f = Followed.get(bangumi_name=i)
                f = model_to_dict(f)
                updated_bangumi_obj.append(f)
            except DoesNotExist:
                pass

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

    for subscribe in updated_bangumi_obj:
        print_info('fetching %s ...' % subscribe['bangumi_name'])
        try:
            bangumi_obj = Bangumi.get(name=subscribe['bangumi_name'])
        except Bangumi.DoesNotExist:
            print_error('Bangumi<{0}> does not exists.'.format(subscribe['bangumi_name']),
                        exit_=False)
            continue
        try:
            followed_obj = Followed.get(bangumi_name=subscribe['bangumi_name'])
        except Followed.DoesNotExist:
            print_error('Bangumi<{0}> is not 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
Esempio n. 37
0
def update(name, download=None, not_ignore=False):
    logger.debug(
        "updating bangumi info with args: download: {}".format(download))
    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"] + 60 * 60 * 24) < now:
            followed_obj = Followed.get(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 + 60 * 60 * 24) < now:
            obj.status = STATUS_FOLLOWED
            obj.save()

    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:
            try:
                f = Followed.get(bangumi_name=i)
                f = model_to_dict(f)
                updated_bangumi_obj.append(f)
            except DoesNotExist:
                pass

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

    for subscribe in updated_bangumi_obj:
        print_info("fetching %s ..." % subscribe["bangumi_name"])
        try:
            bangumi_obj = Bangumi.get(name=subscribe["bangumi_name"])
        except Bangumi.DoesNotExist:
            print_error(
                "Bangumi<{}> does not exists.".format(
                    subscribe["bangumi_name"]),
                exit_=False,
            )
            continue
        try:
            followed_obj = Followed.get(bangumi_name=subscribe["bangumi_name"])
        except Followed.DoesNotExist:
            print_error(
                "Bangumi<{}> is not 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
Esempio n. 38
0
def update(name: List[str],
           download: Any = None,
           not_ignore: bool = False) -> ControllerResult:
    logger.debug("updating bangumi info with args: download: %r", download)
    result: Dict[str, Any] = {
        "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"] + 60 * 60 * 24) < now:
            followed_obj = Followed.get(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 + 60 * 60 * 24) < now:
            obj.status = STATUS_FOLLOWED
            obj.save()

    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 n in name:
            try:
                f = Followed.get(bangumi_name=n)
                f = model_to_dict(f)
                updated_bangumi_obj.append(f)
            except DoesNotExist:
                pass

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

    for subscribe in updated_bangumi_obj:
        print_info(f"fetching {subscribe['bangumi_name']} ...")
        try:
            bangumi_obj = Bangumi.get(name=subscribe["bangumi_name"])
        except Bangumi.DoesNotExist:
            print_error(
                "Bangumi<{}> does not exists.".format(
                    subscribe["bangumi_name"]),
                exit_=False,
            )
            continue
        try:
            followed_obj = Followed.get(bangumi_name=subscribe["bangumi_name"])
        except Followed.DoesNotExist:
            print_error(
                "Bangumi<{}> is not followed.".format(
                    subscribe["bangumi_name"]),
                exit_=False,
            )
            continue

        try:
            episode, all_episode_data = website.get_maximum_episode(
                bangumi=bangumi_obj,
                ignore_old_row=ignore,
                max_page=int(MAX_PAGE))
        except requests.exceptions.ConnectionError as e:
            print_warning(f"error {e} to fetch {bangumi_obj.name}, skip")
            continue

        if (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 + 1)
                print_success(
                    f"{subscribe['bangumi_name']} updated, episode: {episode:d}"
                )
                followed_obj.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
                })

            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([
            Episode(
                **{
                    key: value
                    for key, value in x.items() if key not in ["id", "status"]
                })
            for x in Download.get_all_downloads(status=STATUS_NOT_DOWNLOAD)
        ])

    return result