A
A
alxrv2013-12-22 16:25:41
Yandex
alxrv, 2013-12-22 16:25:41

How to download the entire yandex playlist?

Good afternoon,
please tell me how to download the entire playlist from the Yandex Music service. In playlists of 150-200 tracks, I would not want to tear out one at a time. First of all, the selections from the music.yandex.ru/oldschool page are of interest (also available at music.yandex.ru/#!/users/Muz-winamp/playlists ). A search for trackers did not give anything, browser plugins download 1 record each.

Answer the question

In order to leave comments, you need to log in

5 answer(s)
A
Alexander Zelenin, 2013-12-22
@alxrv

wrote php script

<?php

const MP3_DIR = '/drive2/Dropbox/backup/mp3/';

require_once __DIR__ . '/vendor/autoload.php';

$curl = new \Zelenin\Curl();

$playlist_url = 'http://music.yandex.ru/?ncrnd=6537#!/users/Muz-winamp/playlists/1046';

preg_match_all( '/users\/(.*)\/playlists\/(.*)/isu', $playlist_url, $matches );

$owner = $matches[1][0];
$playlist_id = $matches[2][0];

$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'] );
}

D
dedmaroz, 2014-09-21
@dedmaroz

A search for trackers did not give anything, browser plugins download 1 record each.

Wrote an extension for Chrome, Yandex, Opera browsers: https://github.com/egoroof/yandex-music-fisher
You can download both tracks and playlists, albums and even discography of performers.
UPD (07/01/15) - ID3 tag support added!

A
AnjeyTsibylskij, 2015-09-18
@AnjeyTsibylskij

skyload

A
Andrew, 2014-02-16
@MyCTuK

I used Denver on windows, so I had to optimize the scripts a little.
It is necessary to increase the processing time of the script in php.ini
to simplify the task, I had to change the included file (may the author forgive me)

<?php

/**
 * A simple curl wrapper
 *
 * @package Curl
 * @author  Aleksandr Zelenin <[email protected]>
 * @link    https://github.com/zelenin/Curl
 * @license MIT
 * @version 0.5.0
 */

//namespace Zelenin;

class mCurl
{

added a check for special characters and the existence of the downloaded file:
<?php
const MP3_DIR = 'music/';
include("Curl.php");

$curl = new mCurl();

//$playlist_url = 'http://music.yandex.ru/#!/users/Muz-winamp/playlists/1047';
$playlist_url = 'http://music.yandex.ru/#!/users/muz-winamp/playlists/1046';

preg_match_all( '/users\/(.*)\/playlists\/(.*)/isu', $playlist_url, $matches );

$owner = $matches[1][0];
$playlist_id = $matches[2][0];

$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 ."<br/>";

if ( !file_exists( $playlist_dir ) && !is_dir( $playlist_dir ) ) {
    mkdir( $playlist_dir );
}

$index = 1;
echo "<table>";
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 "<tr><td>".$index."</td><td>" . $mp3_name . PHP_EOL . "</td>";
    //iconv('UTF-8','WINDOWS-1251', $playlist_title);
    //iconv('UTF-8','WINDOWS-1251', $mp3_name);
    
    
    $mp3_name = str_ireplace($denied,"_", $mp3_name);
    
    echo "<td>".$mp3_name . PHP_EOL . "</td>";
    
    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 "<td>downloaded</td></tr>";
    } else {
        echo "<td>exists</td><t/r>";
    };
    $index=$index+1;
 };
 
 echo "</table>";

I was too lazy to deal with the encoding, because the car radio only understands utf :)

V
Vladimir Vasiliev, 2014-09-14
@bobahvas

I was too lazy to deal with the encoding, because the car radio only understands utf :)

So you've already written everything. 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 );

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question