• Resolved Gerald

    (@gerital)


    Just for documentation purposes I wanted to post the code I used to add Soundcloud thumbnail grabbing to this plugin:

    1. As I have the URL in a separte field () I only check with preg_match if it contains the string soundcloud.com:
    preg_match( '/soundcloud.com/', $content, $soundcloud_matches ) )

    2. In case it matches, I first get the track ID from the URL and then the artwork_url:

    elseif ($soundcloud_matches) {
    
    	$url = "https://api.soundcloud.com/resolve.json?url=".$content."&client_id=XXX";
    	$track_json = file_get_contents($url);
    	$track = json_decode($track_json);
    	$video_thumbnail_url = str_replace("large", "crop", $track->artwork_url);
    
    }

    https://wordpress.org/plugins/automatic-featured-images-from-videos/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support Michael Beckwith

    (@tw2113)

    The BenchPresser

    Cool, thanks for sharing this with others in case they want to do some level of soundcloud artwork support.

    Hi Gerital,

    Could you please elaborate a little more on where to add this code to get the thumbnail from SoundCloud?

    I’ve tried hacking into the plugin file but I can’t seem to get it to work.

    Does the code go into this bit?

    if ( $youtube_id ) {
    		// Check to see if our max-res image exists.
    		$remote_headers = wp_remote_head( 'http://img.youtube.com/vi/' . $youtube_id . '/maxresdefault.jpg' );
    		$is_404 = ( 404 === wp_remote_retrieve_response_code( $remote_headers ) );
    		$video_thumbnail_url = ( ! $is_404 ) ? 'http://img.youtube.com/vi/' . $youtube_id . '/maxresdefault.jpg' : 'http://img.youtube.com/vi/' . $youtube_id . '/hqdefault.jpg';
    
    	}
    • This reply was modified 7 years, 5 months ago by Yulia1872.
    Plugin Support Michael Beckwith

    (@tw2113)

    The BenchPresser

    @yulia1872, you’d need to check and see if SoundCloud offers any sort of API endpoint that includes soundcloud graphics, and use those URLs if a SoundCloud ID is provided.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Offtopic: Extract thumbnail from Soundcloud’ is closed to new replies.