Please enable / Bitte aktiviere JavaScript!
Veuillez activer / Por favor activa el Javascript![ ? ]
Download yandex playlist entirely? - bug-code.com Q&A

Download yandex playlist entirely?

0 like 0 dislike
75 views
Good day,
can you please tell me how to download playlist from a Yandex-music as a whole. In playlists 150-200 tracks to tear one would not want to. Primarily interested in the collections page music.yandex.ru/oldschool (also available at music.yandex.ru/#!/users/Muz-winamp/playlists). Search by trackers wouldn't work, the browser plugins pump through 1 records.
asked by | 75 views

5 Answers

0 like 0 dislike
wrote php script
<?php\r\rconst MP3_DIR = '/drive2/Dropbox/backup/mp3/';\r\rrequire_once __DIR__ . '/vendor/autoload.php';\r\r$curl = new \\Zelenin\\Curl();\r\r$playlist_url = 'http://music.yandex.ru/?ncrnd=6537#!/users/Muz-winamp/playlists/1046';\r\rpreg_match_all( '/users\\/(.*)\\/playlists\\/(.*)/isu', $playlist_url, $matches );\r\r$owner = $matches[1][0];\r$playlist_id = $matches[2][0];\r\r$response = $curl->get( 'http://music.yandex.ru/get/playlist2.xml?kinds=' . $playlist_id . '&owner=' . $owner ); $playlist = json_decode( $response['body'], true ); $playlist_title = $playlist['playlists'][0]['title']; $tracks = implode( ',', $playlist['playlists'][0]['tracks'] ); $response = $curl->get( 'http://music.yandex.ru/get/tracks.xml?tracks=' . urlencode( $tracks ) ); $tracks = json_decode( $response['body'], true ); $tracks = $tracks['tracks']; $playlist_dir = MP3_DIR . $playlist_title; if ( !file_exists( $playlist_dir ) && !is_dir( $playlist_dir ) ) { mkdir( $playlist_dir ); } foreach ( $tracks as $track ) { $artist = $track['artist']; $title = $track['title']; $response = $curl->get( 'http://storage.music.yandex.ru/download-info/' . $track['storage_dir'] . '/2.mp3' ); $xml = new DOMDocument(); $xml->loadXML( $response['body'] ); $host = $xml->getElementsByTagName( 'host' )->item(0)->nodeValue; $ts = $xml->getElementsByTagName( 'ts' )->item(0)->nodeValue; $path = $xml->getElementsByTagName( 'path' )->item(0)->nodeValue; $s = $xml->getElementsByTagName( 's' )->item(0)->nodeValue; $n = md5( 'XGRlBW9FXlekgbPrRHuSiA' . substr( $path, 1 ) . $s ); $mp3_url = 'http://' . $host . '/get-mp3/' . $n . '/' . $ts . $path; //echo $mp3_url . PHP_EOL; $response = $curl->get( $mp3_url ); $mp3_name = addslashes( $artist . '- ' . $title . '.mp3' ); echo $mp3_name . PHP_EOL; file_put_contents( MP3_DIR . $playlist_title . '/' . $mp3_name, $response['body'] ); }
answered by
0 like 0 dislike
used Denver on windows, so we had to optimize the script

It is necessary in php.ini to increase the processing time of the script
max_execution_time = 150

to simplify the problem, had to change the plug-in file (with apologies to the author)
<?php\r\r/**\r* A simple curl wrapper\r*\r* @package Curl\r* <a href="user/author">@author Aleksandr Zelenin @zelenin.me> * @link https://github.com/zelenin/Curl * @license MIT * @version 0.5.0 */ //namespace Zelenin; class mCurl {


added check for specials.the characters and the existence of the downloaded file:
<?php\rconst MP3_DIR = 'music/';\rinclude("Curl.php");\r\r$curl = new mCurl();\r\r//$playlist_url = 'http://music.yandex.ru/#!/users/Muz-winamp/playlists/1047';\r$playlist_url = 'http://music.yandex.ru/#!/users/muz-winamp/playlists/1046';\r\rpreg_match_all( '/users\\/(.*)\\/playlists\\/(.*)/isu', $playlist_url, $matches );\r\r$owner = $matches[1][0];\r$playlist_id = $matches[2][0];\r\r$response = $curl->get( 'http://music.yandex.ru/get/playlist2.xml?kinds=' . $playlist_id . '&owner=' . $owner ); $playlist = json_decode( $response['body'], true ); $playlist_title = $playlist['playlists'][0]['title']; $playlist_title = str_replace("\\'","_", $playlist_title); $tracks = implode( ',', $playlist['playlists'][0]['tracks'] ); $response = $curl->get( 'http://music.yandex.ru/get/tracks.xml?tracks=' . urlencode( $tracks ) ); $tracks = json_decode( $response['body'], true ); $tracks = $tracks['tracks']; $denied = array ('\\\\','/',':','?','*','<','>','|','"'); $playlist_title = str_ireplace($denied,"_", $playlist_title); $playlist_dir = MP3_DIR . $playlist_title; //iconv('utf-8','windows-1251', $playlist_dir); echo $playlist_dir ."
"; if ( !file_exists( $playlist_dir ) && !is_dir( $playlist_dir ) ) { mkdir( $playlist_dir ); } $index = 1; echo ""; foreach ( $tracks as $track ) { $artist = $track['artist']; $title = $track['title']; $response = $curl->get( 'http://storage.music.yandex.ru/download-info/' . $track['storage_dir'] . '/2.mp3' ); $xml = new DOMDocument(); $xml->loadXML( $response['body'] ); $host = $xml->getElementsByTagName( 'host' )->item(0)->nodeValue; $ts = $xml->getElementsByTagName( 'ts' )->item(0)->nodeValue; $path = $xml->getElementsByTagName( 'path' )->item(0)->nodeValue; $s = $xml->getElementsByTagName( 's' )->item(0)->nodeValue; $n = md5( 'XGRlBW9FXlekgbPrRHuSiA' . substr( $path, 1 ) . $s ); $mp3_url = 'http://' . $host . '/get-mp3/' . $n . '/' . $ts . $path; //echo $mp3_url . PHP_EOL; $mp3_name = addslashes( $artist . '- ' . $title . '.mp3' ); echo "".$index."". $mp3_name . PHP_EOL . ""; //iconv('UTF-8','WINDOWS-1251', $playlist_title); //iconv('UTF-8','WINDOWS-1251', $mp3_name); $mp3_name = str_ireplace($denied,"_", $mp3_name); echo "".$mp3_name . PHP_EOL . ""; if ( !file_exists( MP3_DIR . $playlist_title . '/' . $mp3_name )) { $response = $curl->get( $mp3_url ); file_put_contents( MP3_DIR . $playlist_title . '/' . $mp3_name, $response['body'] ); echo "downloaded"; } else { echo "exists"; }; $index=$index+1; }; echo "";


encoding was too lazy to figure out because the receiver only understands utf :)
answered by
0 like 0 dislike
encoding was too lazy to figure out because the receiver only understands utf :)


So you have all that written already. Under windows and denwer

// for folder name $playlist_title = iconv('utf-8', 'windows-1251', $playlist_title); // for song name $mp3_name = iconv('utf-8', 'windows-1251', $mp3_name );
answered by
0 like 0 dislike
Search by trackers wouldn't work, the browser plugins pump through 1 records.

Wrote an extension for Chrome, Yandex, Opera: https://github.com/egoroof/yandex-music-fisher
You can download tracks and playlists, albums and even albums from singers.
UPD (01.07.15) - added support for ID3 tags!
answered by
0 like 0 dislike
answered by
Welcome to Bug-code Q&A, where you can ask questions and receive answers from other members of the community.

24.8k questions

46.2k answers

0 comments

13.4k users

24,788 questions
46,220 answers
0 comments
13,438 users