This repository has been archived on 2026-01-07. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
resources/javhd/src/utils.py
T
2025-06-03 10:20:03 +08:00

36 lines
970 B
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import re
import os
import json
import time
import csv
from datetime import datetime
from urllib.parse import urlparse
import logging
import config
from urllib.parse import urlparse, urlunparse, parse_qs, urlencode
def replace_lang_param(url: str) -> str:
"""
将URL中的lang参数统一替换为'en',支持路径中包含lang的情况
"""
parsed = urlparse(url)
# 处理路径中的lang参数(如 /ja/model/... 或 /en/model/...
path_parts = parsed.path.split('/')
if len(path_parts) >= 2 and path_parts[1] in ['en', 'ja', 'zh']:
path_parts[1] = 'en' # 替换第二个路径段为'en'
new_path = '/'.join(path_parts)
else:
new_path = parsed.path
# 处理查询参数中的lang(如有)
query = parse_qs(parsed.query)
# 构建新URL
new_parsed = parsed._replace(
path=new_path,
query=urlencode(query, doseq=True)
)
return urlunparse(new_parsed)