Soundcloud Smart Player

I have a lyrics website on WordPress with thousands of lyrics, and I am looking to embed a player on each one. But I have realised it would be tedious and time consuming to do that.

How would I display a dynamic audio player that would find and play a track (using the current post title) from soundcloud?

This could preferably be a html5 audio player or an actual soundcloud embed.

The way it plays out in my head is to do a search, then pass the first result (track url) into a variable, then call the variable in the src part of the player.

Solutions Collecting From Web of "Soundcloud Smart Player"

If a shortcode isn’t too much effort you can use it to construct the soundcloud url for embedding.

add_shortcode('soundcloud_auto', 'soundcloud_auto_shortcode');

function soundcloud_auto_shortcode($atts) {
    global $post;

    $title = str_replace(" ", "", $post->post_title);
    $title = str_replace("-", "", $title);
    $title = str_replace("_", "", $title);

    $slug = sanitize_title($title, str_replace("-", "", $post->post_name));

    return wp_oembed_get(esc_url("http://soundcloud.com/$slug"));
}

Or do something similar using the_content hook.

add_filter('the_content', 'add_soundcloud');

function add_soundcloud($content){
    global $post;

    $title = str_replace(" ", "", $post->post_title);
    $title = str_replace("-", "", $title);
    $title = str_replace("_", "", $title);

    $slug = sanitize_title($title, str_replace("-", "", $post->post_name));

    return $content . wp_oembed_get(esc_url("http://soundcloud.com/$slug"));
}

The API might be a cleaner route.