Download models/ModelFile.py from Fvitu/Offliner: direct link, hf CLI and curl.
- Browser
- Download file 3.41 kB
-
https://huggingface.co/spaces/Fvitu/Offliner/resolve/main/models/ModelFile.py
- Command line
-
hf download hf://spaces/Fvitu/Offliner/models/ModelFile.py
-
curl -L -o ModelFile.py https://huggingface.co/spaces/Fvitu/Offliner/resolve/main/models/ModelFile.py
3.41 kB
| """ | |
| Modelo de Configuraci贸n - Gestiona la configuraci贸n del descargador. | |
| La configuraci贸n se almacena en el navegador del usuario (localStorage). | |
| """ | |
| import logging | |
| logger = logging.getLogger(__name__) | |
| # Configuraci贸n por defecto para nuevos usuarios | |
| DEFAULT_CONFIG = { | |
| "Client_ID": "", | |
| "Secret_ID": "", | |
| "Calidad_audio_video": "avg", | |
| "Formato_audio": "mp3", | |
| "Formato_video": "mp4", | |
| "Descargar_video": False, | |
| "Descargar_audio": True, | |
| "Fuente_descarga": "YouTube", | |
| "Scrappear_metadata": True, | |
| "Mostrar_tiempo_de_ejecucion": True, | |
| "SponsorBlock_enabled": False, | |
| # Categories -> Sponsor and non-music segments | |
| # "sponsor", "intro", "outro", "selfpromo", "preview", "filler", "interaction", "music_offtopic" | |
| "SponsorBlock_categories": ["sponsor", "music_offtopic"], | |
| "Preferir_YouTube_Music": False, | |
| "cookies_content": "", | |
| "cookies_filepath": "", | |
| } | |
| class ModelFile: | |
| """Modelo para gestionar la configuraci贸n del descargador.""" | |
| def validate_config(cls, config_dict): | |
| """ | |
| Valida y sanitiza una configuraci贸n. | |
| Args: | |
| config_dict: Diccionario con la configuraci贸n | |
| Returns: | |
| dict: Configuraci贸n validada y sanitizada | |
| """ | |
| validated = DEFAULT_CONFIG.copy() | |
| if config_dict.get("Calidad_audio_video") in ["min", "avg", "max"]: | |
| validated["Calidad_audio_video"] = config_dict["Calidad_audio_video"] | |
| if config_dict.get("Formato_audio") in ["mp3", "wav", "m4a", "flac"]: | |
| validated["Formato_audio"] = config_dict["Formato_audio"] | |
| if config_dict.get("Formato_video") in ["mp4", "mov", "mkv", "webm"]: | |
| validated["Formato_video"] = config_dict["Formato_video"] | |
| # Preserve credentials and cookie sources when provided. | |
| for text_field in [ | |
| "Client_ID", | |
| "Secret_ID", | |
| "cookies_content", | |
| "cookies_filepath", | |
| ]: | |
| value = config_dict.get(text_field) | |
| if isinstance(value, str): | |
| validated[text_field] = value | |
| # Campos booleanos | |
| bool_fields = [ | |
| "Descargar_video", | |
| "Descargar_audio", | |
| "Scrappear_metadata", | |
| "Mostrar_tiempo_de_ejecucion", | |
| "SponsorBlock_enabled", | |
| "Preferir_YouTube_Music", | |
| ] | |
| for field in bool_fields: | |
| if isinstance(config_dict.get(field), bool): | |
| validated[field] = config_dict[field] | |
| # Validar Fuente_descarga | |
| if config_dict.get("Fuente_descarga") in ["YouTube", "Spotify"]: | |
| validated["Fuente_descarga"] = config_dict["Fuente_descarga"] | |
| # Validar categor铆as de SponsorBlock | |
| valid_categories = [ | |
| "sponsor", | |
| "intro", | |
| "outro", | |
| "selfpromo", | |
| "preview", | |
| "filler", | |
| "interaction", | |
| "music_offtopic", | |
| ] | |
| if isinstance(config_dict.get("SponsorBlock_categories"), list): | |
| validated["SponsorBlock_categories"] = [ | |
| cat | |
| for cat in config_dict["SponsorBlock_categories"] | |
| if cat in valid_categories | |
| ] | |
| return validated | |