Ejemplo n.º 1
0
    def convert(self, infile, outfile):
        pipe = "/tmp/flac2all_%s-%s" % (uuid.uuid4(), uuid.uuid4())
        os.mkfifo(pipe)
        startTime = time()
        inmetadata = flac().getflacmeta(infile)

        try:
            metastring = self.generate_lame_meta(inmetadata)
        except (UnboundLocalError):
            metastring = []  # If we do not get meta information. leave blank

        stderr = flacdecode(infile, pipe)()
        cmd = [
            "%slame" % ipath.lamepath,
            "--silent",
        ]
        cmd.extend(metastring)
        cmd.extend(self.opts.split(' '))
        cmd.extend([pipe, "%s.mp3" % outfile])

        rc = sp.call(cmd)
        errline = stderr.read().decode('utf-8')
        if os.path.exists(pipe):
            os.unlink(pipe)
        errline = stderr.read()
        errline = errline.upper()

        if rc != 0:
            return [
                infile, outfile, "mp3",
                "ERROR: %s" % errline, -1,
                time() - startTime
            ]

        return [infile, outfile, "mp3", "SUCCESS", 0, time() - startTime]
Ejemplo n.º 2
0
	def convert(self, infile, outfile, logq):
		print("WARNING:  Nero AAC is deprecated and will be removed in a future release")
		startTime = time()
		inmetadata = flac().getflacmeta("\"" + infile + "\"")

		tagcmd = "%sneroAacTag " % ipath.neropath
		try:
			metastring = self.generateNeroTags(inmetadata)
		except(UnboundLocalError):
			metastring = ""

		decoder = flacdecode(infile)()
		encoder = os.popen("%sneroAacEnc %s -if - -of %s.mp4 >/tmp/neroLog" % (
			ipath.neropath,
			self.opts,
			shell().parse_escape_chars(outfile),
		), 'wb', 8192)

		# while data exists in the decoders buffer
		for line in decoder.readlines():
			encoder.write(line)  # write it to the encoders buffer

		decoder.flush()  # if there is any data left in the buffer, clear it
		decoder.close()  # somewhat self explanetory

		encoder.flush()
		encoder.close()

		# Now as the final event, load up the tags
		rc = os.system("%s \"%s.mp4\" %s" % (tagcmd, outfile, metastring))
		if rc != 0:
			logq.put([
				infile,
				outfile,
				"aacNero",
				"WARNING: Could not tag AAC file",
				rc,
				time() - startTime
			])
		else:
			logq.put([
				infile,
				outfile,
				"aacNero",
				"SUCCESS",
				0,
				time() - startTime
			])
Ejemplo n.º 3
0
    def AACPconvert(self, infile, outfile, logq):
        decoder = flacdecode(infile, outfile)()
        encoder = os.popen(
            "%saac-enc %s - \"%s.aac\" > /tmp/aacplusLog" % (
                ipath.aacpath,
                self.opts,
                outfile,
            ), 'wb', 8192)

        # while data exists in the decoders buffer
        for line in decoder.readlines():
            encoder.write(line)  # write it to the encoders buffer

        decoder.flush()
        decoder.close()
        encoder.flush()
        encoder.close()
Ejemplo n.º 4
0
    def mp3convert(self, infile, outfile, logq):
        pipe = "/tmp/flac2all_%s" % str(uuid.uuid4()).strip()
        startTime = time()
        inmetadata = flac().getflacmeta(infile)
        os.mkfifo(pipe)

        try:
            metastring = self.generate_lame_meta(inmetadata)
        except(UnboundLocalError):
            metastring = []  # If we do not get meta information. leave blank

        (decoder, stderr) = flacdecode(infile, pipe)()
        cmd = [
            "%slame" % ipath.lamepath,
            "--silent",
        ]
        cmd.extend(metastring)
        cmd.extend(self.opts.split(' '))
        cmd.extend([pipe, "%s.mp3" % outfile])

        rc = sp.check_call(cmd)
        os.unlink(pipe)
        errline = stderr.read()
        errline = errline.upper()
        if errline.strip() != '':
            print "ERRORLINE: %s" % errline
        if errline.find("ERROR") != -1 or rc != 0:
            logq.put([
                infile,
                "mp3",
                "ERROR: decoder error: %s" % (
                    errline, -1,
                    time() - startTime
                )],
                timeout=10)
            return False

        logq.put([
            infile,
            outfile,
            "mp3",
            "SUCCESS",
            0,
            time() - startTime
        ])
Ejemplo n.º 5
0
	def convert(self, infile, outfile):
		pipe = "/tmp/flac2all_%s" % str(uuid.uuid4()).strip()
		startTime = time()
		stderr = flacdecode(infile, pipe)()
		error = ""
		cmd = [
			"%saac-enc" % ipath.aacpath,
		]
		cmd.extend(self.opts.split(' '))
		cmd.extend([
			pipe,
			"%s.aac" % outfile
		])
		procinst = sp.run(cmd, check=False, stdout=sp.PIPE, stderr=sp.PIPE)
		enc_rc = procinst.returncode

		try:
			procinst.check_returncode()
		except sp.CalledProcessError as e:
			enc_rc = e.returncode
			error = "cmd: %s, rc: %d, stderr: %s" % (' '.join(cmd), enc_rc, stderr.read())

		if enc_rc == 0:
			return [
				infile,
				outfile,
				"aacplus",
				"SUCCESS",
				0,
				time() - startTime
			]
		else:
			if procinst is not None:
				error += "stderr:'%s'" % procinst.stderr.decode("utf-8").strip()
			return [
				infile,
				outfile,
				"aacplus",
				"ERROR: %s" % error,
				enc_rc,
				time() - startTime
			]
Ejemplo n.º 6
0
    def opusConvert(self, infile, outfile, logq):
        # As the new versions of opus support flac natively, I think that the
        # best option is to
        # use >0.1.7 by default, but support earlier ones without tagging.
        startTime = time()

        if self.version is None:
            print "ERROR! Could not discover opus version, assuming version >=\
                0.1.7. THIS MAY NOT WORK!"

            version = (9, 9, 9)
        else:
            version = self.version

        # If we are a release prior to 0.1.7, use non-tagging type conversion,
        # with warning
        result = None
        if (version[0] == 0) and (version[1] <= 1) and (version[2] <= 6):
            print "WARNING: Opus version prior to 0.1.7 detected,\
                NO TAGGING SUPPORT"

            decoder = flacdecode(infile)()
            encoder = sp.Popen([
                "%sopusenc" % ipath.opusencpath,
                "%s" % self.opts,
                "-",
                "%s.opus" % outfile,
            ],
                               bufsize=8192,
                               stdin=sp.PIPE).stdin

            # while data exists in the decoders buffer
            for line in decoder.readlines():
                encoder.write(line)  # write it to the encoders buffer

                # if there is any data left in the buffer, clear it
                decoder.flush()
                decoder.close()  # somewhat self explanetory

                encoder.flush()  # as above
                encoder.close()
            result = "SUCCESS_NOTAGGING"
        else:
            # Later versions support direct conversion from flac->opus, so no
            # need for the above.
            cmd = [
                "%sopusenc" % ipath.opusencpath,
                "--quiet",
            ]
            if self.opts.strip() != "":
                cmd.extend(
                    filter(lambda x: x.strip() != "", self.opts.split(' ')))

            cmd.extend([infile, "%s.opus" % (outfile)])

            try:
                rc = sp.check_call(cmd)
                result = "SUCCESS"
            except sp.CalledProcessError as e:
                rc = e.returncode
                result = "ERROR: opusenc error '%s'. Could not convert" % (
                    e.message)
        logq.put([infile, outfile, "opus", result, rc, time() - startTime])