使用 soundcloud api 将歌曲/音频文件上传到特定的 soundcloud 帐户? [英] Upload songs/audio-files to a specific soundcloud account using soundcloud api?
问题描述
我正在处理如下所示的 php 代码,它将 mp4 文件(存在于 in_folder 中) 转换为 mp3(并将其发送到 out_folder)
I am working on a php code as shown below which convert mp4 files (present in the in_folder) to mp3 (and send it into out_folder)
<?php
foreach ($mp4_files as $f)
{
$parts = pathinfo($f);
switch ($parts['extension'])
{
case 'mp4' :
$filePath = $src_dir . DS . $f;
system('ffmpeg -i ' . $filePath . ' -map 0:2 -ac 1 ' . $destination . DS . $parts['filename'] . '.mp3', $result);
break;
case 'mp3' :
// copy($f, $destination. DS . $parts['filename']. '.' . $parts['extension']);
copy($f, $mp3_processed . DS . $parts['filename'] . '.mp3');
copy($f, $destination . DS . $parts['filename'] . '.mp3');
break;
}
}
?>
<script src="https://connect.soundcloud.com/sdk/sdk-3.3.2.js"></script>
<script>
SC.initialize({
client_id: 'YOUR_CLIENT_ID',
redirect_uri: 'http://example.com/callback'
});
var getTracks = function() { return SC.get('/me/tracks'); };
// connect and update track data
SC.connect().then(getTracks).then(function(tracks){
SC.put('/tracks' + tracks[0].id, {
track: {
description: 'This track was recorded in Berlin',
genre: 'Electronic'
}
});
});
</script>
我的下一步是将mp3 文件(位于 out_folder 中)上传到特定的 soundcloud 帐户.我从 soundcloud 开发人员指南 中添加了一些脚本(php 代码完成的地方)作为上传歌曲的第一步从歌曲目录到 soundcloud.
My next step is to upload the mp3 files(which is in the out_folder) to a specific soundcloud account. I added some script (where php code finish) from soundcloud developers guide as a 1st step in order to upload songs from the songs directory to soundcloud.
问题陈述:
我想知道我应该在上面的脚本代码中进行哪些更改,以便我们可以将歌曲/音频文件从 out_folder 目录上传到任何特定的 soundcloud 帐户.任何指针将不胜感激.
I am wondering what changes I should in the script code above so that we can make upload songs/audio file from the out_folder directory to any specific soundcloud account. Any pointers will be highly appreciated.
推荐答案
在你用 copy() 编写文件后,这样的事情应该可以工作:
After you write the file with copy(), something like this should work:
$blob=file_get_contents($destination . DS . $parts['filename'] . '.mp3');
$title='THE_TITLE';
echo "
<script>
var aFileParts = ['$blob']; // an array with binary data
var audioBlob = new Blob(aFileParts, {type : 'audio/mpeg'});
SC.upload({
file: audioBlob , // a Blob of your WAV, MP3...
title: '$title'
});
</script>
";
当然,您可能需要转义 $blob
You may need to escape $blob, of course
这篇关于使用 soundcloud api 将歌曲/音频文件上传到特定的 soundcloud 帐户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!