0

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.

flash
  • 1,455
  • 11
  • 61
  • 132
  • Wouldn't you need a unique API key that's linked to every single account? – cullanrocks May 21 '19 at 19:12
  • @cullanrocks Yes, I think so. Where can I get a unique API key that is linked to every single account ? I checked this link and I don't think so they are accepting any new registration. https://docs.google.com/forms/d/e/1FAIpQLSfNxc82RJuzC0DnISat7n4H-G7IsPQIdaMpe202iiHZEoso9w/closedform – flash May 21 '19 at 19:14
  • Hmm looks like it's closed temporarily. I'm not sure you'll be able to do whatever it is you are trying to do at the moment. Maybe contact their support team see if they can get you an API key while they are reworking their website. – cullanrocks May 21 '19 at 19:16
  • https://developers.soundcloud.com/docs/api/sdks `register a new app` is currently unavailable. Is there any way we can retrieve unique API key ? – flash May 21 '19 at 19:24
  • No. It's randomly generated and if it says it's unavailable that means it's unavailable. – cullanrocks May 21 '19 at 19:26
  • I saw some answer on SO where it states that I need to check network tab. – flash May 21 '19 at 19:30
  • @cullanrocks one quick question `YOUR_CLIENT_ID` is unique api key ? – flash May 21 '19 at 19:37
  • Correct. It's usually like 20-ish character long string. You're not gonna find it in the network tab if you don't have one... – cullanrocks May 21 '19 at 19:45
  • How about this ? https://stackoverflow.com/questions/40992480/getting-a-soundcloud-api-client-id – flash May 21 '19 at 19:47
  • 1
    You can try that to grab the client id. Not sure if it works or not, you should test it, and respond here with the results. But in that thread they are talking about embedding publicly available JSON data, not uploading a track. Even if this does all work, I'm pretty sure you won't be able to upload tracks to other accounts unless you have those client_ids. – cullanrocks May 21 '19 at 19:57
  • @cullanrocks that client_id which is in the network is not unique, its present in every account. – flash May 21 '19 at 20:59

1 Answers1

0

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

jmarcv
  • 24
  • 5