forked from smoqadam/tg-bot-youtube-downloader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
60 lines (38 loc) · 1.16 KB
/
index.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
<?php
$message = file_get_contents('php://input');
require 'libs/Telegram.php';
require 'libs/Youtube.php';
use Smoqadam\Telegram;
use Smoqadam\Youtube;
$api_token = 'API_TOKEN';
$tg = new Telegram($api_token);
$y = new Youtube();
/**
* download a video by video Id
*/
$tg->cmd('vid:<<:any>>', function ($video_id, $option) use ($tg, $y, $message) {
if (!strlen($video_id)) {
$tg->sendMessage("vid:<youtube video ID>", $tg->getChatId());
return;
}
// get video information and initial
if($y->init($video_id) !== false){
$tg->sendMessage("Please wait ...", $tg->getChatId());
//$tg->sendMessage($y->getName(), $tg->getChatId());
$msg = "Download finished! \n".$y->download();
}else{
$msg = $y->getError();
}
$tg->sendMessage($msg, $tg->getChatId());
$y->checkForOldFiles();
});
/**
* delete file by video id
*/
$tg->cmd('del:<<:any>>', function ($video_id) use ($tg, $y) {
$y->init($video_id);
$y->deleteFile($y->getPath() . $y->getTitle() . '.mp4');
$msg = $y->getTitle() . ' Deleted!!';
$tg->sendMessage($msg, $tg->getChatId());
});
$tg->process(json_decode($message, true));