0

Append OAuth prefix if not present

This commit is contained in:
Kaimi
2018-09-30 10:35:42 +03:00
committed by GitHub
parent d0122d7b09
commit 0d7e0562c4

View File

@@ -37,7 +37,8 @@ use constant
URL_PLAYLIST_REGEX => qr{music\.yandex\.\w+/users/(.+?)/playlists/(\d+)}is,
RESPONSE_LOG_PREFIX => 'log_',
TEST_URL => 'https://api.music.yandex.net/users/ya.playlist/playlists/1',
RENAME_ERRORS_MAX => 5
RENAME_ERRORS_MAX => 5,
AUTH_TOKEN_PREFIX => 'OAuth ',
};
use constant
{
@@ -500,6 +501,16 @@ sub get_track_url
my $storage_dir = shift;
my $track_id = (split(/\./, $storage_dir))[-1];
my $auth_token = '';
if($opt{mobile} && $opt{auth})
{
if($opt{auth} !~ /${\(AUTH_TOKEN_PREFIX)}/i)
{
$auth_token = AUTH_TOKEN_PREFIX;
}
$auth_token .= $opt{auth};
}
my $request = $ua->get
(
$opt{mobile} ?
@@ -507,7 +518,7 @@ sub get_track_url
:
YANDEX_BASE.sprintf(DOWNLOAD_INFO_MASK, time, $storage_dir)
,
Authorization => ($opt{mobile} && $opt{auth}) ? $opt{auth} : ''
Authorization => $auth_token
);
if(!$request->is_success)
{