use 'util.re()' in more places

continuation of b5c88b3d3e
This commit is contained in:
Mike Fährmann
2025-06-23 20:27:40 +02:00
parent c08833aed9
commit 434bf3b1f3
5 changed files with 10 additions and 17 deletions

View File

@@ -492,8 +492,7 @@ class InputManager():
# url
if " #" in line or "\t#" in line:
if strip_comment is None:
import re
strip_comment = re.compile(r"\s+#.*").sub
strip_comment = util.re(r"\s+#.*").sub
line = strip_comment("", line)
if gconf or lconf:
url = ExtendedUrl(line, gconf, lconf)

View File

@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
# Copyright 2023 Mike Fährmann
# Copyright 2023-2025 Mike Fährmann
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
@@ -8,7 +8,6 @@
""" """
import re
import time
import logging
import operator
@@ -32,7 +31,7 @@ def parse(actionspec):
for event, spec in actionspec:
level, _, pattern = event.partition(":")
search = re.compile(pattern).search if pattern else util.true
search = util.re(pattern).search if pattern else util.true
if isinstance(spec, str):
type, _, args = spec.partition(" ")
@@ -138,7 +137,7 @@ def action_print(opts):
def action_status(opts):
op, value = re.match(r"\s*([&|^=])=?\s*(\d+)", opts).groups()
op, value = util.re(r"\s*([&|^=])=?\s*(\d+)").match(opts).groups()
op = {
"&": operator.and_,

View File

@@ -9,7 +9,6 @@
"""Filesystem path handling"""
import os
import re
import shutil
import functools
from . import util, formatter, exception
@@ -148,8 +147,7 @@ class PathFormat():
def func(x, c=chars, r=repl):
return x.replace(c, r)
else:
return functools.partial(
re.compile("[" + chars + "]").sub, repl)
return functools.partial(util.re(f"[{chars}]").sub, repl)
return func
def _process_repl_dict(self, chars):

View File

@@ -7,7 +7,6 @@
# published by the Free Software Foundation.
import os
import re
import sys
from .extractor.common import Extractor, Message
@@ -184,7 +183,7 @@ class UpdateExtractor(Extractor):
tag = channel
exact = True
if re.match(r"\d\.\d+\.\d+", tag):
if util.re_compile(r"\d\.\d+\.\d+").match(tag):
tag = "v" + tag
try:

View File

@@ -8,7 +8,6 @@
"""Helpers for interacting with youtube-dl"""
import re
import shlex
import itertools
from . import text, util, exception
@@ -258,13 +257,12 @@ def parse_command_line(module, argv):
cookiesfrombrowser = getattr(opts, "cookiesfrombrowser", None)
if cookiesfrombrowser:
match = re.fullmatch(r"""(?x)
pattern = util.re(r"""(?x)
(?P<name>[^+:]+)
(?:\s*\+\s*(?P<keyring>[^:]+))?
(?:\s*:\s*(?!:)(?P<profile>.+?))?
(?:\s*::\s*(?P<container>.+))?
""", cookiesfrombrowser)
if match:
(?:\s*::\s*(?P<container>.+))?""")
if match := pattern.fullmatch(cookiesfrombrowser):
browser, keyring, profile, container = match.groups()
if keyring is not None:
keyring = keyring.upper()
@@ -524,7 +522,7 @@ def legacy_postprocessors(opts, module, ytdlp, compat_opts):
if len(dur) == 2 and all(t is not None for t in dur):
remove_ranges.append(tuple(dur))
continue
remove_chapters_patterns.append(re.compile(regex))
remove_chapters_patterns.append(util.re(regex))
if opts.remove_chapters or sponsorblock_query:
postprocessors.append({
"key": "ModifyChapters",