youtube - PHP Online

Form of PHP Sandbox

Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php in the places where the PHP script should be executed.



Your result can be seen below.

Result of php executing





Full code of youtube.php

  1. <?php
  2. /*
  3. ! ]
  4. */
  5.   ob_start("ob_gzhandler");
  6.   error_reporting(0);
  7.   set_time_limit(0);
  8.   ob_implicit_flush(1);
  9.   
  10.   define("API_KEY","5409461569:AAEnwNDkxj-Qg7NZYZFU6T08QtoIE0V8T2Q"); // TOKEN BOT
  11.   ////////CODE////////
  12.   function bot($method,$datas=[]){
  13.       $url = 'https://api.telegram.org/bot'.API_KEY.'/'.$method;
  14.       $ch = curl_init();
  15.       curl_setopt($ch,CURLOPT_URL,$url);
  16.       curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
  17.       curl_setopt($ch,CURLOPT_POSTFIELDS,$datas);
  18.       $res = curl_exec($ch);
  19.       if(curl_error($ch)){
  20.           var_dump(curl_error($ch));
  21.       }else{
  22.           return json_decode($res);
  23.       }
  24.   }
  25.   
  26.   
  27.   /////////////sendmessage///////
  28.   
  29.   function sendmessage($chatid,$text,$parsmode =NULL,$dwpr =NULL,$keyboard = NULL){
  30.       bot('sendmessage',[
  31.           'chat_id' =>$chatid,
  32.           'text'=>$text,
  33.           'parse_mode'=>$parsmode,
  34.           'disable_web_page_preview'=>$dwpr,
  35.           'reply_markup'=>$keyboard
  36.   
  37.   
  38.       ]);
  39.   }
  40.   
  41.   //////////mysql////////
  42.   
  43.   $db=mysqli_connect('localhost','bsfgqymf_you','ON?Z-u_xcVOM','bsfgqymf_you');
  44.       $db->query("SET NAMES 'utf8'");
  45.       $db->query("SET CHARACTER SET utf8mb4");
  46.       $db->query("SET SESSION collation_connection = 'utf8mb4_unicode_ci'");
  47.       if (mysqli_connect_errno()){
  48.           echo "به دلیل مشکل زیر، اتصال برقرار نشد : <br />" .mysqli_connect_error();
  49.       
  50.       }
  51.       
  52.       
  53.       
  54.       
  55.       ///////table//////
  56.       
  57.   $users_db= $db->query("select * FROM users");
  58.   if($users_db== false){mysqli_multi_query($db, "CREATE TABLE `users`
  59.   (`id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
  60.   `step` varchar(500) DEFAULT NULL,
  61.   `chat_id` int(11) DEFAULT NULL)default charset = utf8mb4");}
  62.   
  63.   
  64.   
  65.   ////////motaghaer////////
  66.   $update  = json_decode(file_get_contents("php://input"));
  67.   $message = $update->message;
  68.   $from_id = $message->from->id;
  69.   $chat_id = $message->chat->id;
  70.   $text    = $message->text;
  71.   $fi_name = $message->from->first_name;
  72.   $la_name = $message->from->last_name;
  73.   $us_name = $message->from->username;
  74.   $data    = $update->callback_query->data;
  75.   $chatid  = $update->callback_query->message->chat->id;
  76.   $fromid  = $update->callback_query->from->id;
  77.   $messageid = $update->callback_query->message->message_id;
  78.   
  79.   
  80.   
  81.   
  82.   
  83.   
  84.   
  85.   
  86.   
  87.   //////////////
  88.   $sql_get_data = mysqli_query($db,"SELECT * FROM `users` WHERE chat_id='$chat_id'");
  89.   $num          = mysqli_num_rows($sql_get_data);
  90.   $fetch        = mysqli_fetch_array($sql_get_data);
  91.   $step         = $fetch['step'];
  92.   
  93.   
  94.   ////////////
  95.   
  96.   if($text=="/start"){
  97.       if($num==0 && $chat_id!=NULL){
  98.       mysqli_query($db,"INSERT INTO `users`(chat_id,step) VALUES ($chat_id,'none')");
  99.       
  100.       bot('sendmessage',[
  101.           'chat_id'=>$chat_id,
  102.           'text'=>"سلام خوش آمدید",
  103.          'reply_markup'=>json_encode([
  104.           'keyboard'=>[
  105.               [['text'=>'download youtube']],
  106.               ],
  107.           'resize_keyboard'=>true,
  108.                        ])
  109.                       
  110.                        ]);
  111.               
  112.       
  113.   
  114.   }else{
  115.       $db->query("UPDATE `users` SET `step`='none' WHERE chat_id='$chat_id'");
  116.       bot('sendmessage',[
  117.           'chat_id'=>$chat_id,
  118.           'text'=>"کاربر عزیز شما قبلا در ربات بودید !!
  119.           ",
  120.          'reply_markup'=>json_encode([
  121.           'keyboard'=>[
  122.               [['text'=>'download youtube']],
  123.               ],
  124.           'resize_keyboard'=>true,
  125.                        ])
  126.           
  127.   
  128.       ]);
  129.       die();
  130.   
  131.   }
  132.   }
  133.  
  134. if($text == "download youtube"){ 
  135.     $db->query("UPDATE users SET step = 'youtube' WHERE chat_id = '$chat_id'"); 
  136.     bot(sendmessage,[ 
  137.       'chat_id'=>$from_id, 
  138.       'text'=>"لطفا لینک فیلم یوتوب خود را  وارد کنید
  139.      ",
  140.       ]);
  141.       die();
  142.   
  143.   }
  144.    
  145.    
  146.   if($step == "youtube"){ 
  147.   $get = json_decode(file_get_contents("https://vin-mee.com/wbs/youtube/index.php?url=" . urlencode($text)),true); 
  148.   $title = $get['title']; 
  149.   $photo = $get['photo']; 
  150.   $time = $get['duration']; 
  151.   $you360 = $get['download']['360']; 
  152.   $you720 = $get['download']['720']; 
  153.    
  154.   if($title == null or $time == null){ 
  155.       bot('sendmessage',[ 
  156.         'chat_id'=>$from_id, 
  157.         'text'=>"لینک اشتباه میباشد", 
  158.         'parse_mode'=>"Markdown", 
  159.         ]); 
  160.   }else{ 
  161.   bot('sendphoto',[ 
  162.       'chat_id'=>$from_id, 
  163.       'photo'=>$text, 
  164. 'caption'=>"
  165.       درخاست انجام شد 
  166.        
  167.       موضوع فیلم : $title 
  168.        
  169.       زمان فیلم : $time 
  170.        
  171.      
  172.        
  173.        
  174.       ", 
  175.       'reply_markup'=>json_encode(['resize_keyboard' => true, 
  176.   'inline_keyboard'=>[ 
  177.   [['text' => "Download 360", 'url' => "$you360"]], 
  178.   [['text' => "Download 720", 'url' => "$you720"]], 
  179.   ]]) 
  180.      
  181.    
  182.        
  183.       ]); 
  184.      
  185.    
  186.        
  187.       die(); 
  188.   } 
  189.     } 
  190.   
  191.   ?>
  192.   
  193.   
  194.   
  195.   
  196.   
File Description
  • youtube
  • PHP Code
  • 03 Jul-2022
  • 4.94 Kb
You can Share it: