Upload songs/audio-files to a specific soundcloud account using soundcloud api?

喜夏-厌秋 提交于 2019-12-11 15:05:30

问题


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>

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.

Problem Statement:

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.


回答1:


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>
";

You may need to escape $blob, of course



来源:https://stackoverflow.com/questions/56244969/upload-songs-audio-files-to-a-specific-soundcloud-account-using-soundcloud-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!