diff options
author | Kaimi <kaimi-@users.noreply.github.com> | 2018-09-30 10:35:42 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-09-30 10:35:42 +0300 |
commit | 0d7e0562c46b59e289a8023694660f4e06c1ccfa (patch) | |
tree | 6b01f06ef762c87e4094baef6c0224802b0d7604 | |
parent | d0122d7b09aece1149c49d832fb2466d7853b0a1 (diff) |
Append OAuth prefix if not present
-rwxr-xr-x | src/ya.pl | 15 |
1 files changed, 13 insertions, 2 deletions
@@ -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) { |