def __init__(self, rootDir, cookieDir, fileOf404=None, scfamily=socket.AF_INET, sctype=socket.SOCK_STREAM): """ #Func : 初始化 #Param : rootDir [in] 根目录 #Param : cookieDir [in] cookie目录 #Param : fileOf404 [in] 404文件 #Param : scfamily [in] 网络family #Param : sctype [in] 网络类型 """ rootDir.replace('\\', '/') cookieDir.replace('\\', '/') self.__sockHandle = None self.__sockFamily = scfamily self.__sockType = sctype self.__rootDir = rootDir + '/' self.__cookieDir = cookieDir + '/' self.__fileOf404 = fileOf404 self.__requestFunc = None self.__listenThread = ThreadTool(1) self.__requestThread = ThreadPoolManger(5) self.__revieveLen = 1024
def download(url, descpath, threadnum=15): '''Download file by m3u8-url''' try: urllist = paresUrl(url) if len(urllist) <= 0: return False threads = ThreadTool(threadnum) # Creat tmpdir path = getDirName(descpath) tmpPath = getDiffTmpPathName(path) if mkdirs(tmpPath) is False: return False # Progress progress = ProgressTool(len(urllist), 20) # Download files files = [] for i, item in enumerate(urllist): filepath = tmpPath + '/' + str(i) + '.ts' files.append(filepath) threads.start(__threadfunc__, item, filepath, progress) threads.waitAll() # merger __merger__(files, descpath) shutil.rmtree(tmpPath) threads.close() return True except: shutil.rmtree(tmpPath) return False
def __init__(self, threadNum=3): self.config = TidalConfig() self.tool = TidalTool() self.thread = ThreadTool(int(threadNum)) self.ffmpeg = FFmpegTool(mergerTimeout=45) self.progress = ProgressTool(100) self.check = CheckTool() self.showpro = False if self.config.showprogress == 'True': self.showpro = True
def __init__(self, threadNum=3): self.config = TidalConfig() self.tool = TidalTool() self.thread = ThreadTool(int(threadNum)) self.ffmpeg = FFmpegTool(mergerTimeout=45) self.progress = ProgressTool(100) self.check = CheckTool() pathHelper.mkdirs(self.config.outputdir + "/Album/") pathHelper.mkdirs(self.config.outputdir + "/Playlist/") pathHelper.mkdirs(self.config.outputdir + "/Video/") pathHelper.mkdirs(self.config.outputdir + "/Favorite/")
def start(self, showProgress: bool = False, threadNum: int = 10) -> (bool, str): size = len(self.fileUrls) if size == 1: fileSize, parts, msg = self.__getOneUrlParts__(self.fileUrls[0]) elif size > 1: fileSize, parts, msg = self.__getMoreUrlsParts__(self.fileUrls) else: return False, "Urls is empty." if msg != "": return False, msg self.maxSize = fileSize try: check = createEmptyFile(self.filePath, fileSize) if not check: return False, "Create file failed." if self.userProgress is not None: self.userProgress.setMaxNum(fileSize) # thread threads = ThreadTool(threadNum) fileSize, unit = unitFix(fileSize, Unit.BYTE, Unit.MB) # Progress progress = None if showProgress: progress = ProgressTool(fileSize, 15, unit=unit.name) for item in parts: threads.start(__downloadPartFile__, item, self, progress, unit, 3) results = threads.waitAll() threads.close() for item in results: if item[0] is False: return False, "Some parts download failed." + item[1] return True, "" except Exception as e: return False, str(e)