youtube - PHP Online
Form of PHP Sandbox
*** This page was generated with the meta tag "noindex, nofollow". This happened because you selected this option before saving or the system detected it as spam. This means that this page will never get into the search engines and the search bot will not crawl it. There is nothing to worry about, you can still share it with anyone.
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.
Result of php executing
Full code of youtube.php
- <?php
- /*
- ! ]
- */
- ob_start("ob_gzhandler");
- error_reporting(0);
- set_time_limit(0);
- ob_implicit_flush(1);
- define("API_KEY","5409461569:AAEnwNDkxj-Qg7NZYZFU6T08QtoIE0V8T2Q"); // TOKEN BOT
- ////////CODE////////
- function bot($method,$datas=[]){
- $url = 'https://api.telegram.org/bot'.API_KEY.'/'.$method;
- $ch = curl_init();
- curl_setopt($ch,CURLOPT_URL,$url);
- curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
- curl_setopt($ch,CURLOPT_POSTFIELDS,$datas);
- $res = curl_exec($ch);
- if(curl_error($ch)){
- var_dump(curl_error($ch));
- }else{
- return json_decode($res);
- }
- }
- /////////////sendmessage///////
- function sendmessage($chatid,$text,$parsmode =NULL,$dwpr =NULL,$keyboard = NULL){
- bot('sendmessage',[
- 'chat_id' =>$chatid,
- 'text'=>$text,
- 'parse_mode'=>$parsmode,
- 'disable_web_page_preview'=>$dwpr,
- 'reply_markup'=>$keyboard
- ]);
- }
- //////////mysql////////
- $db=mysqli_connect('localhost','bsfgqymf_you','ON?Z-u_xcVOM','bsfgqymf_you');
- $db->query("SET NAMES 'utf8'");
- $db->query("SET CHARACTER SET utf8mb4");
- $db->query("SET SESSION collation_connection = 'utf8mb4_unicode_ci'");
- if (mysqli_connect_errno()){
- echo "به دلیل مشکل زیر، اتصال برقرار نشد : <br />" .mysqli_connect_error();
- }
- ///////table//////
- $users_db= $db->query("select * FROM users");
- if($users_db== false){mysqli_multi_query($db, "CREATE TABLE `users`
- (`id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
- `step` varchar(500) DEFAULT NULL,
- `chat_id` int(11) DEFAULT NULL)default charset = utf8mb4");}
- ////////motaghaer////////
- $update = json_decode(file_get_contents("php://input"));
- $message = $update->message;
- $from_id = $message->from->id;
- $chat_id = $message->chat->id;
- $text = $message->text;
- $fi_name = $message->from->first_name;
- $la_name = $message->from->last_name;
- $us_name = $message->from->username;
- $data = $update->callback_query->data;
- $chatid = $update->callback_query->message->chat->id;
- $fromid = $update->callback_query->from->id;
- $messageid = $update->callback_query->message->message_id;
- //////////////
- $sql_get_data = mysqli_query($db,"SELECT * FROM `users` WHERE chat_id='$chat_id'");
- $num = mysqli_num_rows($sql_get_data);
- $fetch = mysqli_fetch_array($sql_get_data);
- $step = $fetch['step'];
- ////////////
- if($text=="/start"){
- if($num==0 && $chat_id!=NULL){
- mysqli_query($db,"INSERT INTO `users`(chat_id,step) VALUES ($chat_id,'none')");
- bot('sendmessage',[
- 'chat_id'=>$chat_id,
- 'text'=>"سلام خوش آمدید",
- 'reply_markup'=>json_encode([
- 'keyboard'=>[
- [['text'=>'download youtube']],
- ],
- 'resize_keyboard'=>true,
- ])
- ]);
- }else{
- $db->query("UPDATE `users` SET `step`='none' WHERE chat_id='$chat_id'");
- bot('sendmessage',[
- 'chat_id'=>$chat_id,
- 'text'=>"کاربر عزیز شما قبلا در ربات بودید !!
- ",
- 'reply_markup'=>json_encode([
- 'keyboard'=>[
- [['text'=>'download youtube']],
- ],
- 'resize_keyboard'=>true,
- ])
- ]);
- die();
- }
- }
- if($text == "download youtube"){
- $db->query("UPDATE users SET step = 'youtube' WHERE chat_id = '$chat_id'");
- bot(sendmessage,[
- 'chat_id'=>$from_id,
- 'text'=>"لطفا لینک فیلم یوتوب خود را وارد کنید
- ",
- ]);
- die();
- }
- if($step == "youtube"){
- $get = json_decode(file_get_contents("https://vin-mee.com/wbs/youtube/index.php?url=" . urlencode($text)),true);
- $title = $get['title'];
- $photo = $get['photo'];
- $time = $get['duration'];
- $you360 = $get['download']['360'];
- $you720 = $get['download']['720'];
- if($title == null or $time == null){
- bot('sendmessage',[
- 'chat_id'=>$from_id,
- 'text'=>"لینک اشتباه میباشد",
- 'parse_mode'=>"Markdown",
- ]);
- }else{
- bot('sendphoto',[
- 'chat_id'=>$from_id,
- 'photo'=>$text,
- 'caption'=>"
- درخاست انجام شد
- موضوع فیلم : $title
- زمان فیلم : $time
- ",
- 'reply_markup'=>json_encode(['resize_keyboard' => true,
- 'inline_keyboard'=>[
- [['text' => "Download 360", 'url' => "$you360"]],
- [['text' => "Download 720", 'url' => "$you720"]],
- ]])
- ]);
- die();
- }
- }
- ?>