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