<commit_before># -*- coding: utf-8 -*-
# Copyright (c) 2015, imageio contributors
# imageio is distributed under the terms of the (new) BSD License.

""" Plugin that uses ffmpeg to read and write series of images to
a wide range of video formats.

Code inspired/based on code from moviepy: https://github.com/Zulko/moviepy/
by Zulko

"""

from __future__ import absolute_import, print_function, division

import sys
import os
import stat
import re
import time
import threading
import subprocess as sp
import logging

import numpy as np

from .. import formats
from ..core import (Format, get_remote_file, string_types, read_n_bytes,
                    image_as_uint, get_platform, CannotReadFrameError,
                    InternetNotAllowedError, NeedDownloadError)

FNAME_PER_PLATFORM = {
    'osx32': 'ffmpeg-osx-v3.3.1',
    'osx64': 'ffmpeg-osx-v3.3.1',
    'win32': 'ffmpeg-win32-v3.2.4.exe',
    'win64': 'ffmpeg-win32-v3.2.4.exe',
    'linux32': 'ffmpeg-linux32-v3.3.1',
    'linux64': 'ffmpeg-linux64-v3.3.1',
}


def limit_lines(lines, N=32):
    """ When number of lines > 2*N, reduce to N.
    """
    if len(lines) > 2*N:
        lines = [b'... showing only last few lines ...'] + lines[-N:]
    return lines


def download():
    """ Download the ffmpeg exe to your computer.
    """
    plat = get_platform()
    if not (plat and plat in FNAME_PER_PLATFORM):
        raise RuntimeError("FFMPEG exe isn't available for platform %s" % plat)
    get_remote_file('ffmpeg/' + FNAME_PER_PLATFORM[plat])


def get_exe():
    """ Get ffmpeg exe
    """
    # Is the ffmpeg exe overridden?
    exe = os.getenv('IMAGEIO_FFMPEG_EXE', None)
    if exe:  # pragma: no cover
        return exe

    # Check if ffmpeg is in PATH
    try:
        with open(os.devnull, "w") as null:
            sp.check_call(["ffmpeg", "-version"], stdout=null,
                          stderr=sp.STDOUT)
            return "ffmpeg"
    # ValueError is raised on failure on OS X through Python 2.7.11
    # https://bugs.python.org/issue26083
    except (OSError, ValueError, sp.CalledProcessError):
        pass
    
    plat = get_platform()
    
    # Check if ffmpeg is installed in Python environment
    # (e.g. via conda install ffmpeg -c conda-forge)
    exe = None
    if plat.startswith('win'):
        exe = os.path.join(sys.prefix, 'Library', 'bin', 'ffmpeg.exe')
    # Does the found Python-ffmpeg work?
    if exe and os.path.isfile(exe):
        try:
            with open(os.devnull, "w") as null:
                sp.check_call([exe, "-version"], stdout=null, stderr=sp.STDOUT)
                return exe
        except (OSError, ValueError, sp.CalledProcessError):
            pass
    
    # Finally, try and use the executable that we provide
    if plat and plat in FNAME_PER_PLATFORM:
        try:
            exe = get_remote_file('ffmpeg/' + FNAME_PER_PLATFORM[plat],
                                  auto=False)
            os.chmod(exe, os.stat(exe).st_mode | stat.S_IEXEC)  # executable
            return exe
        except NeedDownloadError:<commit_msg>allow using conda-provided ffmpeg on Unix too<commit_after># -*- coding: utf-8 -*-
# Copyright (c) 2015, imageio contributors
# imageio is distributed under the terms of the (new) BSD License.

""" Plugin that uses ffmpeg to read and write series of images to
a wide range of video formats.

Code inspired/based on code from moviepy: https://github.com/Zulko/moviepy/
by Zulko

"""

from __future__ import absolute_import, print_function, division

import sys
import os
import stat
import re
import time
import threading
import subprocess as sp
import logging

import numpy as np

from .. import formats
from ..core import (Format, get_remote_file, string_types, read_n_bytes,
                    image_as_uint, get_platform, CannotReadFrameError,
                    InternetNotAllowedError, NeedDownloadError)

FNAME_PER_PLATFORM = {
    'osx32': 'ffmpeg-osx-v3.3.1',
    'osx64': 'ffmpeg-osx-v3.3.1',
    'win32': 'ffmpeg-win32-v3.2.4.exe',
    'win64': 'ffmpeg-win32-v3.2.4.exe',
    'linux32': 'ffmpeg-linux32-v3.3.1',
    'linux64': 'ffmpeg-linux64-v3.3.1',
}


def limit_lines(lines, N=32):
    """ When number of lines > 2*N, reduce to N.
    """
    if len(lines) > 2*N:
        lines = [b'... showing only last few lines ...'] + lines[-N:]
    return lines


def download():
    """ Download the ffmpeg exe to your computer.
    """
    plat = get_platform()
    if not (plat and plat in FNAME_PER_PLATFORM):
        raise RuntimeError("FFMPEG exe isn't available for platform %s" % plat)
    get_remote_file('ffmpeg/' + FNAME_PER_PLATFORM[plat])


def get_exe():
    """ Get ffmpeg exe
    """
    # Is the ffmpeg exe overridden?
    exe = os.getenv('IMAGEIO_FFMPEG_EXE', None)
    if exe:  # pragma: no cover
        return exe

    # Check if ffmpeg is in PATH
    try:
        with open(os.devnull, "w") as null:
            sp.check_call(["ffmpeg", "-version"], stdout=null,
                          stderr=sp.STDOUT)
            return "ffmpeg"
    # ValueError is raised on failure on OS X through Python 2.7.11
    # https://bugs.python.org/issue26083
    except (OSError, ValueError, sp.CalledProcessError):
        pass
    
    plat = get_platform()
    
    # Check if ffmpeg is installed in Python environment
    # (e.g. via conda install ffmpeg -c conda-forge)
    exe = None
    if plat.startswith('win'):
        exe = os.path.join(sys.prefix, 'Library', 'bin', 'ffmpeg.exe')
    else:
        exe = os.path.join(sys.prefix, 'bin', 'ffmpeg')
    # Does the found Python-ffmpeg work?
    if exe and os.path.isfile(exe):
        try:
            with open(os.devnull, "w") as null:
                sp.check_call([exe, "-version"], stdout=null, stderr=sp.STDOUT)
                return exe
        except (OSError, ValueError, sp.CalledProcessError):
            pass
    
    # Finally, try and use the executable that we provide
    if plat and plat in FNAME_PER_PLATFORM:
        try:
            exe = get_remote_file('ffmpeg/' + FNAME_PER_PLATFORM[plat],
                                  auto=False)
            os.chmod(exe, os.stat(exe).st_mode | stat.S_IEXEC)  # executable
            return exe
        except NeedDownloadError:
{'fraction_non_alphanumeric': 0.1130016051364366, 'fraction_numerical': 0.017977528089887642, 'mean_word_length': 2.471309192200557, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2611562', 'n_tokens_mistral': 2181, 'n_tokens_neox': 2071, 'n_words': 590}