gpt4 book ai didi

android - 如何忽略 “&feature=xxxxxxxxx”以从YouTube网址获取视频ID

转载 作者:行者123 更新时间:2023-12-03 05:59:18 25 4
gpt4 key购买 nike

这是我的正则表达式:

"(?:http|https|)(?::\\/\\/|)(?:www.|m.)(?:youtu\\.be\\/|youtube\\.com(?:\\/embed\\/|\\/v\\/|\\/watch\\?v=|\\/ytscreeningroom\\?v=|\\/feeds\\/api\\/videos\\/|\\/user\\S*[^\\w\\-\\s]|\\S*[^\\w\\-\\s]))([\\w\\-]{11})[a-z0-9;:@?&%=+\\/\\$_.-]*"

无法从此URL获取ID是:

http://www.youtube.com/watch?v=AfG82u8xEKo&feature=youtube_gdata_player9

最佳答案

试试这个就像魅力一样工作

public String getVideoId(String videoUrl) {

String video_id = "";
if (videoUrl != null && videoUrl.trim().length() > 0) {
String s = "^.*(?:youtu.be\\/|v\\/|e\\/|u\\/\\w+\\/|embed\\/|v=)([^#\\&\\?]*).*";
CharSequence input = videoUrl;
Pattern pattern = Pattern.compile(s, Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(input);
if (matcher.matches()) {
System.out.println("DATA" + matcher.group(1));
String groupIndex1 = matcher.group(1);
if (groupIndex1 != null && groupIndex1.length() == 11)
video_id = groupIndex1;
}
}

System.out.println("VIDEOID" + video_id);
return video_id;
}

关于android - 如何忽略 “&feature=xxxxxxxxx”以从YouTube网址获取视频ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24625962/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com