Exemplo n.º 1
0
    def goto_download(self):
        def _download_callback(step, now_size=None, total_size=None):
            if step == 'downloading':
                p = {'now_size': now_size, 'total_size': total_size}
                self.set_state('download', {'step': step, 'progress': p})
                print(f'download: {p}')
            else:
                self.set_state('download', {'step': step})

        res = self.helper.download(self.url, _download_callback)

        if not res.success:
            self._fail(res.result)
            return

        info = res.result
        _d = db.download_get(info['id'])

        # 提前关闭 helper
        self._dispose_helper()

        if _d is None:
            db.download_create(info['id'], self.act['uid'], self.csdn,
                               info['url'], info['title'], info['type'],
                               info['size'], info['description'],
                               info['filename'], info['point'], info['star'],
                               info['upload_time'], info['uploader'], '',
                               datetime.now())
            self.goto_upload(info)
        else:
            self._done(info['id'])
Exemplo n.º 2
0
def download_get(_id):
    if _id == '':
        return _error_xxx_empty('id')
    _d = db.download_get(_id)
    if _d is None:
        return _error_build('download not found.')
    _download_cut(_d)
    return _success_build(_d)
Exemplo n.º 3
0
    def check_downloaded(self):
        _url = self.url
        if _url.find('#') != -1:
            _url = _url[0:_url.index('#')]

        _id = _url[_url.rfind('/') + 1:]
        _d = db.download_get(_id)
        if _d is not None:
            self._done(_id)
            return
        self.current_func = self.process_start
Exemplo n.º 4
0
def download_get_state(token, uid):
    if token == '':
        return _error_token_empty()
    if uid == '':
        return _error_uid_empty()
    act = db.act.find_one({'id': token, 'uid': uid})
    if act is None:
        return _error_token_not_exist()
    if act['state'] == 'done':
        _d = db.download_get(act['result'])
        if _d is None:
            act['result'] = 'download not found.'
        else:
            act['result'] = _download_cut(_d)
    return _state_build(act)
Exemplo n.º 5
0
async def handle_msg_group(event: Event):
    global last_cmd
    global last_index

    message = event.message

    if is_at_me(message):
        message = rm_at_me(message)

    message = message.strip()
    cmd = message.split(' ')[0]
    arg = message[len(cmd):].strip()

    qq_num = event.sender['user_id']
    qq_name = event.sender['nickname']
    if 'card' in event.sender and event.sender['card'] != '':
        qq_name = event.sender['card']
    qq_group = -1
    if 'group_id' in event:
        qq_group = event['group_id']

    _id = find_csdn_download_id(message)
    if _id is not None:
        log.info('download', _id, f'group: {qq_group}, qq: {qq_num}')
        if db.download_get(_id) is not None:
            msg = command.handle('-info', _id)
            await bot.send(event, msg)
            return
        elif qq_num in config.super_user or qq_group in config.super_group:
            url = find_csdn_download_url(message)
            await utils.run_async_funcs([async_download], event, url)
            return
        else:
            await bot.send(event, '您没有权限下载,请联系管理员下载。')
            return

    msg = command.handle(cmd, arg)
    if msg == '':
        return
    log.info('command', message, f'group: {qq_group}, qq: {qq_num}')
    await bot.send(event, msg)
Exemplo n.º 6
0
    for a in dic:
        set_dt(a)

    return dic


_path = path.frozen_path('kits/backup.db')
if not os.path.exists(_path):
    print(f'未找到备份文件:{_path}')
    exit(0)

f = open(_path, mode='r', encoding='utf8')
_str = f.read()
f.close()
_dic = json_loads(_str)
print(f'共 {len(_dic)} 条数据')
print('开始恢复...')
db.init()
new = 0
up = 0
for d in _dic:
    if db.download_get(d['id']) is None:
        db.download.insert_one(d)
        new += 1
    else:
        pass
        up += 1
        # db.download.update_one({'id': d['id']}, {'$set': d})
print(f'恢复完成:新增 {new} 条,更新 {up} 条')
Exemplo n.º 7
0
    def upload_file(self, file_path, uploading_callback=None):

        # id
        file_name = os.path.basename(file_path)
        _id = file_name[:-4]
        data = db.download_get(_id)

        # 数据校验
        if data is None:
            self.log(f'数据库中未找到文件:{os.path.basename(file_path)}')
            return

        _id = data['id']

        # 文件校验
        if self.file_list.find_by_name(f'{_id}.zip') is not None:
            if self.update_share_url:
                self.save_share_url(
                    _id,
                    self.file_list.find_by_name(f'{_id}.zip').id, True)
            # self.log(f'已上传文件:{_id}')
            return
        if self.dir_list.find_by_name(f'{_id}.zip') is not None:
            _merge_dir = self.dir_list.find_by_name(f'{_id}.zip')
            _merge_files = self.lzy.get_file_list(_merge_dir.id)
            _temp_uploaded = False
            for _merge_item in _merge_files:
                if _merge_item.name.endswith('.txt'):
                    _temp_uploaded = True
            if _temp_uploaded:
                if self.update_share_url:
                    self.save_share_url(_id, _merge_dir.id, False)
                # self.log(f'已上传大文件:{_id}')
                return
            else:
                self.log(f'已损坏的大文件:{_id}')

        # 文件拷贝
        temp_copy_dir = os.path.join(os.path.dirname(file_path),
                                     f'_temp_{_id}')
        if not os.path.exists(temp_copy_dir):
            os.mkdir(temp_copy_dir)
        _copy_path = os.path.join(temp_copy_dir, os.path.basename(file_path))
        shutil.copy(file_path, _copy_path)

        def _uploading_callback(_f_name, total_size, now_size):
            # self.log(f'{_f_name}:上传中[{now_size}/{total_size}]...')
            if uploading_callback is not None:
                uploading_callback(now_size, total_size)

        def _uploaded_callback(fid, is_file):
            self.save_share_url(_id, fid, is_file)
            self.lzy.set_passwd(fid, '', is_file)
            desc = f'{data["info"]["title"]}\n{data["info"]["description"]}'
            self.lzy.set_desc(fid, desc, is_file)

        # 文件上传
        self.log(
            f'开始上传({self.upload_index}/{self.upload_total}):{data["id"]} {data["info"]["size"]}'
        )
        code = self.lzy.upload_file(_copy_path,
                                    self.upload_folder_id,
                                    callback=_uploading_callback,
                                    uploaded_handler=_uploaded_callback)

        if code != LanZouCloud.SUCCESS:
            self.log(f'上传失败({code}):{_id}')
        else:
            self.log(f'上传完成:{_id}')

        # 文件清理
        if os.path.exists(temp_copy_dir):
            self.log(f'清理临时文件夹:{os.path.basename(temp_copy_dir)}')
            shutil.rmtree(temp_copy_dir)

        # catch all
        self.need_catch_all = True

        return code == LanZouCloud.SUCCESS