Exemplo n.º 1
0
 protected function publishToSoundcloud(array $new_mp3s)
 {
     if (is_null(SC_TOKEN) && is_null(SC_TOKEN_SECRET)) {
         $soundcloud = new Soundcloud(SC_CONSUMER_KEY, SC_CONSUMER_SECRET);
         $token = $soundcloud->get_request_token('http://a.callback.url.com/');
         echo ">> Your SC_TOKEN is : " . $token['oauth_token'] . "\n";
         echo ">> Your SC_TOKEN_SECRET is : " . $token['oauth_token_secret'] . "\n";
         $login = $soundcloud->get_authorize_url($token['oauth_token']);
         echo ">> Please fill in the file, and visit {$login}\n";
         return;
     } else {
         $sc = new Soundcloud(SC_CONSUMER_KEY, SC_CONSUMER_SECRET, SC_TOKEN, SC_TOKEN_SECRET);
         foreach ($new_mp3s as $item) {
             /* @var $item SimplePie_Item */
             /* @var $mp3 SimplePie_Enclosure */
             $mp3 = $item->get_enclosure(0);
             $title = $item->get_title();
             echo "Publishing {$title}...\n";
             $filename = basename($this->getLinkFromItem($item));
             $post_data = array('track[title]' => $item->get_title(), 'track[asset_data]' => $filename, 'track[sharing]' => 'private', 'track[description]' => strip_tags($item->get_description()));
             $sc->upload_track($post_data);
         }
     }
 }
Exemplo n.º 2
0
 // If a track is submitted.
 if (isset($_POST['submit'])) {
     // We have to make sure it's a valid and supported format by SoundCloud.
     // Note that you also can include artwork for your tracks. Use the same
     // procedure as for the tracks. PNG, JPG, GIF allowed and a max size of 5MB.
     // The artwork field is called track[artwork_data].
     $mimes = array('aac' => 'video/mp4', 'aiff' => 'audio/x-aiff', 'flac' => 'audio/flac', 'mp3' => 'audio/mpeg', 'ogg' => 'audio/ogg', 'wav' => 'audio/x-wav');
     $extension = explode('.', $_FILES['file']['name']);
     $extension = isset($extension[count($extension) - 1]) ? $extension[count($extension) - 1] : NULL;
     $mime = isset($mimes[$extension]) ? $mimes[$extension] : NULL;
     if (isset($mime)) {
         $tmp_file = $tmp_path . $_FILES['file']['name'];
         // Store the track temporary.
         if (move_uploaded_file($_FILES['file']['tmp_name'], $tmp_file)) {
             $post_data = array('track[title]' => stripslashes($_POST['title']), 'track[asset_data]' => realpath($tmp_file), 'track[sharing]' => 'private');
             if ($response = $soundcloud->upload_track($post_data, $mime)) {
                 $response = new SimpleXMLElement($response);
                 $response = get_object_vars($response);
                 $message = 'Success! <a href="' . $response['permalink-url'] . '">Your track</a> has been uploaded!';
                 // Delete the temporary file.
                 unlink(realpath($tmp_file));
             } else {
                 $message = 'Something went wrong while talking to SoundCloud, please try again.';
             }
         } else {
             $message = 'Couldn\'t move file, make sure the temporary path is writable by the server.';
         }
     } else {
         $message = 'SoundCloud support .mp3, .aiff, .wav, .flac, .aac, and .ogg files. Please select a different file.';
     }
 }