<commit_before>import subprocess
import os


from svtplay_dl.log import log
from svtplay_dl.utils import which


class postprocess(object):
    def __init__(self, stream):
        self.stream = stream
        self.detect = None
        for i in ["ffmpeg", "avconv"]:
            self.detect = which(i)
            if self.detect:
                break


    def mux(self):
        if self.detect is None:
            log.error("Cant detect ffmpeg or avconv. cant mux files without it")
            return
        if self.stream.finished is False:
            return
        orig_filename = self.stream.options.output
        new_name = "{0}.mp4".format(os.path.splitext(self.stream.options.output)[0])

        log.info("Muxing {0} into {1}".format(orig_filename, new_name))
        tempfile = "{0}.temp".format(self.stream.options.output)
        name, ext = os.path.splitext(orig_filename)
        arguments = ["-c", "copy", "-f", "mp4"]
        if ext == "ts":
            arguments += ["-bsf:a", "aac_adtstoasc"]
        arguments += ["-y", tempfile]
        cmd = ["avconv", "-i", orig_filename]
        cmd += arguments
        p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
        stdout, stderr = p.communicate()
        if p.returncode != 0:
            stderr = stderr.decode('utf-8', 'replace')
            msg = stderr.strip().split('\n')[-1]
            log.error("Muxing went wrong: {0}".format(msg))
            return
        log.info("Muxing done. removing the old file.")
        os.remove(self.stream.options.output)
        os.rename(tempfile, new_name)
<commit_msg>postprocess: dont hardcode avconv<commit_after>import subprocess
import os


from svtplay_dl.log import log
from svtplay_dl.utils import which


class postprocess(object):
    def __init__(self, stream):
        self.stream = stream
        self.detect = None
        for i in ["ffmpeg", "avconv"]:
            self.detect = which(i)
            if self.detect:
                break


    def mux(self):
        if self.detect is None:
            log.error("Cant detect ffmpeg or avconv. cant mux files without it")
            return
        if self.stream.finished is False:
            return
        orig_filename = self.stream.options.output
        new_name = "{0}.mp4".format(os.path.splitext(self.stream.options.output)[0])

        log.info("Muxing {0} into {1}".format(orig_filename, new_name))
        tempfile = "{0}.temp".format(self.stream.options.output)
        name, ext = os.path.splitext(orig_filename)
        arguments = ["-c", "copy", "-f", "mp4"]
        if ext == "ts":
            arguments += ["-bsf:a", "aac_adtstoasc"]
        arguments += ["-y", tempfile]
        cmd = [self.detect, "-i", orig_filename]
        cmd += arguments
        p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
        stdout, stderr = p.communicate()
        if p.returncode != 0:
            stderr = stderr.decode('utf-8', 'replace')
            msg = stderr.strip().split('\n')[-1]
            log.error("Muxing went wrong: {0}".format(msg))
            return
        log.info("Muxing done. removing the old file.")
        os.remove(self.stream.options.output)
        os.rename(tempfile, new_name)

{'fraction_non_alphanumeric': 0.13466787989080983, 'fraction_numerical': 0.006672732787382469, 'mean_word_length': 2.211295034079844, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3090397', 'n_tokens_mistral': 1041, 'n_tokens_neox': 1028, 'n_words': 237}