How to get youtube video id from URL with java?

Er KK Chopra

I want to get the v=id from youtube's URL with java

Example Youtube URL formats:

http://www.youtube.com/watch?v=u8nQa1cJyX8&a=GxdCwVVULXctT2lYDEPllDR0LRTutYfW http://www.youtube.com/watch?v=u8nQa1cJyX8 http://youtu.be/0zM3nApSvMg http://www.youtube.com/user/IngridMichaelsonVEVO#p/a/u/1/KdwsulMb8EQ http://youtu.be/dQw4w9WgXcQ http://www.youtube.com/embed/dQw4w9WgXcQ http://www.youtube.com/v/dQw4w9WgXcQ http://www.youtube.com/e/dQw4w9WgXcQ http://www.youtube.com/watch?v=dQw4w9WgXcQ http://www.youtube.com/?v=dQw4w9WgXcQ http://www.youtube.com/watch?feature=player_embedded&v=dQw4w9WgXcQ http://www.youtube.com/?feature=player_embedded&v=dQw4w9WgXcQ http://www.youtube.com/user/IngridMichaelsonVEVO#p/u/11/KdwsulMb8EQ http://www.youtube-nocookie.com/v/6L3ZvIMwZFM?version=3&hl=en_US&rel=0

or any other youtube format what contains a video id in the url

I am Trying with that :-

  Pattern compiledPattern = Pattern.compile("(?<=v=).*?(?=&|$)",Pattern.CASE_INSENSITIVE);      
        Matcher matcher = compiledPattern.matcher(sourceUrl);
        if(matcher.find()){
            setVideoId(matcher.group());
        }

It is not working only for one URL :-

http://youtu.be/6UW3xuJinEg

Er KK Chopra

I found solution for this .. i expand that URL.. and its working ..

public static String expandUrl(String shortenedUrl)  {
        URL url;
        String expandedURL = "";
        try {
            url = new URL(shortenedUrl);
            // open connection
            HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection(Proxy.NO_PROXY); 
            // stop following browser redirect
            httpURLConnection.setInstanceFollowRedirects(false);
            // extract location header containing the actual destination URL
            expandedURL = httpURLConnection.getHeaderField("Location");
            httpURLConnection.disconnect();
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }    
         return expandedURL;
    }

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How do I get the YouTube video ID from a URL?

How can I get a Youtube video ID from the Youtube API given the video url?

Get youtube video id from youtube url in smarty template?

Get youtube video Id from shared video Url

Flutter Dart : How to extract youtube video ID from video URL?

How do I parse YouTube URLs to get the video ID from a URL using Dart?

I need some help in correcting my codes in php - How to get the video id from a YouTube URL

How to get direct url of video from youtube url?

How to get live video id from YouTube channel

How to get thumbnail of youtube video from url using php and API

Extract the video ID from youtube url in .net

How to get video tags from youtube video?

How to get a video from a youtube playlist by count using java?

How can I get direct video url from YouTube video URL?

Is there solution "get youtube video ID from url" contains mobile web url?

Fetch YouTube Video Id from youtube URL in zend framework

how to get youtube player id and stop video

How to get ID of last uploaded video to YouTube?

How to Get Youtube Video URL Programmatically

Access YouTube Video URL With YouTube Video ID

Youtube Data API - How to get video comments from multiple video id

Regex to extract both video id or playlist id from youtube url

How to get Vimeo video id from thumbnail url

How to get Facebook video id from it's url?

How to get the data of a video from youtube in javascript

Youtube Video Id from URL - Swift3

How do I get a YouTube video thumbnail from the YouTube API?

how to get video id from clicking youtube search page link in a webview

How to Get Video IDs from Youtube video feeds?