<commit_before><?php

/**
 * This file is part of ScreenShotr
 *
 * (c) <NAME> <<EMAIL>>
 *
 * This source file is subject to the MIT license that is bundled
 * with this source code in the file LICENSE
 */

namespace ScreenShotr;

use ScreenShotr\Exception\NoFrameException;

/**
 * @author <NAME> <<EMAIL>>
 */
class Core
{
    /**
     * @var string $screenshotDirectory
     */
    public static $screenshotDirectory = '/tmp';

    /**
     * @param $file
     * @param $frameNumber
     *
     * @return string
     * @throws Exception\NoFrameException
     * @throws \Exception
     */
    public static function generateScreenshot($file, $frameNumber)
    {
        if (!file_exists($file)) {
            throw new \Exception("The file '{$file}' does not exist.'");
        }

        $movie = new \ffmpeg_movie($file, false);
        $frame = $movie->getFrame($frameNumber);

        if ($frame === false) {
            throw new NoFrameException("There is no frame located at {$frameNumber} in the movie: {$file}.");
        }

        $gd_image = $frame->toGDImage();
        $file = tempnam(static::$screenshotDirectory, 'ss_');
        if ($file === false) {
            throw new \Exception("Could not create a file in: ".static::$screenshotDirectory);
        }


        imagepng($gd_image, $file);
        imagedestroy($gd_image);

        return $file;
    }
}
<commit_msg>Adding new methods, retuning SplFileInfo instead<commit_after><?php

/**
 * This file is part of ScreenShotr
 *
 * (c) <NAME> <<EMAIL>>
 *
 * This source file is subject to the MIT license that is bundled
 * with this source code in the file LICENSE
 */

namespace ScreenShotr;

use ScreenShotr\Exception\NoFrameException;

/**
 * @author <NAME> <<EMAIL>>
 */
class Core
{
    /**
     * @var string $screenshotDirectory
     */
    public static $screenshotDirectory = '/tmp';

    public static function getMovie($file)
    {
        if (!file_exists($file)) {
            throw new \Exception("The file '{$file}' does not exist.'");
        }

        return new \ffmpeg_movie($file, false);
    }

    /**
     * @param \ffmpeg_movie $movie
     * @param               $frameNumber
     *
     * @return \ffmpeg_frame
     * @throws Exception\NoFrameException
     */
    public static function getFrame(\ffmpeg_movie $movie, $frameNumber)
    {
        $frame = $movie->getFrame($frameNumber);

        if ($frame === false) {
            throw new NoFrameException(
                "There is no frame located at {$frameNumber} in the movie: {$movie->getFilename()}."
            );
        }

        return $frame;
    }

    /**
     * @param \ffmpeg_frame $frame
     *
     * @return \SplFileInfo
     * @throws \Exception
     */
    public static function getScreenshot(\ffmpeg_frame $frame)
    {
        $gd_image = $frame->toGDImage();
        $file     = tempnam(static::$screenshotDirectory, 'ss_');
        if ($file === false) {
            throw new \Exception("Could not create a file in: ".static::$screenshotDirectory);
        }

        imagepng($gd_image, $file);
        imagedestroy($gd_image);

        return new \SplFileInfo($file);
    }

    /**
     * @param $file
     * @param $frameNumber
     *
     * @return string
     * @throws Exception\NoFrameException
     * @throws \Exception
     */
    public static function generateScreenshot($file, $frameNumber)
    {
        return static::getScreenshot(static::getFrame(static::getMovie($file), $frameNumber));
    }

    public static function generateScreenshotEveryFrame($file, $frameCount = 1)
    {
        $movie       = static::getMovie($file);
        $screenShots = [];
        $i           = 1;
        while ($frame = static::getFrame($movie, $i)) {
            $screenShots[$i] = static::getScreenshot($frame);
            $i += $frameCount;
        }

        return $screenShots;
    }
}

{'fraction_non_alphanumeric': 0.13376288659793814, 'fraction_numerical': 0.0005154639175257732, 'mean_word_length': 2.2806424344885885, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 20, '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': '2442747', 'n_tokens_mistral': 1184, 'n_tokens_neox': 1142, 'n_words': 294}