コード例 #1
0
ファイル: nzbToMediaUtil.py プロジェクト: nikagl/nzbToMedia
def extractFiles(src, dst=None, keep_archive=None):
    extracted_folder = []
    extracted_archive = []

    for inputFile in listMediaFiles(src, media=False, audio=False, meta=False, archives=True):
        dirPath = os.path.dirname(inputFile)
        fullFileName = os.path.basename(inputFile)
        archiveName = os.path.splitext(fullFileName)[0]
        archiveName = re.sub(r"part[0-9]+", "", archiveName)

        if dirPath in extracted_folder and archiveName in extracted_archive:
            continue  # no need to extract this, but keep going to look for other archives and sub directories.

        try:
            if extractor.extract(inputFile, dst or dirPath):
                extracted_folder.append(dirPath)
                extracted_archive.append(archiveName)
        except Exception:
            logger.error("Extraction failed for: {0}".format(fullFileName))

    for folder in extracted_folder:
        for inputFile in listMediaFiles(folder, media=False, audio=False, meta=False, archives=True):
            fullFileName = os.path.basename(inputFile)
            archiveName = os.path.splitext(fullFileName)[0]
            archiveName = re.sub(r"part[0-9]+", "", archiveName)
            if archiveName not in extracted_archive or keep_archive:
                continue  # don't remove if we haven't extracted this archive, or if we want to preserve them.
            logger.info("Removing extracted archive {0} from folder {1} ...".format(fullFileName, folder))
            try:
                if not os.access(inputFile, os.W_OK):
                    os.chmod(inputFile, stat.S_IWUSR)
                os.remove(inputFile)
                time.sleep(1)
            except Exception as e:
                logger.error("Unable to remove file {0} due to: {1}".format(inputFile, e))
コード例 #2
0
def extractFiles(src, dst=None, keep_archive=None):
    extracted_folder = []
    extracted_archive = []

    for inputFile in listMediaFiles(src, media=False, audio=False, meta=False, archives=True):
        dirPath = os.path.dirname(inputFile)
        fullFileName = os.path.basename(inputFile)
        archiveName = os.path.splitext(fullFileName)[0]
        archiveName = re.sub(r"part[0-9]+", "", archiveName)

        if dirPath in extracted_folder and archiveName in extracted_archive:
            continue  # no need to extract this, but keep going to look for other archives and sub directories.

        try:
            if extractor.extract(inputFile, dst or dirPath):
                extracted_folder.append(dirPath)
                extracted_archive.append(archiveName)
        except Exception:
            logger.error("Extraction failed for: {0}".format(fullFileName))

    for folder in extracted_folder:
        for inputFile in listMediaFiles(folder, media=False, audio=False, meta=False, archives=True):
            fullFileName = os.path.basename(inputFile)
            archiveName = os.path.splitext(fullFileName)[0]
            archiveName = re.sub(r"part[0-9]+", "", archiveName)
            if archiveName not in extracted_archive or keep_archive:
                continue  # don't remove if we haven't extracted this archive, or if we want to preserve them.
            logger.info("Removing extracted archive {0} from folder {1} ...".format(fullFileName, folder))
            try:
                if not os.access(inputFile, os.W_OK):
                    os.chmod(inputFile, stat.S_IWUSR)
                os.remove(inputFile)
                time.sleep(1)
            except Exception as e:
                logger.error("Unable to remove file {0} due to: {1}".format(inputFile, e))
コード例 #3
0
def extractFiles(src, dst=None, keep_archive = None):
    extracted_folder = []
    extracted_archive = []

    for inputFile in listMediaFiles(src, media=False, audio=False, meta=False, archives=True):
        dirPath = os.path.dirname(inputFile)
        fullFileName = os.path.basename(inputFile)
        archiveName = os.path.splitext(fullFileName)[0]
        archiveName = re.sub(r"part[0-9]+", "", archiveName)

        if dirPath in extracted_folder and archiveName in extracted_archive:
            continue  # no need to extract this, but keep going to look for other archives and sub directories.

        try:
            if extractor.extract(inputFile, dst or dirPath):
                extracted_folder.append(dst or dirPath)
                extracted_archive.append(archiveName)
        except Exception, e:
            logger.error("Extraction failed for: %s" % (fullFileName))
コード例 #4
0
def extractFiles(src, dst=None, keep_archive = None):
    extracted_folder = []
    extracted_archive = []

    for inputFile in listMediaFiles(src, media=False, audio=False, meta=False, archives=True):
        dirPath = os.path.dirname(inputFile)
        fullFileName = os.path.basename(inputFile)
        archiveName = os.path.splitext(fullFileName)[0]
        archiveName = re.sub(r"part[0-9]+", "", archiveName)

        if dirPath in extracted_folder and archiveName in extracted_archive:
            continue  # no need to extract this, but keep going to look for other archives and sub directories.

        try:
            if extractor.extract(inputFile, dst or dirPath):
                extracted_folder.append(dst or dirPath)
                extracted_archive.append(archiveName)
        except Exception, e:
            logger.error("Extraction failed for: %s" % (fullFileName))