从链接获取youtube id [英] getting the youtube id from a link
问题描述
我收到此代码以从
www.youtube.com/watch?v=xxxxxxx
I got this code to get the youtube id from the links like www.youtube.com/watch?v=xxxxxxx
URL youtubeURL = new URL(link);
youtubeURL.getQuery();
基本上这会让我很容易识别你的身份v = xxxxxxxx
basically this will get me the id easily v=xxxxxxxx
但我注意到有时youtube链接会像这样
but I noticed sometime youtube links will be like this
http://gdata.youtube.com/feeds/api/videos/xxxxxx
我从Feed
获取链接所以我也是需要为那个构建一个正则表达式或者是一个解析器来为我做这个吗?
I am getting the links from a feed so do I need to build a regex for that or theres a parser to get that for me ?
推荐答案
试过其他的但我的失败了case - 调整正则表达式以适合我的网址
Tried the other ones but failed in my case - adjusted the regex to fit for my urls
String pattern = "(?<=watch\\?v=|/videos/|embed\\/)[^#\\&\\?]*";
Pattern compiledPattern = Pattern.compile(pattern);
Matcher matcher = compiledPattern.matcher(url);
if(matcher.find()){
return matcher.group();
}
这适用于:(您还可以实施安全检查youtubeid length = 11)
This one works for: (you could also implement a security check youtubeid length = 11 )
http://www.youtube.com/watch?v=384IUU43bfQ
http://gdata.youtube.com/feeds/api/videos/xTmi7zzUa-M&whatever
Woq5iX9XQhA
Woq5iX9XQhA
384IUU43bfQ
384IUU43bfQ
xTmi7zzUa-M
xTmi7zzUa-M
这篇关于从链接获取youtube id的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!