How to get youtube video id from URL with java?

前端 未结 6 2015
伪装坚强ぢ
伪装坚强ぢ 2020-12-16 06:51

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

Example Youtube URL formats:

http://www.youtube.com/watch?v=u8nQa1cJyX8&

6条回答
  •  情话喂你
    2020-12-16 07:45

    6UW3xuJinEg (i mean the string after youtu.be/) is the ID most of the time. But for being more sure you can send HTTP GET request to that URL and it will respond you with a HTTP302 redirect response where you can find the actual redirection URL. you can parse that URL your previous code.

    enter image description here

    To send and recieve that request and response you can use libraries like jsoup. but because it's just a simple GET request you can simply use java sockets.

    Connect to youtube.be on 80 port and write this in output stream:

    GET /6UW3xuJinEg HTTP/1.1
    
    
    
    # Don't forget the blank lines
    

提交回复
热议问题