Basically I have a Youtube URL as string, I want to extract the video Id from that URL. I found some code in objective c that is as below:
NSError *error = NULL;
To get video Id from Youtube Url, use code # Swift4 :
var videoId = ""
if youtubeLink.lowercased().contains("youtu.be"){
linkString = youtubeLink
if let range = linkString.range(of: "be/"){
videoId = youtubeLink[range.upperBound...].trimmingCharacters(in: .whitespaces)
}
}
else if youtubeLink.lowercased().contains("youtube.com"){
linkString = youtubeLink
if let range = linkString.range(of: "?v="){
videoId = youtubeLink[range.upperBound...].trimmingCharacters(in: .whitespaces)
}
}
Hope will be helping! :)