diff --git a/config.yaml b/config.yaml new file mode 100644 index 0000000..9dc174b --- /dev/null +++ b/config.yaml @@ -0,0 +1,37 @@ +# config for Jellyfin file modificator for customization +start_directory: '.' # Startverzeichnis für die Suche + +modifications: + - file_pattern: 'session-login-index-html\..*\.bundle\.js' + insert_rules: + - after_text: '
' + insert_text: '' + + # Instancename, Jellyseer I-Frame + - file_pattern: 'index.html' + insert_rules: + - before_text: '' + insert_text: 'New content to insert' + replace_rules: + - old_text: 'Jellyfin' + new_text: 'SpaceCloud - Cinema' + + + + + - file_pattern: 'another-file-pattern\.js' + insert_rules: + - before_text: 'specific-text-to-search-for' + insert_text: 'Neuer Inhalt vor dem Zieltext' + + - after_text: 'another-specific-text' + insert_text: 'Neuer Inhalt nach dem Zieltext' + + - file_pattern: '\.js$' + replace_rules: + - old_text: 'const version = ' + new_text: 'const version = ' + + insert_rules: + - before_text: 'function initializeApp() {' + insert_text: '// Neue Initialisierungsvorbereitungen' \ No newline at end of file diff --git a/customize-WebUI internal config test.py b/customize-WebUI internal config test.py new file mode 100644 index 0000000..446125f --- /dev/null +++ b/customize-WebUI internal config test.py @@ -0,0 +1,92 @@ +import os +import re +import sys + +# Konfiguration direkt im Skript +MODIFICATIONS = [ + { + 'file_pattern': r'session-login-index-html\..*\.bundle\.js', + 'rules': [ + { + 'after_text': '
', + 'insert_text': '' + }, + { + 'after_text': '
', + 'insert_text': '

Zusätzlicher Informationstext

' + } + ] + }, + { + 'file_pattern': r'another-file-pattern\.js', + 'rules': [ + { + 'after_text': 'specific-text-to-search-for', + 'insert_text': 'New content to insert' + } + ] + } +] + +def modify_files(start_directory='.'): + """ + Modifiziert Dateien basierend auf vordefinierter Konfiguration. + + :param start_directory: Startverzeichnis für die Suche + """ + files_modified = 0 + + # Durch jede Konfiguration gehen + for config in MODIFICATIONS: + search_pattern = config['file_pattern'] + insert_rules = config['rules'] + + # Rekursive Suche ab dem Startverzeichnis + for root, dirs, files in os.walk(start_directory): + for filename in files: + # Überprüfe Dateinamenmuster + if re.search(search_pattern, filename): + full_path = os.path.join(root, filename) + + try: + with open(full_path, 'r', encoding='utf-8') as file: + content = file.read() + + modified = False + modified_content = content + + # Durchlaufe alle Einfügeregeln für diese Datei + for rule in insert_rules: + search_text = rule['after_text'] + insert_text = rule['insert_text'] + + # Prüfe, ob der Einfügetext bereits vorhanden ist + if insert_text not in modified_content: + modified_content = modified_content.replace( + search_text, + f'{search_text}\n{insert_text}' + ) + modified = True + + # Speichere die Datei, wenn Änderungen vorgenommen wurden + if modified: + with open(full_path, 'w', encoding='utf-8') as file: + file.write(modified_content) + + files_modified += 1 + print(f'Modifiziert: {full_path}') + + except Exception as e: + print(f'Fehler bei Datei {full_path}: {e}') + + print(f'\nAnzahl modifizierter Dateien: {files_modified}') + +def main(): + # Optionaler Startpfad als Argument + start_directory = sys.argv[1] if len(sys.argv) > 1 else '.' + + print(f'Suche ab Verzeichnis: {os.path.abspath(start_directory)}') + modify_files(start_directory) + +if __name__ == '__main__': + main() \ No newline at end of file diff --git a/customize-WebUI-V3.py b/customize-WebUI-V3.py new file mode 100644 index 0000000..a3df79e --- /dev/null +++ b/customize-WebUI-V3.py @@ -0,0 +1,95 @@ +import os +import re +import sys +import yaml + +def modify_files(config_path): + """ + Modifiziert Dateien basierend auf einer YAML-Konfigurationsdatei. + + :param config_path: Pfad zur Konfigurationsdatei + """ + # load config + with open(config_path, 'r', encoding='utf-8') as config_file: + config = yaml.safe_load(config_file) + + files_modified = 0 + + # iterate trough every config + for entry in config['modifications']: + search_pattern = entry.get('file_pattern') + insert_rules = entry.get('insert_rules', []) + replace_rules = entry.get('replace_rules', []) + + # recursiv search starting at start dir + for root, dirs, files in os.walk(config.get('start_directory', '.')): + for filename in files: + # check filenamepattern + if re.search(search_pattern, filename): + full_path = os.path.join(root, filename) + + try: + with open(full_path, 'r', encoding='utf-8') as file: + content = file.read() + + modified = False + modified_content = content + + # iterate trough insert rules + for rule in insert_rules: + insert_text = rule.get('insert_text') + + # insert after specific text + if 'after_text' in rule: + search_text = rule.get('after_text') + if insert_text not in modified_content: + modified_content = modified_content.replace( + search_text, + f'{search_text}\n{insert_text}' + ) + modified = True + + # insert before spicific text + elif 'before_text' in rule: + search_text = rule.get('before_text') + if insert_text not in modified_content: + modified_content = modified_content.replace( + search_text, + f'{insert_text}\n{search_text}' + ) + modified = True + + # iterate replace rules + for rule in replace_rules: + old_text = rule.get('old_text') + new_text = rule.get('new_text') + + # check, if the text to be replaced, exists + if old_text in modified_content: + modified_content = modified_content.replace(old_text, new_text) + modified = True + + # save changed files + if modified: + with open(full_path, 'w', encoding='utf-8') as file: + file.write(modified_content) + + files_modified += 1 + print(f'Modified: {full_path}') + + except Exception as e: + print(f'Error modifying file {full_path}: {e}') + + print(f'\nAnzahl modifizierter Dateien: {files_modified}') + +def main(): + # path of config file as argument + if len(sys.argv) < 2: + print("Error: Provide a path to the config.yaml file") + sys.exit(1) + + config_path = sys.argv[1] + modify_files(config_path) + +if __name__ == '__main__': + main() \ No newline at end of file diff --git a/customize-WebUI.py b/customize-WebUI.py new file mode 100644 index 0000000..1ae1c35 --- /dev/null +++ b/customize-WebUI.py @@ -0,0 +1,150 @@ +import os +import re +import sys +import yaml + +def load_configuration(config_path): + """ + Load configuration from a YAML file. + + :param config_path: Path to the configuration file + :return: Loaded configuration dictionary + """ + with open(config_path, 'r', encoding='utf-8') as config_file: + return yaml.safe_load(config_file) + +def matches_file_pattern(filename, pattern): + """ + Check if filename matches the given pattern. + + :param filename: Name of the file + :param pattern: Regex pattern to match + :return: Boolean indicating if filename matches + """ + return re.search(pattern, filename) is not None + +def apply_insert_rules(content, insert_rules): + """ + Apply insertion rules to the content. + + :param content: Original file content + :param insert_rules: List of insertion rules + :return: Modified content and modification flag + """ + modified_content = content + modified = False + + for rule in insert_rules: + insert_text = rule.get('insert_text') + + # Insert after specific text + if 'after_text' in rule: + search_text = rule.get('after_text') + if insert_text not in modified_content: + modified_content = modified_content.replace( + search_text, + f'{search_text}\n{insert_text}' + ) + modified = True + + # Insert before specific text + elif 'before_text' in rule: + search_text = rule.get('before_text') + if insert_text not in modified_content: + modified_content = modified_content.replace( + search_text, + f'{insert_text}\n{search_text}' + ) + modified = True + + return modified_content, modified + +def apply_replace_rules(content, replace_rules): + """ + Apply replacement rules to the content. + + :param content: Original file content + :param replace_rules: List of replacement rules + :return: Modified content and modification flag + """ + modified_content = content + modified = False + + for rule in replace_rules: + old_text = rule.get('old_text') + new_text = rule.get('new_text') + + # Replace text if found + if old_text in modified_content: + modified_content = modified_content.replace(old_text, new_text) + modified = True + + return modified_content, modified + +def modify_files(config): + """ + Modify files based on configuration rules. + + :param config: Configuration dictionary + :return: Number of modified files + """ + files_modified = 0 + start_directory = config.get('start_directory', '.') + + # Process each modification entry + for entry in config.get('modifications', []): + search_pattern = entry.get('file_pattern') + insert_rules = entry.get('insert_rules', []) + replace_rules = entry.get('replace_rules', []) + + # Walk through directory + for root, _, files in os.walk(start_directory): + for filename in files: + # Check if file matches pattern + if matches_file_pattern(filename, search_pattern): + full_path = os.path.join(root, filename) + + try: + # Read file content + with open(full_path, 'r', encoding='utf-8') as file: + content = file.read() + + # Apply insert rules + content_after_insert, insert_modified = apply_insert_rules( + content, insert_rules + ) + + # Apply replace rules + final_content, replace_modified = apply_replace_rules( + content_after_insert, replace_rules + ) + + # Save modified file + if insert_modified or replace_modified: + with open(full_path, 'w', encoding='utf-8') as file: + file.write(final_content) + + files_modified += 1 + print(f'Modified: {full_path}') + + except Exception as e: + print(f'Error processing file {full_path}: {e}') + + return files_modified + +def main(): + # Check command-line argument + if len(sys.argv) < 2: + print("Please provide the path to the configuration file.") + sys.exit(1) + + config_path = sys.argv[1] + + # Load configuration and modify files + config = load_configuration(config_path) + total_modified = modify_files(config) + + print(f'\nTotal files modified: {total_modified}') + +if __name__ == '__main__': + main() \ No newline at end of file