-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
157 lines (132 loc) · 5.29 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
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
<?php
require_once __DIR__ . '/vendor/autoload.php';
require_once __DIR__ . '/VK_helper.php';
if (file_exists(__DIR__ . '/config.php')) {
require_once __DIR__ . '/config.php';
} else {
die('Rename config.sample.php to config.php and edit.');
}
use GuzzleHttp\Client;
use GuzzleHttp\Cookie\CookieJar;
use voku\helper\HtmlDomParser;
$cookieJar = new CookieJar();
$client = new Client([
'cookies' => $cookieJar,
'verify' => false,
'allow_redirects' => true,
'headers' => [
'Accept' => 'text/html',
'Content-Type' => 'text/html',
],
]);
$tracks = [];
$offset = (isset($_GET['offset']) ? (int) $_GET['offset'] : 0);
// Get login URL
try {
$loginPageResponse = $client->request('GET', 'https://m.vk.com');
if ($loginPageResponse->getStatusCode() == 200) {
$__loginPageHTML = $loginPageResponse->getBody()->getContents();
// Get form URL
$dom = HtmlDomParser::str_get_html($__loginPageHTML);
$loginForm = $dom->find('form', 0);
$__loginFormAction = $loginForm->action;
// Login & Save cookies
try {
$response = $client->request('POST', $__loginFormAction, [
'form_params' => [
'email' => $__USERNAME,
'pass' => $__PASSWORD,
],
]);
// Get my music
try {
$userMusicPageResponse = $client->request('POST', 'https://m.vk.com/audios' . $__USER_ID, [
'headers' => [
'X-Requested-With' => 'XMLHttpRequest',
],
'form_params' => [
'_ajax' => 1,
'offset' => $offset,
],
]);
if ($userMusicPageResponse->getStatusCode() == 200) {
$__myMusicPageJSON = $userMusicPageResponse->getBody()->getContents();
$__arrayFromJSON = json_decode($__myMusicPageJSON, true);
foreach ($__arrayFromJSON as $key => $value) {
if ($key == '3') {
foreach ($value as $key => $value) {
if ($key == '0') {
foreach ($value as $key => $value) {
$tracks[] = [
'title' => isset($value[0]) ? $value[0] : null,
'artist' => isset($value[3]) ? $value[3] : null,
'song' => isset($value[4]) ? $value[4] : null,
'extra_url' => isset($value[2]) ? $value[2] : null,
'decoded_url' => isset($value[2]) ? decode($value[2]) : null,
];
}
}
}
}
}
}
} catch (\Exception $e) {
die('An error occured: ' . $e->getMessage());
}
} catch (\Exception $e) {
die('An error occured: ' . $e->getMessage());
}
}
} catch (\Exception $e) {
die('An error occured: ' . $e->getMessage());
}
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>VK.Music — Direct Download Mp3</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
</head>
<body class="bg-light">
<div class="container">
<div class="py-3 text-center">
<h2>Playlist</h2>
<p class="lead">Get playlist from user ID: <strong><?=$__USER_ID;?></strong></p>
</div>
<div class="row py-3">
<div class="col-sm">
<?php if ($offset > 0) {?>
<a href="?offset=<?=($offset - 50);?>" class="btn btn-sm btn-primary">« Previous 50 records</a>
<?php }?>
</div>
<div class="col-sm text-right">
<?php if (count($tracks) >= 50) {?>
<a href="?offset=<?=($offset + 50);?>" class="btn btn-sm btn-primary">Next 50 records »</a>
<?php }?>
</div>
</div>
<table class="table table-bordered table-striped">
<thead class="thead-dark">
<tr>
<th>Title</th>
<th>Artist</th>
<th>Song</th>
<th>Download</th>
</tr>
</thead>
<tbody>
<?php foreach ($tracks as $__t) {?>
<tr>
<td><?=$__t['title'];?></td>
<td><?=$__t['artist'];?></td>
<td><?=$__t['song'];?></td>
<td><a href="<?=$__t['decoded_url'];?>" class="btn btn-sm btn-block btn-success" target="_blank">Download</a></td>
</tr>
<?}?>
</tbody>
</table>
</div>
</body>
</html>