<commit_before><?php
namespace frontend\controllers;

use common\models\Video;
use darkdrim\simplehtmldom\SimpleHTMLDom;
use frontend\components\YoutubeAPI;
use frontend\models\FindVideoForm;
use frontend\models\YoutubeVideo;
use Yii;
use yii\base\InvalidParamException;
use yii\data\ActiveDataProvider;
use yii\web\BadRequestHttpException;
use yii\web\Controller;
use yii\filters\VerbFilter;
use yii\filters\AccessControl;
use common\models\LoginForm;
use frontend\models\PasswordResetRequestForm;
use frontend\models\ResetPasswordForm;
use frontend\models\SignupForm;
use frontend\models\ContactForm;
use yii\web\NotFoundHttpException;

/**
 * Site controller
 */
class SiteController extends Controller
{
    /**
     * @inheritdoc
     */
    public function behaviors()
    {
        return [
            'access' => [
                'class' => AccessControl::className(),
                'only' => ['logout', 'signup'],
                'rules' => [
                    [
                        'actions' => ['signup'],
                        'allow' => true,
                        'roles' => ['?'],
                    ],
                    [
                        'actions' => ['logout'],
                        'allow' => true,
                        'roles' => ['@'],
                    ],
                ],
            ],
            'verbs' => [
                'class' => VerbFilter::className(),
                'actions' => [
                    'logout' => ['post'],
                ],
            ],
        ];
    }

    /**
     * @inheritdoc
     */
    public function actions()
    {
        return [
            'error' => [
                'class' => 'yii\web\ErrorAction',
            ],
            'captcha' => [
                'class' => 'yii\captcha\CaptchaAction',
                'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,
            ],
        ];
    }

    /**
     * Displays homepage.
     *
     * @return mixed
     */
    public function actionIndex()
    {
        return $this->render('index', [
            'lastAddedProvider' =>  new ActiveDataProvider([
                'query' =>  Video::find()->where('views > 500000'),
                'sort'  =>  [
                    'defaultOrder'  =>  [
                        'checked' =>  SORT_DESC
                    ]
                ]
            ])
        ]);
    }

    public function actionSearchVideo($hash = null){
        $video = new Video();

        if(!empty(\Yii::$app->request->post("FindVideoForm")) && empty($hash)){
            $findVideoForm = new FindVideoForm();
            $findVideoForm->load(\Yii::$app->request->post());
            
            $video = Video::findOne(['youtubeID' => $findVideoForm->videoID]);

            if(!$video){
                $video = new YoutubeVideo();

                $video->link = $findVideoForm->url;

                if(!$video->parse()){
                    throw new NotFoundHttpException("Не удалось распознать видео");
                }

                $video = $video->save();
            }

            $this->redirect('/search-video/'.$video->youtubeID);
        }

        if($hash){
            $video = Video::findOne(['youtubeID' => $hash]);

            if(!$video){
                throw new NotFoundHttpException("Видео не найдено!");
            }
        }

        if($video->isNewRecord){
            throw new NotFoundHttpException("Видео не найдено!");
        }

        if(strtotime($video->checked) - 3600 > strtotime(time())){
            $api = new YoutubeAPI();

            $video->applyApiData($api->getVideos($video->youtubeID));

            $video->save(false);<commit_msg>fix video autoupdate<commit_after><?php
namespace frontend\controllers;

use common\models\Video;
use darkdrim\simplehtmldom\SimpleHTMLDom;
use frontend\components\YoutubeAPI;
use frontend\models\FindVideoForm;
use frontend\models\YoutubeVideo;
use Yii;
use yii\base\InvalidParamException;
use yii\data\ActiveDataProvider;
use yii\web\BadRequestHttpException;
use yii\web\Controller;
use yii\filters\VerbFilter;
use yii\filters\AccessControl;
use common\models\LoginForm;
use frontend\models\PasswordResetRequestForm;
use frontend\models\ResetPasswordForm;
use frontend\models\SignupForm;
use frontend\models\ContactForm;
use yii\web\NotFoundHttpException;

/**
 * Site controller
 */
class SiteController extends Controller
{
    /**
     * @inheritdoc
     */
    public function behaviors()
    {
        return [
            'access' => [
                'class' => AccessControl::className(),
                'only' => ['logout', 'signup'],
                'rules' => [
                    [
                        'actions' => ['signup'],
                        'allow' => true,
                        'roles' => ['?'],
                    ],
                    [
                        'actions' => ['logout'],
                        'allow' => true,
                        'roles' => ['@'],
                    ],
                ],
            ],
            'verbs' => [
                'class' => VerbFilter::className(),
                'actions' => [
                    'logout' => ['post'],
                ],
            ],
        ];
    }

    /**
     * @inheritdoc
     */
    public function actions()
    {
        return [
            'error' => [
                'class' => 'yii\web\ErrorAction',
            ],
            'captcha' => [
                'class' => 'yii\captcha\CaptchaAction',
                'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,
            ],
        ];
    }

    /**
     * Displays homepage.
     *
     * @return mixed
     */
    public function actionIndex()
    {
        return $this->render('index', [
            'lastAddedProvider' =>  new ActiveDataProvider([
                'query' =>  Video::find()->where('views > 500000'),
                'sort'  =>  [
                    'defaultOrder'  =>  [
                        'checked' =>  SORT_DESC
                    ]
                ]
            ])
        ]);
    }

    public function actionSearchVideo($hash = null){
        $video = new Video();

        if(!empty(\Yii::$app->request->post("FindVideoForm")) && empty($hash)){
            $findVideoForm = new FindVideoForm();
            $findVideoForm->load(\Yii::$app->request->post());
            
            $video = Video::findOne(['youtubeID' => $findVideoForm->videoID]);

            if(!$video){
                $video = new YoutubeVideo();

                $video->link = $findVideoForm->url;

                if(!$video->parse()){
                    throw new NotFoundHttpException("Не удалось распознать видео");
                }

                $video = $video->save();
            }

            $this->redirect('/search-video/'.$video->youtubeID);
        }

        if($hash){
            $video = Video::findOne(['youtubeID' => $hash]);

            if(!$video){
                throw new NotFoundHttpException("Видео не найдено!");
            }
        }

        if($video->isNewRecord){
            throw new NotFoundHttpException("Видео не найдено!");
        }

        if(strtotime($video->checked) < time() - 3600){
            $api = new YoutubeAPI();

            $video->applyApiData($api->getVideos($video->youtubeID));

            $video->save(false);
{'fraction_non_alphanumeric': 0.14437194127243066, 'fraction_numerical': 0.0027188689505165853, 'mean_word_length': 1.4746047763202152, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 98, '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': '4612183', 'n_tokens_mistral': 2093, 'n_tokens_neox': 1988, 'n_words': 327}