Results 1 to 6 of 6
Like Tree1Likes
  • 1 Post By Norm

Thread: Please how do i extract youtube video id from these links maybe using Regex

  1. #1
    sledjama is offline Member
    Join Date
    Jun 2011
    Posts
    4
    Rep Power
    0

    Default Please how do i extract youtube video id from these links maybe using Regex

    Java Code:
    http://www.youtube.com/v/[videoid]
    http://www.youtube.com/watch?v=[videoid]
    http://www.youtube.com/watch?v=[videoid]&feature=blabla
    Thanks
    Last edited by DarrylBurke; 06-25-2011 at 05:00 PM. Reason: Removed automatically generated url tags and wrapped the urls in code tags

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,298
    Rep Power
    20

    Default

    The samples you posted don't reveal a regularity that could be used to extract the ID. Does the "videoid" follow any pattern?

    db

  3. #3
    sledjama is offline Member
    Join Date
    Jun 2011
    Posts
    4
    Rep Power
    0

    Default

    the video id is a 11 character string that could be a-z A-Z 0-9 underscore and dash
    it could be
    youtube.com/?v=videoid
    youtube.com/v/videoid
    youtube.com/watch?v=videoid
    youtube.com/watch?v=videoid&feature=whatever&this=that

    i got stole this code
    Java Code:
    Pattern p = Pattern.compile("http.*\\?v=([a-zA-Z0-9_\\-]+)(?:&.)*");
    Matcher m = p.matcher(input);
    
    if (m.matches()) {
    input = m.group(1);
    }
    
    return input;
    from here (http://gdata-java-client.googlecode....iteClient.java)

    i know thats what the coder used for videoid extraction but i just dont know if this solve the above

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,513
    Rep Power
    25

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,298
    Rep Power
    20

    Default

    Thanks Norm.

    db

  6. #6
    Dark's Avatar
    Dark is offline Senior Member
    Join Date
    Apr 2011
    Location
    Camp Lejuene, North Carolina
    Posts
    643
    Rep Power
    4

    Default

    You could check the strings with .contains and depending on which one link you get is how you could cut from the strings. That is if you have a limited number of link variations.
    • Use [code][/code] tags when posting code. That way people don't want to stab their eyes out when trying to help you.
    • +Rep people for helpful posts.

Similar Threads

  1. tomcat embedded youtube video
    By crank6015 in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 06-04-2011, 01:30 AM
  2. Youtube API - retrieve video on user input
    By Jman85 in forum New To Java
    Replies: 4
    Last Post: 11-11-2010, 06:15 AM
  3. youtube Video downloads
    By Gloomy in forum New To Java
    Replies: 2
    Last Post: 09-06-2010, 05:40 AM
  4. embed the video in the html page by youtube api
    By javastuden in forum Advanced Java
    Replies: 6
    Last Post: 06-17-2010, 01:23 PM
  5. download youtube video
    By lalit.wientech in forum Networking
    Replies: 11
    Last Post: 03-24-2010, 04:30 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •