Forums

Grabbing the thumb from a Soundcloud URL. (1 post)

  1. enderpal444
    Member
    Posted 7 months ago #

    I use this function to grab the thumbs from a youtube video URL which works great...

    function get_youtube_screen_link( $url = '', $type = 'default', $echo = true ) {
        if( empty( $url ) )
            return false;
    
        if( !isset( $type ) )
            $type = '';
    
        $url = esc_url( $url );
    
        preg_match("|[\\?&]v=([^&#]*)|",$url,$vid_id);
    
        if( !isset( $vid_id[1] ) )
            return false;
    
        $img_server_num =  'i'. rand(1,4);
    
        switch( $type ) {
            case 'large':
                $img_link = "http://{$img_server_num}.ytimg.com/vi/{$vid_id[1]}/0.jpg";
                break;
            case 'first':
                // Thumbnail of the first frame
                $img_link = "http://{$img_server_num}.ytimg.com/vi/{$vid_id[1]}/1.jpg";
                break;
            case 'small':
                // Thumbnail of a later frame(i'm not sure how they determine this)
                $img_link = "http://{$img_server_num}.ytimg.com/vi/{$vid_id[1]}/2.jpg";
                break;
            case 'default':
            case '':
            default:
                $img_link = "http://{$img_server_num}.ytimg.com/vi/{$vid_id[1]}/default.jpg";
                break;
        }
        if( $echo )
            echo $img_link;
        else
            return $img_link;
    
    }

    My question is how can I adapt this to grab the thumb from a Soundcloud URL?

Reply

You must log in to post.

About this Topic