opened
scalloty
username_0
pytube.exceptions.RegexMatchError 
issue
created
The-Judge
username_1
Experiencing the same with https://www.youtube.com/watch?v=YGpmxFj0yd4
comment
created
mbeltre
username_2
same here with https://www.youtube.com/watch?v=FrrsTi6M8_Q
comment
created
dbolya
username_3
Here's a fix:

In cypher.py, change pattern starting at line 38 to this:
```Python
    pattern = [
        r'(["\'])signature\1\s*,\s*(?P<sig>[a-zA-Z0-9$]+)\(',
        r'\.sig\|\|(?P<sig>[a-zA-Z0-9$]+)\(',
        r'yt\.akamaized\.net/\)\s*\|\|\s*.*?\s*c\s*&&\s*d\.set\([^,]+\s*,\s*(?:encodeURIComponent\s*\()?(?P<sig>[a-zA-Z0-9$]+)\(',
        r'\bc\s*&&\s*d\.set\([^,]+\s*,\s*(?:encodeURIComponent\s*\()?\s*(?P<sig>[a-zA-Z0-9$]+)\(',
        r'\bc\s*&&\s*d\.set\([^,]+\s*,\s*\([^)]*\)\s*\(\s*(?P<sig>[a-zA-Z0-9$]+)\(',
    ]
```

(these regexes come from [here](https://github.com/rg3/youtube-dl/commit/fa4ac365f69cbd51e4c9801984ebea49a12825b7))

Then the regex_search function in helper.py seems to only use the first regex in the list for some reason, so we also need to fix that. Simplest way is to replace
```Python
                    raise RegexMatchError(
                        'regex pattern ({pattern}) had zero matches'
                        .format(pattern=p),
                    )
```
in helpers.py on line 39 with
```Python
                if p == pattern[-1]:
                    raise RegexMatchError(
                        'regex pattern ({pattern}) had zero matches'
                        .format(pattern=p),
                    )
```
comment
created
The-Judge
username_1
That file refered to is named ``cipher.py``, for those who are puzzled.

For me, that change fixes it, too.

Here's what @username_3 described as a patch:

```
diff --git a/pytube/cipher.py b/pytube/cipher.py
index e048d1f..3db0a4c 100644
--- a/pytube/cipher.py
+++ b/pytube/cipher.py
@@ -36,10 +36,11 @@ def get_initial_function_name(js):
     """
     # c&&d.set("signature", EE(c));
     pattern = [
-        r'yt\.akamaized\.net/\)\s*\|\|\s*'
-        r'.*?\s*c\s*&&\s*d\.set\([^,]+\s*,\s*(?P<sig>[a-zA-Z0-9$]+)\(',
+        r'(["\'])signature\1\s*,\s*(?P<sig>[a-zA-Z0-9$]+)\(',
         r'\.sig\|\|(?P<sig>[a-zA-Z0-9$]+)\(',
-        r'\bc\s*&&\s*d\.set\([^,]+\s*,\s*(?P<sig>[a-zA-Z0-9$]+)\(',
+        r'yt\.akamaized\.net/\)\s*\|\|\s*.*?\s*c\s*&&\s*d\.set\([^,]+\s*,\s*(?:encodeURIComponent\s*\()?(?P<sig>[a-zA-Z0-9$]+)\(',
+        r'\bc\s*&&\s*d\.set\([^,]+\s*,\s*(?:encodeURIComponent\s*\()?\s*(?P<sig>[a-zA-Z0-9$]+)\(',
+        r'\bc\s*&&\s*d\.set\([^,]+\s*,\s*\([^)]*\)\s*\(\s*(?P<sig>[a-zA-Z0-9$]+)\(',
     ]
     logger.debug('finding initial function name')
     return regex_search(pattern, js, group=1)
diff --git a/pytube/helpers.py b/pytube/helpers.py
index 93351a9..aeef190 100644
--- a/pytube/helpers.py
+++ b/pytube/helpers.py
@@ -36,10 +36,11 @@ def regex_search(pattern, string, groups=False, group=None, flags=0):
             regex = re.compile(p, flags)
             results = regex.search(string)
             if not results:
-                raise RegexMatchError(
-                    'regex pattern ({pattern}) had zero matches'
-                    .format(pattern=p),
-                )
+                if p == pattern[-1]:
+                    raise RegexMatchError(
+                        'regex pattern ({pattern}) had zero matches'
+                        .format(pattern=p),
+                    )
             else:
                 logger.debug(
                     'finished regex search: %s',
```

When will this be implemented?? ;)
comment
created
peterrenshaw
username_4
@dboyla change works for me, excellent explanation.
comment
created
formazione
username_5
I have the same error in version 9.5.1, I tryed to do what username_3 suggested, but it does not work.
comment