Skip to content

Commit b709144

Browse files
committed
fix: improve regex patterns for M3U parsing and attribute handling (#1353)
1 parent 11b2175 commit b709144

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

utils/constants.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,11 @@
7171
m3u_pattern = re.compile(r"^#EXTINF:-1[\s+,,](?P<attributes>[^,,]+)[,,](?P<name>.*?)\n(?P<value>.+)$")
7272

7373
multiline_m3u_pattern = re.compile(
74-
r"^#EXTINF:-1(?:[\s+,,]*(?P<attributes>[^,,\r\n]+))?[,,](?P<name>.*?)[\r\n]+"
75-
r"(?P<options>(?:#EXTVLCOPT:.*[\r\n]+)*)(?P<value>.*?)(?=\r?\n#EXTINF:-1|\Z)",
74+
r"^#EXTINF:-1(?:[\s+,,]*(?P<attributes>(?:[^,,\r\n\"]+|\"[^\"\r\n]*\")*))?[,,](?P<name>.*?)[\r\n]+"
75+
r"(?P<options>(?:(?:[ \t]*\r?\n)+|#EXTVLCOPT:[^\r\n]*(?:\r?\n|$))*)(?P<value>.*?)(?=\r?\n(?:[ \t]*\r?\n)*#EXTINF:-1|\Z)",
7676
re.MULTILINE | re.DOTALL)
7777

78-
key_value_pattern = re.compile(r'(?P<key>\w+)=(?P<value>\S+)')
78+
key_value_pattern = re.compile(r'(?P<key>[\w-]+)=(?P<value>"[^"]*"|\'[^\']*\'|\S+)')
7979

8080
sub_pattern = re.compile(
8181
r"-|_|\((.*?)\)|((.*?))|\[(.*?)]|「(.*?)」| |||频道|普清|标清|高清|HD|hd|超清|超高|超高清|4K|4k|中央|央视|电视台|台|电信|联通|移动")

utils/tools.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -653,8 +653,8 @@ def get_name_value(content, pattern, open_headers=False, check_value=True):
653653
if not name or (check_value and not value):
654654
continue
655655
data = {"name": name, "value": value}
656-
attributes = {**get_headers_key_value(group_dict.get("attributes", "")),
657-
**get_headers_key_value(group_dict.get("options", ""))}
656+
attributes = {**get_headers_key_value(group_dict.get("options", "")),
657+
**get_headers_key_value(group_dict.get("attributes", ""))}
658658
headers = {
659659
"User-Agent": attributes.get("useragent", ""),
660660
"Referer": attributes.get("referer", ""),

0 commit comments

Comments
 (0)