Last active
December 27, 2015 01:49
-
-
Save studentIvan/7247445 to your computer and use it in GitHub Desktop.
php download manager for vk.com music (for savefrom.net extension -> get all mp3 links)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$links = <<<EOL | |
https://psv4.vk.me/c536213/u23259354/audios/6622030b9956.mp3 | |
https://psv4.vk.me/c6086/u3197020/audios/d0a867f54401.mp3 | |
https://cs9-6v4.vk.me/p13/e2886ae987e8c5.mp3 | |
https://psv4.vk.me/c6182/u211520772/audios/6ec1531bd181.mp3 | |
https://psv4.vk.me/c536610/u886918/audios/0e3ad42b151d.mp3 | |
https://psv4.vk.me/c6178/u47402845/audios/d45d27698600.mp3 | |
https://cs9-6v4.vk.me/p13/17e4437ffe0922.mp3 | |
https://psv4.vk.me/c6098/u2294877/audios/990035362c3a.mp3 | |
EOL; | |
function ID3GetTags($file) | |
{ | |
$f = fopen($file, 'rb'); | |
rewind($f); | |
fseek($f, -128, SEEK_END); | |
$tmp = fread($f,128); | |
$format = ($tmp[125] == Chr(0) and $tmp[126] != Chr(0)) | |
? 'a3TAG/a30NAME/a30ARTISTS/a30ALBUM/a4YEAR/a28COMMENT/x1/C1TRACK/C1GENRENO' | |
: 'a3TAG/a30NAME/a30ARTISTS/a30ALBUM/a4YEAR/a30COMMENT/C1GENRENO'; | |
$id3tag = unpack($format, $tmp); | |
fclose($f); | |
$result = array( | |
'artist' => (isset($id3tag['ARTISTS']) && strlen($id3tag['ARTISTS']) > 0) ? $id3tag['ARTISTS'] : null, | |
'title' => (isset($id3tag['NAME']) && strlen($id3tag['NAME']) > 0) ? $id3tag['NAME'] : null, | |
); | |
if ($result['artist'] == $result['title']) { | |
$result['artist'] = $result['title'] = null; | |
} | |
return $result; | |
} | |
foreach (explode("\n", $links) as $link) { | |
$link = trim($link); | |
echo "\ndownload $link...\n"; | |
file_put_contents(md5($link) . ".mp3", file_get_contents($link)); | |
$tag = ID3GetTags(md5($link) . ".mp3"); | |
$artist = $tag['artist'] ? ucfirst($tag['artist']) . " - " : ""; | |
$title = $tag['title'] ? ucfirst($tag['title']) : md5($link); | |
rename(md5($link) . ".mp3", trim($artist . $title) . ".mp3"); | |
echo "{$artist}{$title}.mp3 downloaded complete\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment