コード例 #1
0
ファイル: classes.py プロジェクト: DINKIN/XDM
 def imgName(self):
     return helper.fileNameClean(u"e%s-%s-%s.%s" % (
         self.element.id,
         self.name,
         self.provider,
         self.type
     ))
コード例 #2
0
ファイル: classes.py プロジェクト: Enjoy14/XDM
 def imgName(self):
     return helper.turn_into_ascii(helper.fileNameClean(u"%s (%s) %s-%s.%s" % (
         helper.replace_all(self.element.getName()),
         self.element.id,
         self.name,
         self.provider,
         self.type
     )))
コード例 #3
0
    def addDownload(self, download):
        b_dir = self._getPath(download.element)
        if not os.path.isdir(b_dir):
            log.info("Could not save %s at %s, it's not a valid folder" % (download, b_dir))
            return False

        file_name = "%s.%s" % (self._downloadName(download), self._getDownloadTypeExtension(download.type))
        dst = os.path.join(b_dir, helper.fileNameClean(file_name))
        r = requests.get(download.url)
        if r.status_code == 200:
            with open(dst, "wb") as f:
                for chunk in r.iter_content():
                    f.write(chunk)
        else:
            log.info("Download save to Blackhole at %s failed" % dst)
            return False

        log.info("Download saved to Blackhole at %s" % dst)
        return True
コード例 #4
0
    def addDownload(self, download):
        b_dir = self._getPath(download.element)
        if not os.path.isdir(b_dir):
            log.info("Could not save %s at %s, it's not a valid folder" % (download, b_dir))
            return False

        file_name = '%s.%s' % (self._downloadName(download), self._getDownloadTypeExtension(download.type))
        dst = os.path.join(b_dir, helper.fileNameClean(file_name))
        headers = download.extra_data['headers'] if 'headers' in download.extra_data else { }
        r = requests.get(download.url, headers=headers)
        if r.status_code == 200:
            with open(dst, 'wb') as f:
                for chunk in r.iter_content():
                    f.write(chunk)
        else:
            log.info("Download save to Blackhole at %s failed" % dst)
            return False

        log.info("Download saved to Blackhole at %s" % dst)
        return True
コード例 #5
0
class AnimeEpisodeMover(PostProcessor):
    identifier = 'de.lad1337.anime.simplemover'
    version = "0.1"
    types = ["de.uranime.anime"]
    _config = {
        'show_parent_path': "",
        'name_format': '{show_name}/{show_name} - {e#:0>2} - {title}',
    }

    elementConfig = {
        'show_parent_path': 'show_parent_path',
        'name_format': 'name_format'
    }

    screenName = 'Anime Episode Mover'
    addMediaTypeOptions = False
    config_meta = {
        'plugin_desc':
        'This will move the episode based on a format string, format string syntax http://docs.python.org/2/library/string.html#formatspec',
        'name_format': {
            'desc':
            '{show_name}: the show name, {s#}: episode number, {title}: episode title'
        }
    }

    _allowed_extensions = ('.avi', '.mkv', '.iso', '.mp4')

    def postProcessPath(self, element, filePath):
        self.e.getConfigsFor(element)
        if not self.e.show_parent_path:
            msg = "Destination path for %s is not set. Stopping PP." % element
            log.warning(msg)
            return (False, msg)
        # log of the whole process routine from here on except debug
        # this looks hacky: http://stackoverflow.com/questions/7935966/python-overwriting-variables-in-nested-functions
        processLog = [""]

        def processLogger(message):
            log.info(message)
            createdDate = time.strftime("%a %d %b %Y / %X",
                                        time.localtime()) + ": "
            processLog[0] = processLog[0] + createdDate + message + "\n"

        def fixName(name):
            return name.replace(":", " ")

        allEpisodeFileLocations = []
        if os.path.isdir(filePath):
            processLogger("Starting file scan on %s" % filePath)
            for root, dirnames, filenames in os.walk(filePath):
                processLogger("I can see the files %s" % filenames)
                for filename in filenames:
                    if filename.endswith(self._allowed_extensions):
                        if 'sample' in filename.lower():
                            continue
                        curFile = os.path.join(root, filename)
                        allEpisodeFileLocations.append(curFile)
                        processLogger("Found episode: %s" % curFile)
            if not allEpisodeFileLocations:
                processLogger("No files found!")
                return (False, processLog[0])
        else:
            allEpisodeFileLocations = [filePath]

        if len(allEpisodeFileLocations) > 1:
            processLogger(
                "Sorry i found more then one file i don't know what to do...")
            return (False, processLog[0])

        processLogger("Renaming and moving episode")
        success = True

        curFile = allEpisodeFileLocations[0]
        processLogger("Processing episode: %s" % curFile)
        dst = None
        try:
            extension = os.path.splitext(curFile)[1]
            newFileRoute = u"%s%s" % (self._build_file_name(element),
                                      extension)
            processLogger("New Filename shall be: %s" % newFileRoute)

            dst = os.path.join(self.e.show_parent_path, newFileRoute)
            processLogger("Creating folders leading to %s" % dst)
            mkdir_p(os.path.dirname(dst))
            processLogger("Moving File from: %s to: %s" % (curFile, dst))
            shutil.move(curFile, dst)
        except Exception, msg:
            processLogger(
                "Unable to rename and move episode: %s. Please process manually"
                % curFile)
            processLogger("given ERROR: %s" % msg)
            success = False

        processLogger("File processing done")
        # write process log
        logFileName = helper.fileNameClean(u"%s.log" % element.getName())
        logFilePath = os.path.join(filePath, logFileName)
        try:
            # This tries to open an existing file but creates a new file if necessary.
            logfile = open(logFilePath, "a")
            try:
                logfile.write(processLog[0])
            finally:
                logfile.close()
        except IOError:
            pass

        return (success, dst, processLog[0])
コード例 #6
0
 def fixName(name, replaceSpace):
     return helper.fileNameClean(name.replace(" ", replaceSpace))
コード例 #7
0
ファイル: classes.py プロジェクト: ragnvaldur/XDM
 def imgName(self):
     return helper.fileNameClean(u"%s (%s) %s.%s" % (helper.replace_all(
         self.element.getName()), self.element.id, self.name, self.type))
コード例 #8
0
ファイル: classes.py プロジェクト: nekoserv/xdm
 def imgName(self):
     return helper.fileNameClean(u"%s (%s) %s.%s" % (helper.replace_all(self.element.getName()),
                                                     self.element.id,
                                                     self.name,
                                                     self.type))
コード例 #9
0
 def fixName(name, replaceSpace):
     return helper.fileNameClean(name.replace(" ", replaceSpace))
コード例 #10
0
ファイル: classes.py プロジェクト: indigos33k3r/XDM-1
 def imgName(self):
     return helper.fileNameClean(
         u"e%s-%s-%s.%s" %
         (self.element.id, self.name, self.provider, self.type))
コード例 #11
0
ファイル: classes.py プロジェクト: unyxor/XDM
 def imgName(self):
     return helper.turn_into_ascii(
         helper.fileNameClean(
             u"%s (%s) %s-%s.%s" %
             (helper.replace_all(self.element.getName()), self.element.id,
              self.name, self.provider, self.type)))