This repository has been archived by the owner on Nov 14, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
zing.php
70 lines (61 loc) · 2.76 KB
/
zing.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
<?php
// code by toiviet.com vui long khong xoa dong nay khi su dung
//Đầu tiên là hàm get curl để connect đên mp3 zing, có thể thay thế hàm này bằng file_get_contents nhưng không tối ưu bằng curl
function get_by_curl($url){
//echo "curl:url<pre>".$url."</pre><BR>";
$options = array(
CURLOPT_RETURNTRANSFER => true, // return web page
CURLOPT_HEADER => false, // don't return headers
CURLOPT_ENCODING => "", // handle all encodings
CURLOPT_USERAGENT => "spider", // who am i
CURLOPT_AUTOREFERER => true, // set referer on redirect
CURLOPT_CONNECTTIMEOUT => 15, // timeout on connect
CURLOPT_TIMEOUT => 15, // timeout on response
CURLOPT_MAXREDIRS => 10, // stop after 10 redirects
CURLOPT_SSL_VERIFYPEER => false,
);
$ch = curl_init($url);
curl_setopt_array( $ch, $options );
$content = curl_exec( $ch );
$err = curl_errno( $ch );
$errmsg = curl_error( $ch );
$header = curl_getinfo( $ch,CURLINFO_EFFECTIVE_URL );
curl_close( $ch );
//$header['errno'] = $err;
// $header['errmsg'] = $errmsg;
//change errmsg here to errno
if ($errmsg)
{
echo "CURL:".$errmsg."<BR>";
}
return $content;
}
// Bắt đầu từ đây
if($_GET['getlink']) {
$link = ($_GET['link']);
// Nếu người dùng bấm vào submit thì [dưới]
if (empty($link)) { // thì kiểm tra xem có rỗng hay không nếu rỗng thì thông báo và kết thúc không chạy bất kỳ lệnh nào.
echo '<center>Mời bạn điền link vào</center>';
exit;
}
// nếu không rỗng thì tiếp tục chạy và kiểm tra có phải đúng link dạng http://mp3.zing.vn/bai-hat/(.*?)/ZW7I0ZWA.html hay không
// nếu đúng thì làm nó sẽ kết nối, còn không đúng dạng thì nó nhảy xuống [chú thích 09]
if (preg_match("/http:\/\/mp3.zing.vn\/bai\-hat\/(.*?).html/",$link)){
$data = get_by_curl($link);// kết nối và lấy toàn bộ dữ liệu của link
preg_match("/http:\/\/mp3.zing.vn\/xml\/song\-xml\/(.*?)\"/",$data,$arr_preg);
$link_xml = str_replace('"','',$arr_preg[0]);
$xml_data = get_by_curl($link_xml);
// tách lấy tên bài hát trong file xml
preg_match("/<title><!\[CDATA\[(.*?)]]><\/title>/",$xml_data,$name_arr);
$name_song = $name_arr[1];
// tách lấy link mp3 trong xml
preg_match("/http:\/\/mp3.zing.vn\/xml\/load\-song\/(.*?)]/",$xml_data,$arr_link_mp3);
$link_mp3 = str_replace(']','',$arr_link_mp3[0]);
echo '<center><h3><a href="'.$link_mp3.'" target="_blank">'.$name_song.'</a></h3></center>';
}
else{
// [chú thích 09]
echo "<center>Link MP3 không đúng xin vui lòng kiểm tra lại</center>";
}
}
?>