backend/models/youtube.php
/**
     * Process the video url and return details of the video
     * @param $vid
     * @return array|void
     */
Process the video url and return details of the video
@param $vid
@return array|void
Process the video url and return details of the video @param $vid @return array|void
public function processVideo($vid) {
        parse_str(file_get_contents("https://youtube.com/get_video_info?video_id=".$vid),$info);
        $playabilityJson = json_decode($info['player_response']);
        $adaptiveFormats = $playabilityJson->streamingData->adaptiveFormats;
        $IsPlayable = $playabilityJson->playabilityStatus->status;
        if(strtolower($IsPlayable) != 'ok') {
            $log = date("c")." ".$info['player_response']."\n";
            file_put_contents('./video.log', $log, FILE_APPEND);
        }
        $result = array();
        if(!empty($info) && $info['status'] == 'ok' && strtolower($IsPlayable) == 'ok') {
            $i=0;
            foreach($adaptiveFormats as $stream) {
                $streamUrl = $stream->url;
                $type = explode(";", $stream->mimeType);
                $qualityLabel='';
                if(!empty($stream->qualityLabel)) {
                    $qualityLabel = $stream->qualityLabel;
                }
                $videoOptions[$i]['link'] = $streamUrl;
                $videoOptions[$i]['type'] = $type[0];
                $videoOptions[$i]['quality'] = $qualityLabel;
                $i++;
            }
            $result = array('info'=>$info,'videos'=>$videoOptions);
            return $result;
        }
        else {
            return;
        }
    }
public function processVideo ( $ vid ) { parse_str ( file_get_contents ( " https://youtube.com/get_video_info?video_id= " . $ vid ) , $ info ) ; $ playabilityJson = json_decode ( $ info [ 'player_response' ] ) ; $ adaptiveFormats = $ playabilityJson -> streamingData -> adaptiveFormats ; $ IsPlayable = $ playabilityJson -> playabilityStatus -> status ; if ( strtolower ( $ IsPlayable ) != 'ok' ) { $ log = date ( " c " ) . " " . $ info [ 'player_response' ] . " \n " ; file_put_contents ( './video.log' , $ log , FILE_APPEND ) ; } $ result = array ( ) ; if ( ! empty ( $ info ) && $ info [ 'status' ] == 'ok' && strtolower ( $ IsPlayable ) == 'ok' ) { $ i = 0 ; foreach ( $ adaptiveFormats as $ stream ) { $ streamUrl = $ stream -> url ; $ type = explode ( " ; " , $ stream -> mimeType ) ; $ qualityLabel = '' ; if ( ! empty ( $ stream -> qualityLabel ) ) { $ qualityLabel = $ stream -> qualityLabel ; } $ videoOptions [ $ i ] [ 'link' ] = $ streamUrl ; $ videoOptions [ $ i ] [ 'type' ] = $ type [ 0 ] ; $ videoOptions [ $ i ] [ 'quality' ] = $ qualityLabel ; $ i ++ ; } $ result = array ( 'info' => $ info , 'videos' => $ videoOptions ) ; return $ result ; } else { return ; } }
Process the video url and return details of the video
 @param $vid
 @return array|void
Process the video url and return details of the video @param $vid @return array|void
//Checking playable or not //writing to log file