<commit_before><?php

/**
 * A minds archive video entity
 *
 * Handles basic communication with cinemr
 */

namespace Minds\Entities;

use Minds\Core;
use Minds\Core\Media\Services\Factory as ServiceFactory;
use Minds\Core\Di\Di;
use cinemr;
use Minds\Helpers;
use Minds\Helpers\StringLengthValidators\DescriptionLengthValidator;

/**
 * Class Video
 * @package Minds\Entities
 * @property string $youtube_id
 * @property string $youtube_channel_id
 * @property string $transcoding_status
 * @property string $chosen_format_url
 * @property string $youtube_thumbnail
 * @property string $cinemr_guid
 * @property string $super_subtype
 * @property string $thumbnail
 * @property string $boost_rejection_reason
 * @property string $license
 * @property int $time_sent
 * @property int $width
 * @property int $height
 * @property string $permaweb_id
 * @property bool $full_hd
 * @property bool $mature
 * @property array $nsfw
 * @property int $rating
 */
class Video extends MindsObject
{
    private $cinemr;

    protected function initializeAttributes()
    {
        parent::initializeAttributes();

        $this->attributes['super_subtype'] = 'archive';
        $this->attributes['subtype'] = "video";
        $this->attributes['boost_rejection_reason'] = -1;
        $this->attributes['rating'] = 2;
        $this->attributes['time_sent'] = null;
        $this->attributes['youtube_id'] = null;
        $this->attributes['youtube_channel_id'] = null;
        $this->attributes['transcoding_status'] = null;
        $this->attributes['youtube_thumbnail'] = null; // this is ephemeral
        $this->attributes['transcoder'] = null;
        $this->attributes['cloudflare_id'] = null;
    }


    public function __construct($guid = null)
    {
        parent::__construct($guid);
    }

    /**
     * @param string $transcoder
     * @return self
     */
    public function setTranscoder(string $transcoder): self
    {
        $this->attributes['transcoder'] = $transcoder;
        return $this;
    }

    /**
     * @return string
     */
    public function getTranscoder(): string
    {
        return $this->attributes['transcoder'] ?: 'minds_ffmpeg';
    }

    /**
     * Sets the cloudflare id
     * @param string $id
     * @return self
     */
    public function setCloudflareId($id): self
    {
        $this->attributes['cloudflare_id'] = $id;
        return $this;
    }

    /**
     * Returns the cloudflare id
     * @return string
     */
    public function getCloudflareId(): ?string
    {
        return $this->attributes['cloudflare_id'] ?: null;
    }

    /**
     * Return the source url of the remote video
     * @param string $transcode
     * @return string
     */
    public function getSourceUrl($transcode = '720.mp4')
    {
        $mediaManager = Di::_()->get('Media\Video\Manager');
        return $mediaManager->getPublicAssetUri($this, $transcode);
    }

    /**
     * Uploads to remote
     *
     */

    public function upload($filepath)
    {
        // TODO: Confirm why this is still here
        $this->generateGuid();

        // Upload the source and start the transcoder pipeline
        /** @var Core\Media\Video\Transcoder\Manager $transcoderManager */
        $transcoderManager = Di::_()->get('Media\Video\Transcoder\Manager');
        $transcoderManager->uploadSource($this, $filepath);
        $transcoderManager->createTranscodes($this);

        // Legacy support
        $this->cinemr_guid = $this->getGuid();
    }

    public function getIconUrl($size = "medium")
    {
        // return $domain . 'api/v1/media/thumbnails/' . $this->guid . '/' . $this->time_updated;

        // if we didn't save this and it has a YouTube video ID, return YouTube's thumbnail
        if (!$this->guid && $this->youtube_id) {
            return $this->getYouTubeThumbnail();
        }

        $mediaManager = Di::_()->get('Media\Image\Manager');
        return $mediaManager->getPublicAssetUri($this, 'medium');
    }

    public function getURL()
    {
        return elgg_get_site_url() . 'media/' . $this->guid;<commit_msg>(fix): video thumbnails no longer working<commit_after><?php

/**
 * A minds archive video entity
 *
 * Handles basic communication with cinemr
 */

namespace Minds\Entities;

use Minds\Core;
use Minds\Core\Media\Services\Factory as ServiceFactory;
use Minds\Core\Di\Di;
use cinemr;
use Minds\Helpers;
use Minds\Helpers\StringLengthValidators\DescriptionLengthValidator;

/**
 * Class Video
 * @package Minds\Entities
 * @property string $youtube_id
 * @property string $youtube_channel_id
 * @property string $transcoding_status
 * @property string $chosen_format_url
 * @property string $youtube_thumbnail
 * @property string $cinemr_guid
 * @property string $super_subtype
 * @property string $thumbnail
 * @property string $boost_rejection_reason
 * @property string $license
 * @property int $time_sent
 * @property int $width
 * @property int $height
 * @property string $permaweb_id
 * @property bool $full_hd
 * @property bool $mature
 * @property array $nsfw
 * @property int $rating
 */
class Video extends MindsObject
{
    private $cinemr;

    protected function initializeAttributes()
    {
        parent::initializeAttributes();

        $this->attributes['super_subtype'] = 'archive';
        $this->attributes['subtype'] = "video";
        $this->attributes['boost_rejection_reason'] = -1;
        $this->attributes['rating'] = 2;
        $this->attributes['time_sent'] = null;
        $this->attributes['youtube_id'] = null;
        $this->attributes['youtube_channel_id'] = null;
        $this->attributes['transcoding_status'] = null;
        $this->attributes['youtube_thumbnail'] = null; // this is ephemeral
        $this->attributes['transcoder'] = null;
        $this->attributes['cloudflare_id'] = null;
    }


    public function __construct($guid = null)
    {
        parent::__construct($guid);
    }

    /**
     * @param string $transcoder
     * @return self
     */
    public function setTranscoder(string $transcoder): self
    {
        $this->attributes['transcoder'] = $transcoder;
        return $this;
    }

    /**
     * @return string
     */
    public function getTranscoder(): string
    {
        return $this->attributes['transcoder'] ?: 'minds_ffmpeg';
    }

    /**
     * Sets the cloudflare id
     * @param string $id
     * @return self
     */
    public function setCloudflareId($id): self
    {
        $this->attributes['cloudflare_id'] = $id;
        return $this;
    }

    /**
     * Returns the cloudflare id
     * @return string
     */
    public function getCloudflareId(): ?string
    {
        return $this->attributes['cloudflare_id'] ?: null;
    }

    /**
     * Return the source url of the remote video
     * @param string $transcode
     * @return string
     */
    public function getSourceUrl($transcode = '720.mp4')
    {
        $mediaManager = Di::_()->get('Media\Video\Manager');
        return $mediaManager->getPublicAssetUri($this, $transcode);
    }

    /**
     * Uploads to remote
     *
     */

    public function upload($filepath)
    {
        // TODO: Confirm why this is still here
        $this->generateGuid();

        // Upload the source and start the transcoder pipeline
        /** @var Core\Media\Video\Transcoder\Manager $transcoderManager */
        $transcoderManager = Di::_()->get('Media\Video\Transcoder\Manager');
        $transcoderManager->uploadSource($this, $filepath);
        $transcoderManager->createTranscodes($this);

        // Legacy support
        $this->cinemr_guid = $this->getGuid();
    }

    public function getIconUrl($size = "medium")
    {
        // return $domain . 'api/v1/media/thumbnails/' . $this->guid . '/' . $this->time_updated;

        // if we didn't save this and it has a YouTube video ID, return YouTube's thumbnail
        if (!$this->guid && $this->youtube_id) {
            return $this->getYouTubeThumbnail();
        }

        $mediaManager = Di::_()->get('Media\Image\Manager');
        return $mediaManager->getPublicAssetUris($this, 'medium')[0];
    }

    public function getURL()
    {
        return elgg_get_site_url() . 'media/' . $this->guid;
{'fraction_non_alphanumeric': 0.13405708709441327, 'fraction_numerical': 0.0018297145645279336, 'mean_word_length': 2.7888170055452863, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 65, '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': '7104690', 'n_tokens_mistral': 2451, 'n_tokens_neox': 2401, 'n_words': 554}