I need help finding a regular expression to match these Youtube links. I'm feeling lost and unsure of what to do.
https://www.youtube.com/watch?v=2BS3oePljr8
http://www.youtube.com/watch?v=iwGFalTRHDA
http://www.youtube.com/watch?v=iwGFalTRHDA&feature=related
http://youtu.be/iwGFalTRHDA
http://youtu.be/n17B_uFF4cA
http://www.youtube.com/embed/watch?feature=player_embedded&v=r5nB9u4jjy4
http://www.youtube.com/watch?v=t-ZRX8984sc
http://youtu.be/t-ZRX8984sc
I'm not sure if there is a regex I can use that covers most of these cases, any assistance would be greatly appreciated.
Problems encountered when trying to load/play videos:
[XCDYouTubeKit] No signature function in player script
[XCDYouTubeKit] Video operation finished with error: This video is unavailable.
Domain: XCDYouTubeVideoErrorDomain
Code: 150
NSLocalizedDescription = "This video is unavailable.";
NSURL = "https://www.youtube.com/get_video_info?el=embedded&hl=en&ps=default&video_id=2BS3oePljr8";
Code:
NSArray<NSString *>*patterns = @[@"\\.sig\\|\\|([a-zA-Z0-9$]+)\\(",
@"[\"']signature[\"']\\s*,\\s*([^\\(]+)",
@"yt\\.akamaized\\.net/\\)\\s*\\|\\|\\s*.*?\\s*c\\s*&&\\s*d\\.set\\([^,]+\\s*,\\s*(?:encodeURIComponent\\s*\\()?([a-zA-Z0-9$]+)\\(",
@"\\bc\\s*&&\\s*d\\.set\\([^,]+\\s*,\\s*(?:encodeURIComponent\\s*\\()?\\s*([a-zA-Z0-9$]+)\\(",
@"\\bc\\s*&&\\s*d\\.set\\([^,]+\\s*,\\s*\\([^)]*\\)\\s*\\(\\s*([a-zA-Z0-9$]+)\\("
];
There's also this information available: //See list of regex patterns here https://github.com/rg3/youtube-dl/blob/master/youtube_dl/extractor/youtube.py#L1179
However, this appears quite complex and confusing to me.
Additional code required to play the Youtube video:
XCDYouTubeClient.default().getVideoWithIdentifier("2BS3oePljr8") { (video: XCDYouTubeVideo?, error: Error?) in
if let streamURL = video?.streamURLs[XCDYouTubeVideoQuality.medium360.rawValue] {
player = AVPlayer(url: streamURL)
playerLayer = AVPlayerLayer(player: player)
let playerLayerView = UIView()
playerLayerView.frame.size = CGSize(width: self.page3View.frame.width / 1.25, height: self.page3View.frame.height / 2)
playerLayerView.center = CGPoint(self.page3View.frame.width * 0.5, self.page3View.frame.height * 0.5)
playerLayer.frame = CGRect(0.0, 0.0, playerLayerView.frame.width, playerLayerView.frame.height)
playerLayer.videoGravity = AVLayerVideoGravity.resizeAspectFill
playerLayer.zPosition = 2
playerLayer.backgroundColor = UIColor.black.cgColor
playerLayerView.layer.addSublayer(playerLayer)
self.page3View.insertSubview(playerLayerView, at: 2)
player.seek(to: kCMTimeZero)
player.play()