Player script does not contain a valid function signature according to XCDYouTubeKit

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()

Answer №1

When looking at this pattern:

https?:\/\/(?:www\.)?(youtu(\.?be)?(\.com)?)\/(?:embed\/)?(?:watch\?(?:feature=player_embedded&)?v=)?([A-Za-z0-9_-]{11})

it appears to be capturing the desired IDs with the given regex string.

To check if all necessary characters are covered in the char class:

[A-Za-z0-9_-]

If not, you can simply include any additional characters needed.


You can further explore and modify this expression on this demo. Additionally, watch how it matches against different inputs on this link.


To capture various components of URLs, consider integrating more capturing groups into the expression instead of non-capturing ones:

^https?:\/\/(www\.)?((music\.)?youtu(\.?be)?(\.com)?)\/(embed\/)?(watch\?(feature=player_embedded&(?:amp;)*?)?v=)?(get_video_info\?el=embedded&hl=en&ps=default&video_id=)?([A-Za-z0-9_-]{11})(.*)$

The desired IDs will now be captured by group $10 within this extended regex pattern.

Designing a universal expression for all URLs

List all possible URLs, capture the 11-digit IDs first, then use optional groups ? for various URL components preceding the IDs.

DEMO

Escaping special characters

To escape metacharacters, double backslash them, e.g., \\ instead of \. Your pattern may end up looking like:

^https?:\\/\\/(www\\.)?((music\\.)?youtu(\\.?be)?(\\.com)?)\\/(embed\\/)?(watch\\?(feature=player_embedded&(?:amp;)*?)?v=)?(get_video_info\\?el=embedded&hl=en&ps=default&video_id=)?([A-Za-z0-9_-]{11})(.*)$

Check this demo to see the changes in escaping in your example.

RegEx Visualization

Visualize regular expressions with jex.im:

https://i.sstatic.net/1QIJ6.png

References:

Swift regular expression format?

NSRegularExpression

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Error: The meteor package encountered a SyntaxError due to an unexpected reserved word 'export'

I've made some modifications to a meteor package by adding this line: export const myName = 'my-package' However, I'm encountering an error: export const myName = 'my-package' ^^^^^^ SyntaxError: Unexpected reserved word I ...

When adding margin-left and margin-right, images do not appear in their designated positions

I have a chart displaying images, which are showing up correctly. However, I am facing an issue when I try to add some spacing to the chart by using margin-left and margin-right. Here is the CSS code I included: #chart1 { margin: 0 auto; ...

Python: Mimicking Splinter/Selenium Functionality to Test a JavaScript-Driven Website

My automated bot interacts with a dynamic website using Splinter and Selenium. Despite its effectiveness most of the time, it occasionally encounters exceptions due to random events. Debugging these occurrences is quite challenging, especially since the we ...

Strange rendering issues when using the react material-ui dialog

Exploring the Project Recently, I developed a front-end project focusing on a delivery service using React and Material UI. One interesting feature I added was a Dialog window that pops up when users click on an item, allowing them to customize it. Here i ...

Unable to retrieve variable from ajax success function in response

In my MVC view, I have an ajax call that triggers a chain of 5 functions before completion. Each function contains an if/else statement to return its own error message in case of failure, requiring the original page to be reloaded to display the errors. Ho ...

Modifying content on the fly with a dropdownlist in Knockout framework

Currently experimenting with implementing inline editing through knockout. I stumbled upon this informative thread about Knockout Inline Edit Binding After some tweaks to introduce a "Select" for edit mode, the functionality seems to be working fine. Howe ...

AngularJS ng-map defines the view position using rectangular coordinates

Is there a way to set the position of ng-map view using the ng-map directive not as the center value of [40.74, -74.18], but instead as a rectangle defined by the corner values of the map view (north, south, east, west)? Currently, I have this code: < ...

Avoid causing the newline character to display

var i = 'Hello \n World' console.log(i) /* Output: Hello World */ /* Desired output: Hello \n world */ var j = 'javscr\u0012ipt' console.log(j) /* Output: javscr ipt */ /* Desired output: javscr\u0012ipt */ ...

Testing an ExpressJS route and their corresponding controller individually: a step-by-step guide

I have set up an Express route in my application using the following code snippet (where app represents my Express app): module.exports = function(app) { var controller = require('../../app/controllers/experiment-schema'); app.route('/a ...

Monitoring changes in the size of the parent element with an AngularJS directive

Issue I am facing a challenge with a directive that updates the size of an element based on the window size. The directive monitors changes in window dimensions and adjusts the element accordingly. MyApp.directive('resizeTest', ['$window&a ...

Renaming errors within a project with a complex nested structure using npm

I am encountering an issue in my NodeJS project which consists of nested subprojects with their own package.json files. Whenever I make changes to dependencies in the subprojects, I encounter errors similar to the one below: npm ERR! code ENOENT npm ERR! ...

How can I use jQuery to hide the calendar popup on the Bootstrap date picker?

What is the best way to prevent the calendar popup from appearing when using a Bootstrap date picker with jQuery? $("#id").val('').attr('disabled',true).trigger("liszt:updated"); I have tried using .prop and it's not working for ...

Guide on transferring a wav audio file with javascript and webapi in C#

In order to send an audio wav file to the WebAPI controller for Microsoft Bing Speech API calls, the following steps have been taken: The audio was recorded and converted to base64 data using JavaScript on the client side. An AJAX call was made to in ...

Error: You can't use the 'await' keyword in this context

I encountered a strange issue while using a CLI that reads the capacitor.config.ts file. Every time the CLI reads the file, it throws a "ReferenceError: await is not defined" error. Interestingly, I faced a similar error with Vite in the past but cannot ...

Divide and conquer - meteorjs

I am currently utilizing the most recent version of Meteor. Meteor is designed to keep everything within the same directory structure, like this: MeteorProject -- .meteor -- client -- imports -- server -- test -- node_modules -- packa ...

Creating interactive avatars with Material UI and React to provide a dynamic user

I have developed a simple form validation application using react.js. Each user has a unique profile containing their personal information. I am looking to utilize the first letter of the user's name, for example Peter, where the letter "P" would be d ...

`To filter out JSON data that does not exist in Javascript, follow these steps:``

Utilizing JavaScript Fetch to retrieve JSON data, I am aiming to present the information in a well-arranged HTML layout. I encountered challenges when attempting to process certain content. The majority of the data objects I am parsing include images that ...

Response is sent by Sequelize Foreach loop before data is updated

My goal is to retrieve all content and media from a post, then append it to a new post before sending it as a response for easier access to the data. The issue I'm encountering is that the response is being sent before the content and media are fetche ...

Navigate within the div by scrolling in increments of 100%

I am facing an issue with a div that contains multiple children set to 100% height. My goal is to scroll exactly the height of one child (which is also 100%) on each scroll. However, I am struggling to prevent scrolling multiple steps at a time. I have tri ...

Deriving worth from a JSON object

My JSON data structure has the following format: .... "location" : { "lat" : 37.42140090, "lng" : -122.08537010 }, .... I am having trouble accessing the lat and lng values. Any suggestions on how to do this? Cu ...