Оптимизирована замена URL в функции change_vmix_datasource_urls
This commit is contained in:
15
get_data.py
15
get_data.py
@@ -14,7 +14,7 @@ from dotenv import load_dotenv
|
||||
from pprint import pprint
|
||||
import nasio
|
||||
import io, os, platform, time
|
||||
import xml.etree.ElementTree as ET
|
||||
import xml.etree.ElementTree as ETя
|
||||
import re
|
||||
from PIL import Image, ImageDraw, ImageFont
|
||||
from io import BytesIO
|
||||
@@ -3194,14 +3194,11 @@ def change_vmix_datasource_urls(xml_data, new_base_url: str) -> bytes:
|
||||
root = ET.fromstring(text)
|
||||
|
||||
# 4. Меняем URL
|
||||
for ds in root.findall(".//datasource[@friendlyName='JSON']"):
|
||||
for inst in ds.findall(".//instance"):
|
||||
url_tag = inst.find(".//state/xml/url")
|
||||
if url_tag is not None and url_tag.text:
|
||||
old_url = url_tag.text.strip()
|
||||
pattern = r"https?\:\/\/\w+\.\w+\.\w{2,}|https?\:\/\/\d{,3}\.\d{,3}\.\d{,3}\.\d{,3}\:\d*"
|
||||
new_url = re.sub(pattern, new_base_url, old_url, count=0, flags=0)
|
||||
url_tag.text = new_url
|
||||
for url_tag in root.findall(".//datasource[@friendlyName='JSON']//instance//state/xml/url"):
|
||||
old_url = url_tag.text.strip()
|
||||
pattern = r'https?:\/\/[^\/]+'
|
||||
new_url = re.sub(pattern, new_base_url, old_url, count=0, flags=0)
|
||||
url_tag.text = new_url
|
||||
|
||||
# 5. Сериализуем обратно в bytes
|
||||
new_xml = ET.tostring(root, encoding="utf-8", method="xml")
|
||||
|
||||
Reference in New Issue
Block a user