-
Notifications
You must be signed in to change notification settings - Fork 2
/
youtube.php
87 lines (74 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
<?php
class Youtube
{
protected $apikey;
function __construct( $apikey )
{
$this->key = $apikey;
}
public function b0t($url , $post = null)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
if($post != null)
{
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$post);
}
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
$server_output = curl_exec($ch);
curl_close ($ch);
return $server_output;
}
public function search( $q )
{
$this->q = $q;
return $this;
}
public function start( $page = null)
{
$q = urlencode($this->q);
if($page != null) { $page = "&pageToken=$page"; }
$bot = $this->b0t("https://www.googleapis.com/youtube/v3/search?part=snippet&q={$q}&type=video&videoCaption=closedCaption&maxResults=6&key={$this->key}{$page}");
$this->videos = json_decode($bot);
return $this;
}
public function videodetay( $id )
{
$bot = $this->b0t("https://www.googleapis.com/youtube/v3/videos?part=snippet&id={$id}&key={$this->key}");
$item = json_decode($bot);
return $item->items;
}
public static function copyfile($url,$saveto){
$ch = curl_init ($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
$raw=curl_exec($ch);
curl_close ($ch);
if(file_exists($saveto)){
unlink($saveto);
}
$fp = fopen($saveto,'x');
fwrite($fp, $raw);
fclose($fp);
}
public function selflink($s) {
$tr = array('ş','Ş','ı','I','İ','ğ','Ğ','ü','Ü','ö','Ö','Ç','ç','(',')','/',':',',');
$eng = array('s','s','i','i','i','g','g','u','u','o','o','c','c','','','-','-','');
$s = str_replace($tr,$eng,$s);
$s = strtolower($s);
$s = preg_replace('/&amp;amp;amp;amp;amp;amp;amp;amp;.+?;/', '', $s);
$s = preg_replace('/\s+/', '-', $s);
$s = preg_replace('|-+|', '-', $s);
$s = preg_replace('/#/', '', $s);
$s = str_replace('.', '', $s);
$s = trim($s, '-');
return $s;
}
}
?>