示例#1
0
 def get_dir_list(self, folder_id=-1) -> FolderList:
     """获取子文件夹列表"""
     folder_list = FolderList()
     para = {
         'item': 'files',
         'action': 'index',
         'folder_node': 1,
         'folder_id': folder_id
     }
     html = self._get(self._mydisk_url, params=para)
     if not html:
         return folder_list
     info = re.findall(
         r'&nbsp;(.+?)</a>&nbsp;.+"folk(\d+)"(.*?)>.+#BBBBBB">\[?(.*?)\.*\]?</font>',
         html.text)
     for folder_name, fid, pwd_flag, desc in info:
         folder_list.append(
             Folder(
                 id=int(fid),
                 name=folder_name.replace('&amp;', '&'),  # 修复网页中的 &amp; 为 &
                 has_pwd=True if pwd_flag else
                 False,  # 有密码时 pwd_flag 值为 style="display:initial"
                 desc=desc  # 文件夹描述信息
             ))
     return folder_list
示例#2
0
 def get_rec_dir_list(self) -> FolderList:
     """获取回收站文件夹列表"""
     # 回收站中文件(夹)名只能显示前 17 个中文字符或者 34 个英文字符,如果这些字符相同,则在文件(夹)名后添加 (序号) ,以便区分
     html = self._get(self._mydisk_url,
                      params={
                          'item': 'recycle',
                          'action': 'files'
                      })
     if not html:
         return FolderList()
     dirs = re.findall(
         r'folder_id=(\d+).+?>&nbsp;(.+?)\.{0,3}</a>.*\n+.*<td.+?>(.+?)</td>.*\n.*<td.+?>(.+?)</td>',
         html.text)
     all_dir_list = FolderList()  # 文件夹信息列表
     dir_name_list = []  # 文件夹名列表d
     counter = 1  # 重复计数器
     for fid, name, size, time in dirs:
         if name in dir_name_list:  # 文件夹名前 17 个中文或 34 个英文重复
             counter += 1
             name = f'{name}({counter})'
         else:
             counter = 1
         dir_name_list.append(name)
         all_dir_list.append(RecFolder(name, int(fid), size, time, None))
     return all_dir_list
示例#3
0
文件: core.py 项目: ylsmt/lanzou-gui
 def get_move_folders(self) -> FolderList:
     """获取全部文件夹 id-name 列表,用于移动文件至新的文件夹"""
     # 这里 file_id 可以为任意值,不会对结果产生影响
     result = FolderList()
     result.append(FolderId(name='LanZouCloud', id=-1))
     resp = self._post(self._doupload_url, data={"task": 19, "file_id": -1})
     if not resp or resp.json()['zt'] != 1:  # 获取失败或者网络异常
         return result
     for folder in resp.json()['info']:
         folder_id, folder_name = int(folder['folder_id']), folder['folder_name']
         result.append(FolderId(folder_name, folder_id))
     return result
示例#4
0
文件: core.py 项目: ylsmt/lanzou-gui
    def get_move_paths(self) -> List[FolderList]:
        """获取所有文件夹的绝对路径(耗时长)"""
        result = []
        root = FolderList()
        root.append(FolderId('LanZouCloud', -1))
        result.append(root)
        resp = self._post(self._doupload_url, data={"task": 19, "file_id": -1})
        if not resp or resp.json()['zt'] != 1:  # 获取失败或者网络异常
            return result

        ex = ThreadPoolExecutor()  # 线程数 min(32, os.cpu_count() + 4)
        id_list = [int(folder['folder_id']) for folder in resp.json()['info']]
        task_list = [ex.submit(self.get_full_path, fid) for fid in id_list]
        for task in as_completed(task_list):
            result.append(task.result())
        return sorted(result)
示例#5
0
文件: core.py 项目: ylsmt/lanzou-gui
 def get_rec_all(self):
     """获取整理后回收站的所有信息"""
     root_files = self.get_rec_file_list()  # 回收站根目录文件列表
     folder_list = FolderList()  # 保存整理后的文件夹列表
     for folder in self.get_rec_dir_list():  # 遍历所有子文件夹
         this_folder = RecFolder(folder.name, folder.id, folder.size, folder.time, FileList())
         for file in self.get_rec_file_list(folder.id):  # 文件夹内的文件属性: name,id,type,size
             if root_files.find_by_id(file.id):  # 根目录存在同名文件
                 file_time = root_files.pop_by_id(file.id).time  # 从根目录删除, time 信息用来补充文件夹中的文件
                 file = file._replace(time=file_time)  # 不能直接更新 namedtuple, 需要 _replace
                 this_folder.files.append(file)
             else:  # 根目录没有同名文件(用户手动删了),文件还在文件夹中,只是根目录不显示,time 信息无法补全了
                 file = file._replace(time=folder.time)  # 那就设置时间为文件夹的创建时间
                 this_folder.files.append(file)
         folder_list.append(this_folder)
     return root_files, folder_list
示例#6
0
文件: core.py 项目: ylsmt/lanzou-gui
 def get_full_path(self, folder_id=-1) -> FolderList:
     """获取文件夹完整路径"""
     path_list = FolderList()
     path_list.append(FolderId('LanZouCloud', -1))
     html = self._get(self._mydisk_url, params={'item': 'files', 'action': 'index', 'folder_id': folder_id})
     if not html:
         return path_list
     html = remove_notes(html.text)
     path = re.findall(r'&raquo;&nbsp;.+?folder_id=(\d+)">.+?&nbsp;(.+?)</a>', html)
     for fid, name in path:
         path_list.append(FolderId(name, int(fid)))
     # 获取当前文件夹名称
     if folder_id != -1:
         current_folder = re.search(r'align="(top|absmiddle)" />&nbsp;(.+?)\s<(span|font)', html).group(2).replace(
             '&amp;', '&')
         path_list.append(FolderId(current_folder, folder_id))
     return path_list