-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrecord.php
More file actions
67 lines (61 loc) · 2.19 KB
/
record.php
File metadata and controls
67 lines (61 loc) · 2.19 KB
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
<?php
preg_match_all('/href="([^"]+.mp3)/i', http('http://www.radiorecord.ru/radio/top100/rr.txt'), $files);
set_time_limit(0);
$dir = rtrim($_GET['dir'] ?? $argv[1] ?? __DIR__, '\\\/') . DIRECTORY_SEPARATOR;
$eol = !empty($argv) ? PHP_EOL : '<br>';
$dirFiles = scandir($dir);
$trackNames = [];
foreach ($dirFiles as $dirFile) {
if ($dirFile != '.' && $dirFile != '..') {
$trackNames[mb_substr($dirFile, 4)] = mb_substr($dirFile, 0 ,4);
}
}
if(!empty($files)) {
$skipped = '';
foreach ($files[1] as $file) {
$file = trim($file);
$basename = urldecode(basename($file));
$path = $dir . $basename;
$trackName = mb_substr($basename, 4);
$newPosition = mb_substr($basename, 0, 4);
if (!isset($trackNames[$trackName])) {
$result = http($file,'http://www.radiorecord.ru/radio/stations/?st=rr', $path);
echo $basename . $eol;
if (filesize($path) < 1000) {
exit(file_get_contents($path));
}
sleep(rand(.4, 1.5));
} elseif ($trackNames[$trackName] != $newPosition) {
rename($dir . $trackNames[$trackName] . $trackName, $path);
echo "$trackName: $trackNames[$trackName] -> $newPosition $eol";
} else {
$skipped .= $basename . $eol;
}
}
echo $eol . 'Skipped:' . $eol . $skipped;
}
function http($url, $referrer = '', $path = '')
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_HEADER, false);
if (!empty($referrer)) {
curl_setopt($ch, CURLOPT_REFERER, $referrer);
}
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_USERAGENT,'Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36');
curl_setopt($ch, CURLOPT_URL, $url);
if (!empty($path)) {
$fp = fopen($path, 'w');
curl_setopt($ch, CURLOPT_FILE, $fp);
} else {
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
}
$result = curl_exec($ch);
curl_close($ch);
if (!empty($fp)) {
fclose($fp);
}
return $result;
}