]> jfr.im git - yt-dlp.git/commitdiff
[extractor/common] Escape `%` in `representation_id` of m3u8
authorpukkandan <redacted>
Fri, 9 Sep 2022 04:28:41 +0000 (09:58 +0530)
committerpukkandan <redacted>
Fri, 9 Sep 2022 22:12:14 +0000 (03:42 +0530)
Closes #4877

yt_dlp/extractor/common.py

index 02a4c6cec6c76d1878003e84462e9a86e715db42..dae952f6a83b3ef90e2a93c9089df742f7c08215 100644 (file)
@@ -2914,6 +2914,8 @@ def extract_Initialization(source):
 
                     def prepare_template(template_name, identifiers):
                         tmpl = representation_ms_info[template_name]
+                        if representation_id is not None:
+                            tmpl = tmpl.replace('$RepresentationID$', representation_id)
                         # First of, % characters outside $...$ templates
                         # must be escaped by doubling for proper processing
                         # by % operator string formatting used further (see
@@ -2928,8 +2930,6 @@ def prepare_template(template_name, identifiers):
                                 t += c
                         # Next, $...$ templates are translated to their
                         # %(...) counterparts to be used with % operator
-                        if representation_id is not None:
-                            t = t.replace('$RepresentationID$', representation_id)
                         t = re.sub(r'\$(%s)\$' % '|'.join(identifiers), r'%(\1)d', t)
                         t = re.sub(r'\$(%s)%%([^$]+)\$' % '|'.join(identifiers), r'%(\1)\2', t)
                         t.replace('$$', '$')