Android Open Source - YouTubePlayerActivity Youtube Url Parser






From Project

Back to project page YouTubePlayerActivity.

License

The source code is released under:

MIT License

If you think the Android project YouTubePlayerActivity listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.thefinestartist.ytpa.utils;
//from  w w w  .j a  va2s .c om
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created by TheFinestArtist on 2/15/15.
 */
public class YouTubeUrlParser {

    // (?:youtube(?:-nocookie)?\.com\/(?:[^\/\n\s]+\/\S+\/|(?:v|e(?:mbed)?)\/|\S*?[?&]v=)|youtu\.be\/)([a-zA-Z0-9_-]{11})
    final static String reg = "(?:youtube(?:-nocookie)?\\.com\\/(?:[^\\/\\n\\s]+\\/\\S+\\/|(?:v|e(?:mbed)?)\\/|\\S*?[?&]v=)|youtu\\.be\\/)([a-zA-Z0-9_-]{11})";

    public static String getVideoId(String videoUrl) {
        if (videoUrl == null || videoUrl.trim().length() <= 0)
            return null;

        Pattern pattern = Pattern.compile(reg, Pattern.CASE_INSENSITIVE);
        Matcher matcher = pattern.matcher(videoUrl);

        if (matcher.find())
            return matcher.group(1);
        return null;
    }

    public static String getVidoeUrl(String videoId) {
        return "http://youtu.be/" + videoId;
    }
}




Java Source Code List

com.thefinestartist.ytpa.YouTubePlayerActivity.java
com.thefinestartist.ytpa.enums.Orientation.java
com.thefinestartist.ytpa.sample.ApplicationTest.java
com.thefinestartist.ytpa.sample.MainActivity.java
com.thefinestartist.ytpa.utils.AudioUtil.java
com.thefinestartist.ytpa.utils.StatusBarUtil.java
com.thefinestartist.ytpa.utils.YoutubeUrlParser.java
com.thefinestartist.ytpa.utils.YoutubeUtil.java