forked from anmolduainter/Youtube-Telegram-Bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathYoutube.php
96 lines (76 loc) · 2.63 KB
/
Youtube.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
require('simple_html_dom.php');
function authenticate(){
$webToken="302517024:AAGgrgOiESarNaMM8LoS6Ct-goVmJ3ircmc";
$url="https://api.telegram.org/bot".$webToken;
return $url;
}
function getMessage_id(){
$url_a=authenticate();
$update=file_get_contents($url_a."/getupdates");
$updateArray=json_decode($update,TRUE);
$chat_id=$updateArray["result"][0]["message"]["chat"]["id"];
return $chat_id;
}
function getMessage_text(){
$url_a=authenticate();
$update=file_get_contents($url_a."/getupdates");
$updateArray=json_decode($update,TRUE);
$num=(sizeof($updateArray["result"]))-1;
$chat_text=$updateArray["result"][$num]["message"]["text"];
return $chat_text;
}
function getMessage_textDownload(){
$url_a=authenticate();
$update=file_get_contents($url_a."/getupdates");
$updateArray=json_decode($update,TRUE);
$num=(sizeof($updateArray["result"]))-2;
$chat_text=$updateArray["result"][$num]["message"]["text"];
return $chat_text;
}
function getUrl(){
$chat_text_url=getMessage_text();
$html=file_get_html('https://www.youtube.com/results?search_query='.str_replace(' ','+',$chat_text_url));
return $html;
}
function getUrlDownload(){
$chat_text_url=getMessage_textDownload();
$html=file_get_html('https://www.youtube.com/results?search_query='.str_replace(' ','+',$chat_text_url));
return $html;
}
function getVideoUrl(){
$ol=getUrl()->find('h3.yt-lockup-title',0);
$a=$ol->find('a.yt-uix-tile-link',0);
$video_url=$a->href;
$video_youtube='https://youtube.com'.$video_url;
return $video_youtube;
}
function getVideoUrlDownload(){
$ol=getUrlDownload()->find('h3.yt-lockup-title',0);
$a=$ol->find('a.yt-uix-tile-link',0);
$video_url=$a->href;
$video_youtube='https://www.youtube.com'.$video_url;
return $video_youtube;
}
function sendMessage(){
if (getMessage_text()=='Hi'){
file_get_contents(authenticate()."/sendmessage?chat_id=".getMessage_id()."&text=Hi Sir Search For songs.....");
}
else if(getMessage_text()=='Y'){
file_get_contents(authenticate()."/sendmessage?chat_id=".getMessage_id()."&text=Getting url for download.....");
file_get_contents(authenticate()."/sendmessage?chat_id=".getMessage_id()."&text=".download());
}
else if(getMessage_text()=='N'){
file_get_contents(authenticate()."/sendmessage?chat_id=".getMessage_id()."&text=Okay Sir ...");
}
else{
file_get_contents(authenticate()."/sendmessage?chat_id=".getMessage_id()."&text=".getVideoUrl());
file_get_contents(authenticate()."/sendmessage?chat_id=".getMessage_id()."&text=Want to download (Y/N)");
}
}
function download(){
$url="http://keepvid.com/?url=".getVideoUrlDownload();
return $url;
}
sendMessage();
?>