Repaired a lot of Media Management
This commit is contained in:
1
check_video/__init__.py
Normal file
1
check_video/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from .check_video import check_video_ext, normalize_language, normalize_lang_code
|
||||
BIN
check_video/__pycache__/__init__.cpython-314.pyc
Normal file
BIN
check_video/__pycache__/__init__.cpython-314.pyc
Normal file
Binary file not shown.
BIN
check_video/__pycache__/check_video.cpython-314.pyc
Normal file
BIN
check_video/__pycache__/check_video.cpython-314.pyc
Normal file
Binary file not shown.
BIN
check_video/__pycache__/languages.cpython-314.pyc
Normal file
BIN
check_video/__pycache__/languages.cpython-314.pyc
Normal file
Binary file not shown.
42
check_video/check_video.py
Normal file
42
check_video/check_video.py
Normal file
@@ -0,0 +1,42 @@
|
||||
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")
|
||||
Reference in New Issue
Block a user