42 lines
1.2 KiB
Python
42 lines
1.2 KiB
Python
from languages import LANG_CODES, REVERSE_LANG_CODES
|
|
|
|
extensions=("mp4", "mkv", "avi", "mov", "wmv", "flv", "webm", "lrv", "gif")
|
|
|
|
def check_video_ext(extension: str) -> bool:
|
|
if extension.lower().strip('.') in extensions:
|
|
return True
|
|
return False
|
|
|
|
def normalize_language(lang: str) -> str:
|
|
"""
|
|
Input: 'ger', 'DE', 'German', 'GERMAN'
|
|
Output: 'German'
|
|
"""
|
|
if not lang:
|
|
return "Undefined"
|
|
|
|
# 1. Clean the input
|
|
query = lang.strip().lower()
|
|
|
|
# 2. Check if it's already a code (e.g., 'de' or 'ger')
|
|
if query in LANG_CODES:
|
|
return LANG_CODES[query]
|
|
|
|
# 3. Check if it's a full name (e.g., 'german')
|
|
# We need a case-insensitive check against the names in REVERSE_LANG_CODES
|
|
for full_name in REVERSE_LANG_CODES:
|
|
if full_name.lower() == query:
|
|
return full_name
|
|
|
|
return "Undefined"
|
|
|
|
def normalize_lang_code(lang: str) -> str:
|
|
"""
|
|
Input: 'ger', 'DE', 'German', 'GERMAN'
|
|
Output: 'de' (the canonical media code (ISO 639-1))
|
|
"""
|
|
# First, get the standard full name
|
|
full_name = normalize_language(lang)
|
|
|
|
# Then, look up that full name in the reverse table
|
|
return REVERSE_LANG_CODES.get(full_name, "und") |