I
I
Ivan Ivanov2017-02-16 20:48:45
PHP
Ivan Ivanov, 2017-02-16 20:48:45

How now to get a link to mp3 when parsing vk.com (Vkontakte)?

From today noted that if parse the URL mp3 c vk.com by post request https://vk.com/al_audio.php (previously authorized)
such as such act = reload_audio & al = 1 & ids = 33503953_157663689% 2C33503953_172403905% 2C33503953_170887163 % 2C33503953_170651507% 2C33503953_158704841 %2C33503953_157663689
Then the url to mp3 is no longer returned, but only a response of this type is returned (translated jsom into an array):

array (
  0 => 
  array (
    0 => '157663689',
    1 => '33503953',
    2 => 'https://vk.com/mp3/audio_api_unavailable.mp3?extra=s1HhmNLsEum1zfHyAu1jxOuVuMj5s2Pjsf8VEefYBY1vwvPjAuHWngnxrwS3ytOWBOrtrZHMDwnutI8OzOKVnxHqrhvWy1C9rwHbsZfAsNfZsOLbngD4qJHyu2DqptDHwfv6D1vsvJDlzeTgDLiXChm1tZKOAhy3zOWTyvbRCM9VAOvFwLbLpxvZt25VrKHmCZ9LreeUy3rOmMDZmMDNy2rXzxjTA2neBuHZqI5cCNeTEu0UzKPJlwLhCw1ToKDeseH2#CGSOnGLYcZmZcxy',
    3 => 'Невесомость',
    4 => '4 апреля',
    5 => 200,
    6 => 0,
    7 => 0,
    8 => '',
    9 => 0,
    10 => 1,
    11 => '',
    12 => '[]',
    13 => '//bff041ac529e483557',
  ),
  1 => 
  array (
    0 => '172403905',
    1 => '33503953',
    2 => 'https://vk.com/mp3/audio_api_unavailable.mp3?extra=zXWDzaW6pr4sabOCgsmIbgPGcqvLy2m6gam7oISGkHWwiN4ebHScaqnIjgqenWqhjduMzHfMkrONbH06yISlct0egYaybdadbdycfYuhyMuhgwSPjdKHmbjHpXbIbYrLcGK7oXvIkIyKoICIjWKBnWyhysqgcJi3dgaYhcS3zMahFIeYftuuddTLog4YisCRnMXGiZ59zgvIz2rNy2bQzZfHygz8zcn8jZy9FtO3mh44jx1Njwf+zcaWFhXPicmNjZS#EaTtcxy',
    3 => 'Careless Whisper (George Michael Cover)',
    4 => 'Seether',
    5 => 302,
    6 => 0,
    7 => 0,
    8 => '',
    9 => 0,
    10 => 32769,
    11 => '',
    12 => '[]',
    13 => '//8cb914bae6de4fc957',
  ),
  2 => 
  array (
    0 => '170887163',
    1 => '33503953',
    2 => 'https://vk.com/mp3/audio_api_unavailable.mp3?extra=A3neCLbJzM5MCZfNsuXtz1jwsKjTEMX3Ew9suNCZr2jOtfv1r2HAmLjcnuHbuhvkCwOXqwO3rgfhtvv0vv83vwDQsLPgsdrqvKO5vNjKEg4WsvjkAgPFBZvrqKPfrdr5Cey4zu9psuLortzozdztzxvvzdLTyMiWsvnblwXqBK5Nse5kwdntneuYxZ1HCNr4zt8ZCgOUztqWnge1mwyOm2vKmgyVmdjWl3rLBI5UzgmTA3yUnhy1ltDZyY8VoNnWDhr0#DG',
    3 => 'Runaway Train',
    4 => 'Soul Asylum',
    5 => 266,
    6 => 0,
    7 => 0,
    8 => '',
    9 => 0,
    10 => 1,
    11 => '',
    12 => '[]',
    13 => '//40e1941ff852a5373e',
  ),
  3 => 
  array (
    0 => '170651507',
    1 => '33503953',
    2 => 'https://vk.com/mp3/audio_api_unavailable.mp3?extra=uK5osKKafrvzsqOxcuWofeXrf1LEvbruxO4vsGSofqOlcGipcqWjdLGmcaLyffDkcqvFqK5iwWCocO1cchn/dv9+uq1YaOP/xvnICWnvyg91vfv0waTIuL8nDO5ZwgXZtNb0xxLxww9lDxH4xeXxsxX4xqP4xW1+fOj5ExKccuP2uLnsCeXPCM5Fcx1pxMuxxfzIwgOxBu9BF3njs1bmswPdAgP+yf5Sva1wyhL4AujYu1v1yNLqqWnGD3vGua5OB2v3#EaTzcxGlyW',
    3 => 'Deceit',
    4 => 'Metalforce',
    5 => 327,
    6 => 0,
    7 => 0,
    8 => '',
    9 => 0,
    10 => 1,
    11 => '',
    12 => '[]',
    13 => '//12c4bf3458d3f70c35',
  ),
  4 => 
  array (
    0 => '158704841',
    1 => '33503953',
    2 => 'https://vk.com/mp3/audio_api_unavailable.mp3?extra=uO85zuTPC3aWmOTKmOjWC1HpCJvKnK9Une9PqJaVAwS2l2W9tejrmOu9uK4VzITrmt1qBMi9mdf2Egz2s1P2AvPIDxvXnKvkmI95BhrOk29UzxnXy2PqDNzIlZL2ptr1rc16CZjVu3zTChjSBMW5rw9KBwiRyOvgtvmZs2rqBhLQBg5jq2jeAKnYpvDyyMr0mt9optKUmvf5tfjAtLjsmtj5wvHwtKW9vMqXkY4Rt10Tn2yUmgznlvjJwLzwoMm9zgqO#CGSOoqL2',
    3 => 'Свобода',
    4 => 'Ария',
    5 => 313,
    6 => 0,
    7 => 0,
    8 => '',
    9 => 0,
    10 => 1,
    11 => '',
    12 => '[]',
    13 => '//8823e17f4869e0b9c5',
  ),
)

Where links to mp3 are replaced with an audio recording https://vk.com/mp3/audio_api_unavailable.mp3?extra... with the text that you need to use official applications to use music in contact. I suspect that the link to mp3 is somehow encrypted here, which is pulled out by some function. Does anyone know how to get now the link to the desired mp3? Thanks in advance.
P.s. For those who read inattentively, I repeat once again - I'm talking about direct parsing of VK, and not about using the API. No need to write for the 100500th time that the api has not been working since December 16, I know about it, direct parsing of the vk.com site worked until the last days, today I found out that it does not work.

Answer the question

In order to leave comments, you need to log in

5 answer(s)
I
ImIeeee, 2017-02-17
@romalu

Update.
I posted all the files on Github - an encryption, decryption algorithm, an example of using a token. Only the latest version of the PHP decryption code will be here, as per the question.
Created a repository with the code to get a VK token suitable for the Audio API by GMS ID and GMS token.
Now the address of the audio recording seems to be tied to the user ID of VKontakte. You need to specify it in the code.

<?php

define('VK_ID', ID_пользователя_в_виде_числа);

function decode($str){
  $vals = explode("#", explode("?extra=", $str)[1]);
  $tstr = vk_o($vals[0]);
  $ops = vk_o($vals[1]);
  $ops_arr = explode(chr(9), $ops);
  $len = sizeof($ops_arr);
  for($i = $len - 1; $i >= 0; $i--){
    $args_arr = explode(chr(11), $ops_arr[$i]);
    $op_ind = array_shift($args_arr);
    switch($op_ind){
      case "v": $tstr = vk_v($tstr); break;
      case "r": $tstr = vk_r($tstr, $args_arr[0]); break;
      case "x": $tstr = vk_x($tstr, $args_arr[0]); break;
      case "s": $tstr = vk_s($tstr, $args_arr[0]); break;
      case "i": $tstr = vk_i($tstr, $args_arr[0]); break;
    }
  }
  return $tstr;
}

$vk_str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMN0PQRSTUVWXYZO123456789+/=";

function vk_o($str){
  global $vk_str;
  $len = strlen($str);
  $result = "";
  for($s = 0, $index2 = 0; $s < $len; $s++){
    $sym_index = strpos($vk_str, $str[$s]);
    if($sym_index !== false){
      $i = (($index2 % 4) !== 0) ? ( ($i<<6) + $sym_index) : $sym_index;
      if(($index2%4) != 0){
        $index2++;
        $shift = -2 * $index2 & 6;
        $result .= chr(0xFF & ($i >> $shift));
      } else {
        $index2++;
      }
    }
  }
  return $result;
}

function vk_s($str, $start){
  $len = strlen($str);
  if($len > 0){
    $cur = abs($start);
    $shuffle_pos = array();
    for($i = $len - 1; $i >= 0; $i--){
      $cur = (($len * ($i + 1)) ^ $cur + $i) % $len;
      $shuffle_pos[$i] = $cur;
    }
    for($i = 1; $i < $len; $i++){
      $offset = $shuffle_pos[$len - $i - 1];
      $prev = $str[$i];
      $str[$i] = $str[$offset];
      $str[$offset] = $prev;
    }
  }
  return $str;
}

function vk_i($str, $i){
  return vk_s($str, $i ^ (int) VK_ID);
}

function vk_v($str){
  return strrev($str);
}

function vk_r($str, $i){
  global $vk_str;
  $vk_str2 = $vk_str . $vk_str;
  $vk_str2_len = strlen($vk_str2);
  $len = strlen($str);
  $result = "";
  for($s = 0; $s < $len; $s++){
    $index = strpos($vk_str2, $str[$s]);
    if($index !== false){
      $offset = ($index - $i);
      if($offset < 0){
        $offset += $vk_str2_len;
      }
      $result .= $vk_str2[$offset];
    } else {
      $result .= $str[$s];
    }
  }
  return $result;
}

function vk_x($str, $i){
  $xor_val = ord($i[0]);
  $str_len = strlen($str);
  $result = "";
  for($i = 0; $i < $str_len; $i++){
    $result .= chr(ord($str[$i]) ^ $xor_val);
  }
  return $result;
}

echo decode($argv[1]);
?>

D
Dimonchik, 2017-02-16
@dimonchik2013

pass the API key, you can look in the application

D
Densikos, 2017-02-26
@Densikos

What can replace

t.split("").forEach(function(o) {
            e.push(String.fromCharCode(o.charCodeAt(0) ^ i))
        })

forEach doesn't want to work in delphi.

O
ovt00, 2018-01-23
@ovt00

Please tell me what is wrong in my code. I pass the authorization, I also get a response to the audio request, but there is no encrypted link to the audio in the form vk.com\/mp3\/audio_api_unavailable.mp3, it is just empty, the rest of the data is there. Code itself:
login = 'my login'
password = 'my password'
url = ' https://vk.com/ '
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit /537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Language': 'ru-ru,ru;q=0.8,en-us;q=0.5,en;q=0.3',
'Accept-Encoding': 'gzip,
'DNT': '1'
}
session = requests.session()
data = session.get(url, headers=headers)
page = lxml.html.fromstring(data.content)
form = page.forms[0]
form.fields ['email'] = login
form.fields['pass'] = password
session.post(form.action, data=form.form_values())
url = " https://vk.com/al_audio.php "
data = {"act": "reload_audio", "al": "1", "ids": "2000446189_456241048"}
result = session.post(url, data=data, headers=headers)
Result:
"!--4643796536976068770{"259570469":1 }41dafbafe8dfdd3a59"

K
kibirnetik90, 2018-04-12
@kibirnetik90

Let's make an analogue of api vk to order who is interested in writing in a personal https://vk.com/id347323513

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question