我有一个shell脚本,可以通过curl
将音频文件上传到SoundCloud帐户。最近它开始行为不端。具体做法是:
/oauth2/token
间歇性地为同一请求有效负载返回401 Unauthorized
。有时候它有效,有时候不行。/tracks.json
始终返回422 Unprocessable Entity
。以下是上传脚本:
#!/bin/bash
audio_path=/tmp/test.wav # RIFF (little-endian) data, WAVE audio, Microsoft PCM, 16 bit, mono 8000 Hz
sc_client_id=...
sc_client_secret=...
sc_username=...
sc_password=...
track_name=$(date +'%F-%H%M%S')
# Get SoundCloud auth token
auth_token=$(curl -sX POST 'https://api.soundcloud.com/oauth2/token' \
-F "client_id=${sc_client_id}" \
-F "client_secret=${sc_client_secret}" \
-F "grant_type=password" \
-F "username=${sc_username}" \
-F "password=${sc_password}" | \
grep -Po '(?<="access_token":")[^"]+(?=")')
if [ -z "$auth_token" ]; then
echo "Failed to get auth token from SoundCloud" >&2
exit 1
fi
# Upload audio to SoundCloud
curl --fail -sX POST 'https://api.soundcloud.com/tracks.json' \
-F "oauth_token=${auth_token}" \
-F "track[asset_data]=@${audio_path}" \
-F "track[title]=${track_name}" \
-F "track[sharing]=public" >/dev/null 2>&1
if [ $? -eq 0 ]; then
echo "$audio_path -> $track_name"
else
echo "Failed to upload audio to SoundCloud" >&2
exit 1
fi
我在API文档[1]中查找了更改,但没有任何内容向我发出。我很好奇其他人是否可以重现这个问题,或者它是否适合我的问题。任何提示都非常感谢。谢谢!