From 088095b006a167f94889f2611f5a9c875f620767 Mon Sep 17 00:00:00 2001 From: McCloudS <64094529+McCloudS@users.noreply.github.com> Date: Fri, 22 Mar 2024 12:56:49 -0600 Subject: [PATCH 01/26] Added ability to choose github branch on download and run --- launcher.py | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/launcher.py b/launcher.py index 256685f..27e4286 100644 --- a/launcher.py +++ b/launcher.py @@ -83,8 +83,7 @@ def main(): parser.add_argument('-u', '--update', default=False, action='store_true', help="Update Subgen (default: False)") parser.add_argument('-dnr', '--donotrun', default=False, action='store_true', help="Do not run subgen.py (default: False)") parser.add_argument('-b', '--bazarrsetup', default=False, action='store_true', help="Prompt for common Bazarr setup parameters and save them for future runs (default: False)") - - + parser.add_argument('--branch', type=str, default='main', help='Specify the branch to download from. (default: main)') args = parser.parse_args() @@ -104,18 +103,24 @@ def main(): if args.install: install_packages_from_requirements(requirements_file) - subgen_script_name = "./subgen.py" - - if not os.path.exists(subgen_script_name): - print(f"File {subgen_script_name} does not exist. Downloading from GitHub...") - download_from_github("https://raw.githubusercontent.com/McCloudS/subgen/main/subgen.py", subgen_script_name) - elif convert_to_bool(os.getenv("UPDATE", "False")) or args.update: - print(f"File exists, but UPDATE is set to True. Downloading {subgen_script_name} from GitHub...") - download_from_github("https://raw.githubusercontent.com/McCloudS/subgen/main/subgen.py", subgen_script_name) + # Get the branch name from the BRANCH environment variable or default to 'main' + branch_name = args.branch or os.getenv("BRANCH", "main") + + # Determine the script name based on the branch name + subgen_script_name = f"subgen-{branch_name}.py" if branch_name != "main" else "subgen.py" + + # Check if the script exists or if the UPDATE environment variable is set to True + if not os.path.exists(subgen_script_name) or convert_to_bool(os.getenv("UPDATE", "False")): + print(f"Downloading {subgen_script_name} from GitHub branch {branch_name}...") + download_from_github(f"https://raw.githubusercontent.com/McCloudS/subgen/{branch_name}/subgen.py", subgen_script_name) else: - print("Environment variable UPDATE is not set or set to False, skipping download.") - if not args.donotrun: - subprocess.run(['python3', '-u', 'subgen.py'], check=True) + print("File exists and UPDATE is not set to True, skipping download.") + + if not args.donotrun: + if branch_name: + subprocess.run(['python3', '-u', f'subgen-{branch_name}.py'], check=True) + else: + subprocess.run(['python3', '-u', 'subgen.py'], check=True) else: print("Not running subgen.py: -dnr or --donotrun set") From 57045b6d89955e374dc054f97088c1af14b4c191 Mon Sep 17 00:00:00 2001 From: GitHub Actions Date: Fri, 22 Mar 2024 18:56:59 +0000 Subject: [PATCH 02/26] Automated update subgen.py with version --- subgen.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subgen.py b/subgen.py index f93abdf..ac58b7c 100644 --- a/subgen.py +++ b/subgen.py @@ -1,4 +1,4 @@ -subgen_version = '2024.3.21.45' +subgen_version = '2024.3.22.46' from datetime import datetime import subprocess From bb400ceb2465861d7de5217e3b60b995d735544b Mon Sep 17 00:00:00 2001 From: McCloudS <64094529+McCloudS@users.noreply.github.com> Date: Fri, 22 Mar 2024 14:30:39 -0600 Subject: [PATCH 03/26] Update launcher.py --- launcher.py | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/launcher.py b/launcher.py index 27e4286..a0dae3d 100644 --- a/launcher.py +++ b/launcher.py @@ -1,5 +1,6 @@ import os -import requests +import sys +import urllib.request import subprocess import argparse @@ -9,19 +10,24 @@ def convert_to_bool(in_bool): def install_packages_from_requirements(requirements_file): try: + download_from_github(f"https://raw.githubusercontent.com/McCloudS/subgen/main/requirements.txt", "requirements.txt") subprocess.run(['pip3', 'install', '-r', requirements_file, '--upgrade'], check=True) print(f"Requirements from {requirements_file} have been successfully installed.") except subprocess.CalledProcessError as e: print(f"Failed to install requirements: {e}") def download_from_github(url, output_file): - response = requests.get(url) - if response.status_code == 200: - with open(output_file, 'wb') as f: - f.write(response.content) + try: + with urllib.request.urlopen(url) as response, open(output_file, 'wb') as out_file: + data = response.read() # a `bytes` object + out_file.write(data) print(f"File downloaded successfully to {output_file}") - else: - print(f"Failed to download file from {url}") + except urllib.error.HTTPError as e: + print(f"Failed to download file from {url}. HTTP Error Code: {e.code}") + except urllib.error.URLError as e: + print(f"URL Error: {e.reason}") + except Exception as e: + print(f"An error occurred: {e}") def prompt_and_save_bazarr_env_variables(): """ @@ -72,6 +78,18 @@ def load_env_variables(env_filename='subgen.env'): print(f"{env_filename} file not found. Please run prompt_and_save_env_variables() first.") def main(): + # Check if the script is run with 'python' or 'python3' + if 'python3' in sys.executable: + python_cmd = 'python3' + elif 'python' in sys.executable: + python_cmd = 'python' + else: + print("Script started with an unknown command") + sys.exit(1) + if sys.version_info[0] < 3: + print(f"This script requires Python 3 or higher, you are running {sys.version}") + sys.exit(1) # Terminate the script + #Make sure we're saving subgen.py and subgen.env in the right folder os.chdir(os.path.dirname(os.path.abspath(__file__))) @@ -118,9 +136,9 @@ def main(): if not args.donotrun: if branch_name: - subprocess.run(['python3', '-u', f'subgen-{branch_name}.py'], check=True) + subprocess.run([f'{python_cmd}', '-u', f'subgen-{branch_name}.py'], check=True) else: - subprocess.run(['python3', '-u', 'subgen.py'], check=True) + subprocess.run([f'{python_cmd}', '-u', 'subgen.py'], check=True) else: print("Not running subgen.py: -dnr or --donotrun set") From fbde375b9cd2d7e100c5a3f6706492d6e2caefdc Mon Sep 17 00:00:00 2001 From: GitHub Actions Date: Fri, 22 Mar 2024 20:30:52 +0000 Subject: [PATCH 04/26] Automated update subgen.py with version --- subgen.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subgen.py b/subgen.py index ac58b7c..6fb87d4 100644 --- a/subgen.py +++ b/subgen.py @@ -1,4 +1,4 @@ -subgen_version = '2024.3.22.46' +subgen_version = '2024.3.22.47' from datetime import datetime import subprocess From 24f5fc5262cddfe6b06833adb741270ec4aff577 Mon Sep 17 00:00:00 2001 From: McCloudS <64094529+McCloudS@users.noreply.github.com> Date: Fri, 22 Mar 2024 15:58:26 -0600 Subject: [PATCH 05/26] Added support for LRC files --- subgen.py | 129 ++++++++---------------------------------------------- 1 file changed, 19 insertions(+), 110 deletions(-) diff --git a/subgen.py b/subgen.py index 6fb87d4..405d708 100644 --- a/subgen.py +++ b/subgen.py @@ -1,4 +1,4 @@ -subgen_version = '2024.3.22.47' +subgen_version = '2024.3.21.43' from datetime import datetime import subprocess @@ -57,8 +57,6 @@ clear_vram_on_complete = convert_to_bool(os.getenv('CLEAR_VRAM_ON_COMPLETE', Tru compute_type = os.getenv('COMPUTE_TYPE', 'auto') append = convert_to_bool(os.getenv('APPEND', False)) reload_script_on_change = convert_to_bool(os.getenv('RELOAD_SCRIPT_ON_CHANGE', False)) -model_prompt = os.getenv('USE_MODEL_PROMPT', 'False') -custom_model_prompt = os.getenv('CUSTOM_MODEL_PROMPT', '') if transcribe_device == "gpu": transcribe_device = "cuda" @@ -334,9 +332,7 @@ def asr( start_model() files_to_transcribe.insert(0, f"Bazarr-asr-{random_name}") audio_data = np.frombuffer(audio_file.file.read(), np.int16).flatten().astype(np.float32) / 32768.0 - if(model_prompt): - custom_model_prompt = greetings_translations.get(language, '') or custom_model_prompt - result = model.transcribe_stable(audio_data, task=task, input_sr=16000, language=language, progress_callback=progress, initial_prompt=custom_model_prompt) + result = model.transcribe_stable(audio_data, task=task, input_sr=16000, language=language, progress_callback=progress) appendLine(result) elapsed_time = time.time() - start_time minutes, seconds = divmod(int(elapsed_time), 60) @@ -394,6 +390,17 @@ def delete_model(): model = None gc.collect() +def isAudioFileExtension(file_extension): + return file_extension.casefold() in \ + [ '.mp3', '.flac', '.wav', '.alac', '.ape', '.ogg', '.wma', '.m4a', '.m4b', '.aac', '.aiff' ] + +def write_lrc(result, file_path): + with open(file_path, "w") as file: + for segment in result.segments: + minutes, seconds = divmod(int(segment.start), 60) + fraction = int((segment.start - int(segment.start)) * 100) + file.write(f"[{minutes:02d}:{seconds:02d}.{fraction:02d}] {segment.text}\n") + def gen_subtitles(file_path: str, transcribe_or_translate: str, front=True, forceLanguage=None) -> None: """Generates subtitles for a video file. @@ -436,9 +443,13 @@ def gen_subtitles(file_path: str, transcribe_or_translate: str, front=True, forc if force_detected_language_to: forceLanguage = force_detected_language_to logging.info(f"Forcing language to {forceLanguage}") - result = model.transcribe_stable(file_path, language=forceLanguage, task=transcribe_or_translate, progress_callback=progress, initial_prompt=custom_model_prompt) + result = model.transcribe_stable(file_path, language=forceLanguage, task=transcribe_or_translate, progress_callback=progress) appendLine(result) - result.to_srt_vtt(get_file_name_without_extension(file_path) + subextension, word_level=word_level_highlight) + file_name, file_extension = os.path.splitext(file_path) + if isAudioFileExtension(file_extension): + write_lrc(result, file_name + '.lrc') + else: + result.to_srt_vtt(file_name + subextension, word_level=word_level_highlight) elapsed_time = time.time() - start_time minutes, seconds = divmod(int(elapsed_time), 60) logging.info(f"Transcription of {os.path.basename(file_path)} is completed, it took {minutes} minutes and {seconds} seconds to complete.") @@ -754,108 +765,6 @@ whisper_languages = { "su": "sundanese", } -greetings_translations = { - "en": "Hello, welcome to my lecture.", - "zh": "你好,欢迎来到我的讲座。", - "de": "Hallo, willkommen zu meiner Vorlesung.", - "es": "Hola, bienvenido a mi conferencia.", - "ru": "Привет, добро пожаловать на мою лекцию.", - "ko": "안녕하세요, 제 강의에 오신 것을 환영합니다.", - "fr": "Bonjour, bienvenue à mon cours.", - "ja": "こんにちは、私の講義へようこそ。", - "pt": "Olá, bem-vindo à minha palestra.", - "tr": "Merhaba, dersime hoş geldiniz.", - "pl": "Cześć, witaj na mojej wykładzie.", - "ca": "Hola, benvingut a la meva conferència.", - "nl": "Hallo, welkom bij mijn lezing.", - "ar": "مرحبًا، مرحبًا بك في محاضرتي.", - "sv": "Hej, välkommen till min föreläsning.", - "it": "Ciao, benvenuto alla mia conferenza.", - "id": "Halo, selamat datang di kuliah saya.", - "hi": "नमस्ते, मेरे व्याख्यान में आपका स्वागत है।", - "fi": "Hei, tervetuloa luentooni.", - "vi": "Xin chào, chào mừng bạn đến với bài giảng của tôi.", - "he": "שלום, ברוך הבא להרצאתי.", - "uk": "Привіт, ласкаво просимо на мою лекцію.", - "el": "Γεια σας, καλώς ήλθατε στη διάλεξή μου.", - "ms": "Halo, selamat datang ke kuliah saya.", - "cs": "Ahoj, vítejte na mé přednášce.", - "ro": "Bună, bun venit la cursul meu.", - "da": "Hej, velkommen til min forelæsning.", - "hu": "Helló, üdvözöllek az előadásomon.", - "ta": "வணக்கம், என் பாடத்திற்கு வரவேற்கிறேன்.", - "no": "Hei, velkommen til foredraget mitt.", - "th": "สวัสดีครับ ยินดีต้อนรับสู่การบรรยายของฉัน", - "ur": "ہیلو، میری لیکچر میں خوش آمدید۔", - "hr": "Pozdrav, dobrodošli na moje predavanje.", - "bg": "Здравейте, добре дошли на моята лекция.", - "lt": "Sveiki, sveiki atvykę į mano paskaitą.", - "la": "Salve, gratias vobis pro eo quod meam lectionem excipitis.", - "mi": "Kia ora, nau mai ki aku rorohiko.", - "ml": "ഹലോ, എന്റെ പാഠത്തിലേക്ക് സ്വാഗതം.", - "cy": "Helo, croeso i fy narlith.", - "sk": "Ahoj, vitajte na mojej prednáške.", - "te": "హలో, నా పాఠానికి స్వాగతం.", - "fa": "سلام، خوش آمدید به سخنرانی من.", - "lv": "Sveiki, laipni lūdzam uz manu lekciju.", - "bn": "হ্যালো, আমার লেকচারে আপনাকে স্বাগতম।", - "sr": "Здраво, добродошли на моје предавање.", - "az": "Salam, mənim dərsimə xoş gəlmisiniz.", - "sl": "Pozdravljeni, dobrodošli na moje predavanje.", - "kn": "ಹಲೋ, ನನ್ನ ಭಾಷಣಕ್ಕೆ ಸುಸ್ವಾಗತ.", - "et": "Tere, tere tulemast minu loengusse.", - "mk": "Здраво, добредојдовте на мојата предавање.", - "br": "Demat, kroget e oa d'an daol-labour.", - "eu": "Kaixo, ongi etorri nire hitzaldi.", - "is": "Halló, velkomin á fyrirlestur minn.", - "hy": "Բարեւ, ողջույն եկավ իմ դասընթացի.", - "ne": "नमस्ते, मेरो प्रवचनमा स्वागत छ।", - "mn": "Сайн байна уу, миний хичээлд тавтай морилно уу.", - "bs": "Zdravo, dobrodošli na moje predavanje.", - "kk": "Сәлеметсіз бе, оқу сабағыма қош келдіңіз.", - "sq": "Përshëndetje, mirësevini në ligjëratën time.", - "sw": "Habari, karibu kwenye hotuba yangu.", - "gl": "Ola, benvido á miña conferencia.", - "mr": "नमस्कार, माझ्या व्याख्यानात आपले स्वागत आहे.", - "pa": "ਸਤ ਸ੍ਰੀ ਅਕਾਲ, ਮੇਰੀ ਵਾਰਤਾ ਵਿੱਚ ਤੁਹਾਨੂੰ ਜੀ ਆਇਆ ਨੂੰ ਸੁਆਗਤ ਹੈ।", - "si": "හෙලෝ, මගේ වාර්තාවට ඔබේ ස්වාදයට සාමාජිකත්වයක්.", - "km": "សួស្តី, សូមស្វាគមន៍មកកាន់អារម្មណ៍របស់ខ្ញុំ។", - "sn": "Mhoro, wakaribisha kumusoro wangu.", - "yo": "Bawo, ku isoro si wa orin mi.", - "so": "Soo dhawoow, soo dhawoow marka laga hadlo kulambanayaashaaga.", - "af": "Hallo, welkom by my lesing.", - "oc": "Bonjorn, benvenguda a ma conferéncia.", - "ka": "გამარჯობა, მესწარმეტყველება ჩემი ლექციაზე.", - "be": "Прывітанне, запрашаем на маю лекцыю.", - "tg": "Салом, ба лаҳзаи мавзӯъати ман хуш омадед.", - "sd": "هيلو، ميري ليڪڪي ۾ خوش آيو.", - "gu": "નમસ્તે, મારી પાઠશાળામાં આપનું સ્વાગત છે.", - "am": "ሰላም፣ ለአንድነት የተመረጠን ትምህርት በመሆን እናመሰግናለን።", - "yi": "העלאָ, ווילקומן צו מיין לעקטשער.", - "lo": "ສະບາຍດີ, ຍິນດີນາງຂອງຂ້ອຍໄດ້ຍິນດີ.", - "uz": "Salom, darsimda xush kelibsiz.", - "fo": "Halló, vælkomin til mína fyrilestrar.", - "ht": "Bonjou, byenveni nan leson mwen.", - "ps": "سلام، مې لومړۍ کې خوش آمدید.", - "tk": "Salam, dersimiňe hoş geldiňiz.", - "nn": "Hei, velkomen til førelesinga mi.", - "mt": "Hello, merħba għall-lezzjoni tiegħi.", - "sa": "नमस्ते, मम उपन्यासे स्वागतं.", - "lb": "Hallo, wëllkomm zu menger Lektioun.", - "my": "မင်္ဂလာပါ၊ ကျေးဇူးတင်သည့်ကိစ္စသည်။", - "bo": "བཀྲ་ཤིས་བདེ་ལེགས་འབད་བཅོས། ངའི་འཛིན་གྱི་སློབ་མའི་མིང་གི་འཕྲོད།", - "tl": "Kamusta, maligayang pagdating sa aking leksyon.", - "mg": "Manao ahoana, tonga soa sy tonga soa eto amin'ny lesona.", - "as": "নমস্কাৰ, মোৰ পাঠলৈ আপোনাক স্বাগতম।", - "tt": "Сәлам, лекциямга рәхмәт киләсез.", - "haw": "Aloha, welina me ke kipa ana i ko'u ha'i 'ōlelo.", - "ln": "Mbote, tango na zongisa mwa kilela yandi.", - "ha": "Sannu, ka ci gaba da tattalin arziki na.", - "ba": "Сәләм, лекцияғыма ҡуш тиңләгәнһүҙ.", - "jw": "Halo, sugeng datang marang kulawargané.", - "su": "Wilujeng, hatur nuhun ka lékturing abdi.", -} - if __name__ == "__main__": import uvicorn logging.info(f"Subgen v{subgen_version}") From 6c724f88730ab1107f0e0ccb1195fed9c40c4e8e Mon Sep 17 00:00:00 2001 From: GitHub Actions Date: Fri, 22 Mar 2024 21:58:39 +0000 Subject: [PATCH 06/26] Automated update subgen.py with version --- subgen.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subgen.py b/subgen.py index 405d708..362d0cb 100644 --- a/subgen.py +++ b/subgen.py @@ -1,4 +1,4 @@ -subgen_version = '2024.3.21.43' +subgen_version = '2024.3.22.48' from datetime import datetime import subprocess From 98c91aace0e74beddb70a15f641aeaaf3318d040 Mon Sep 17 00:00:00 2001 From: McCloudS <64094529+McCloudS@users.noreply.github.com> Date: Fri, 22 Mar 2024 16:04:59 -0600 Subject: [PATCH 07/26] Added LRC env variable and other nonsense from me. --- subgen.py | 115 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 111 insertions(+), 4 deletions(-) diff --git a/subgen.py b/subgen.py index 362d0cb..b79244d 100644 --- a/subgen.py +++ b/subgen.py @@ -1,4 +1,4 @@ -subgen_version = '2024.3.22.48' +subgen_version = '2024.3.21.44' from datetime import datetime import subprocess @@ -57,6 +57,9 @@ clear_vram_on_complete = convert_to_bool(os.getenv('CLEAR_VRAM_ON_COMPLETE', Tru compute_type = os.getenv('COMPUTE_TYPE', 'auto') append = convert_to_bool(os.getenv('APPEND', False)) reload_script_on_change = convert_to_bool(os.getenv('RELOAD_SCRIPT_ON_CHANGE', False)) +model_prompt = os.getenv('USE_MODEL_PROMPT', 'False') +custom_model_prompt = os.getenv('CUSTOM_MODEL_PROMPT', '') +lrc_for_audio_files = convert_to_bool(os.getenv('LRC_FOR_AUDIO_FILES', True)) if transcribe_device == "gpu": transcribe_device = "cuda" @@ -332,7 +335,9 @@ def asr( start_model() files_to_transcribe.insert(0, f"Bazarr-asr-{random_name}") audio_data = np.frombuffer(audio_file.file.read(), np.int16).flatten().astype(np.float32) / 32768.0 - result = model.transcribe_stable(audio_data, task=task, input_sr=16000, language=language, progress_callback=progress) + if(model_prompt): + custom_model_prompt = greetings_translations.get(language, '') or custom_model_prompt + result = model.transcribe_stable(audio_data, task=task, input_sr=16000, language=language, progress_callback=progress, initial_prompt=custom_model_prompt) appendLine(result) elapsed_time = time.time() - start_time minutes, seconds = divmod(int(elapsed_time), 60) @@ -443,10 +448,10 @@ def gen_subtitles(file_path: str, transcribe_or_translate: str, front=True, forc if force_detected_language_to: forceLanguage = force_detected_language_to logging.info(f"Forcing language to {forceLanguage}") - result = model.transcribe_stable(file_path, language=forceLanguage, task=transcribe_or_translate, progress_callback=progress) + result = model.transcribe_stable(file_path, language=forceLanguage, task=transcribe_or_translate, progress_callback=progress, initial_prompt=custom_model_prompt) appendLine(result) file_name, file_extension = os.path.splitext(file_path) - if isAudioFileExtension(file_extension): + if isAudioFileExtension(file_extension) and lrc_for_audio_files: write_lrc(result, file_name + '.lrc') else: result.to_srt_vtt(file_name + subextension, word_level=word_level_highlight) @@ -765,6 +770,108 @@ whisper_languages = { "su": "sundanese", } +greetings_translations = { + "en": "Hello, welcome to my lecture.", + "zh": "你好,欢迎来到我的讲座。", + "de": "Hallo, willkommen zu meiner Vorlesung.", + "es": "Hola, bienvenido a mi conferencia.", + "ru": "Привет, добро пожаловать на мою лекцию.", + "ko": "안녕하세요, 제 강의에 오신 것을 환영합니다.", + "fr": "Bonjour, bienvenue à mon cours.", + "ja": "こんにちは、私の講義へようこそ。", + "pt": "Olá, bem-vindo à minha palestra.", + "tr": "Merhaba, dersime hoş geldiniz.", + "pl": "Cześć, witaj na mojej wykładzie.", + "ca": "Hola, benvingut a la meva conferència.", + "nl": "Hallo, welkom bij mijn lezing.", + "ar": "مرحبًا، مرحبًا بك في محاضرتي.", + "sv": "Hej, välkommen till min föreläsning.", + "it": "Ciao, benvenuto alla mia conferenza.", + "id": "Halo, selamat datang di kuliah saya.", + "hi": "नमस्ते, मेरे व्याख्यान में आपका स्वागत है।", + "fi": "Hei, tervetuloa luentooni.", + "vi": "Xin chào, chào mừng bạn đến với bài giảng của tôi.", + "he": "שלום, ברוך הבא להרצאתי.", + "uk": "Привіт, ласкаво просимо на мою лекцію.", + "el": "Γεια σας, καλώς ήλθατε στη διάλεξή μου.", + "ms": "Halo, selamat datang ke kuliah saya.", + "cs": "Ahoj, vítejte na mé přednášce.", + "ro": "Bună, bun venit la cursul meu.", + "da": "Hej, velkommen til min forelæsning.", + "hu": "Helló, üdvözöllek az előadásomon.", + "ta": "வணக்கம், என் பாடத்திற்கு வரவேற்கிறேன்.", + "no": "Hei, velkommen til foredraget mitt.", + "th": "สวัสดีครับ ยินดีต้อนรับสู่การบรรยายของฉัน", + "ur": "ہیلو، میری لیکچر میں خوش آمدید۔", + "hr": "Pozdrav, dobrodošli na moje predavanje.", + "bg": "Здравейте, добре дошли на моята лекция.", + "lt": "Sveiki, sveiki atvykę į mano paskaitą.", + "la": "Salve, gratias vobis pro eo quod meam lectionem excipitis.", + "mi": "Kia ora, nau mai ki aku rorohiko.", + "ml": "ഹലോ, എന്റെ പാഠത്തിലേക്ക് സ്വാഗതം.", + "cy": "Helo, croeso i fy narlith.", + "sk": "Ahoj, vitajte na mojej prednáške.", + "te": "హలో, నా పాఠానికి స్వాగతం.", + "fa": "سلام، خوش آمدید به سخنرانی من.", + "lv": "Sveiki, laipni lūdzam uz manu lekciju.", + "bn": "হ্যালো, আমার লেকচারে আপনাকে স্বাগতম।", + "sr": "Здраво, добродошли на моје предавање.", + "az": "Salam, mənim dərsimə xoş gəlmisiniz.", + "sl": "Pozdravljeni, dobrodošli na moje predavanje.", + "kn": "ಹಲೋ, ನನ್ನ ಭಾಷಣಕ್ಕೆ ಸುಸ್ವಾಗತ.", + "et": "Tere, tere tulemast minu loengusse.", + "mk": "Здраво, добредојдовте на мојата предавање.", + "br": "Demat, kroget e oa d'an daol-labour.", + "eu": "Kaixo, ongi etorri nire hitzaldi.", + "is": "Halló, velkomin á fyrirlestur minn.", + "hy": "Բարեւ, ողջույն եկավ իմ դասընթացի.", + "ne": "नमस्ते, मेरो प्रवचनमा स्वागत छ।", + "mn": "Сайн байна уу, миний хичээлд тавтай морилно уу.", + "bs": "Zdravo, dobrodošli na moje predavanje.", + "kk": "Сәлеметсіз бе, оқу сабағыма қош келдіңіз.", + "sq": "Përshëndetje, mirësevini në ligjëratën time.", + "sw": "Habari, karibu kwenye hotuba yangu.", + "gl": "Ola, benvido á miña conferencia.", + "mr": "नमस्कार, माझ्या व्याख्यानात आपले स्वागत आहे.", + "pa": "ਸਤ ਸ੍ਰੀ ਅਕਾਲ, ਮੇਰੀ ਵਾਰਤਾ ਵਿੱਚ ਤੁਹਾਨੂੰ ਜੀ ਆਇਆ ਨੂੰ ਸੁਆਗਤ ਹੈ।", + "si": "හෙලෝ, මගේ වාර්තාවට ඔබේ ස්වාදයට සාමාජිකත්වයක්.", + "km": "សួស្តី, សូមស្វាគមន៍មកកាន់អារម្មណ៍របស់ខ្ញុំ។", + "sn": "Mhoro, wakaribisha kumusoro wangu.", + "yo": "Bawo, ku isoro si wa orin mi.", + "so": "Soo dhawoow, soo dhawoow marka laga hadlo kulambanayaashaaga.", + "af": "Hallo, welkom by my lesing.", + "oc": "Bonjorn, benvenguda a ma conferéncia.", + "ka": "გამარჯობა, მესწარმეტყველება ჩემი ლექციაზე.", + "be": "Прывітанне, запрашаем на маю лекцыю.", + "tg": "Салом, ба лаҳзаи мавзӯъати ман хуш омадед.", + "sd": "هيلو، ميري ليڪڪي ۾ خوش آيو.", + "gu": "નમસ્તે, મારી પાઠશાળામાં આપનું સ્વાગત છે.", + "am": "ሰላም፣ ለአንድነት የተመረጠን ትምህርት በመሆን እናመሰግናለን።", + "yi": "העלאָ, ווילקומן צו מיין לעקטשער.", + "lo": "ສະບາຍດີ, ຍິນດີນາງຂອງຂ້ອຍໄດ້ຍິນດີ.", + "uz": "Salom, darsimda xush kelibsiz.", + "fo": "Halló, vælkomin til mína fyrilestrar.", + "ht": "Bonjou, byenveni nan leson mwen.", + "ps": "سلام، مې لومړۍ کې خوش آمدید.", + "tk": "Salam, dersimiňe hoş geldiňiz.", + "nn": "Hei, velkomen til førelesinga mi.", + "mt": "Hello, merħba għall-lezzjoni tiegħi.", + "sa": "नमस्ते, मम उपन्यासे स्वागतं.", + "lb": "Hallo, wëllkomm zu menger Lektioun.", + "my": "မင်္ဂလာပါ၊ ကျေးဇူးတင်သည့်ကိစ္စသည်။", + "bo": "བཀྲ་ཤིས་བདེ་ལེགས་འབད་བཅོས། ངའི་འཛིན་གྱི་སློབ་མའི་མིང་གི་འཕྲོད།", + "tl": "Kamusta, maligayang pagdating sa aking leksyon.", + "mg": "Manao ahoana, tonga soa sy tonga soa eto amin'ny lesona.", + "as": "নমস্কাৰ, মোৰ পাঠলৈ আপোনাক স্বাগতম।", + "tt": "Сәлам, лекциямга рәхмәт киләсез.", + "haw": "Aloha, welina me ke kipa ana i ko'u ha'i 'ōlelo.", + "ln": "Mbote, tango na zongisa mwa kilela yandi.", + "ha": "Sannu, ka ci gaba da tattalin arziki na.", + "ba": "Сәләм, лекцияғыма ҡуш тиңләгәнһүҙ.", + "jw": "Halo, sugeng datang marang kulawargané.", + "su": "Wilujeng, hatur nuhun ka lékturing abdi.", +} + if __name__ == "__main__": import uvicorn logging.info(f"Subgen v{subgen_version}") From 97d13cb7c66509922070ea891a028a8cfad2d109 Mon Sep 17 00:00:00 2001 From: GitHub Actions Date: Fri, 22 Mar 2024 22:05:11 +0000 Subject: [PATCH 08/26] Automated update subgen.py with version --- subgen.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subgen.py b/subgen.py index b79244d..dc28066 100644 --- a/subgen.py +++ b/subgen.py @@ -1,4 +1,4 @@ -subgen_version = '2024.3.21.44' +subgen_version = '2024.3.22.49' from datetime import datetime import subprocess From 46fa8b30b92966950dd10026db2a25fe621ec1f7 Mon Sep 17 00:00:00 2001 From: McCloudS <64094529+McCloudS@users.noreply.github.com> Date: Fri, 22 Mar 2024 16:06:33 -0600 Subject: [PATCH 09/26] Added LRC instructions --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 010f240..98700fa 100644 --- a/README.md +++ b/README.md @@ -175,6 +175,7 @@ The following environment variables are available in Docker. They will default | MONITOR | False | Will monitor `TRANSCRIBE_FOLDERS` for real-time changes to see if we need to generate subtitles | | USE_MODEL_PROMPT | False | When set to `True`, will use the default prompt stored in greetings_translations "Hello, welcome to my lecture." to try and force the use of punctuation in transcriptions that don't. | | CUSTOM_MODEL_PROMPT | '' | If `USE_MODEL_PROMPT` is `True`, you can override the default prompt (See: https://medium.com/axinc-ai/prompt-engineering-in-whisper-6bb18003562d for great examples). | +| LRC_FOR_AUDIO_FILES' | True | Will generate LRC (instead of SRT) files for filetypes: '.mp3', '.flac', '.wav', '.alac', '.ape', '.ogg', '.wma', '.m4a', '.m4b', '.aac', '.aiff' | ### Images: `mccloud/subgen:latest` is GPU or CPU
From b80a17a3f0404a862bd935c65801e2f054e538f8 Mon Sep 17 00:00:00 2001 From: McCloudS <64094529+McCloudS@users.noreply.github.com> Date: Fri, 22 Mar 2024 16:09:15 -0600 Subject: [PATCH 10/26] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 98700fa..814bb17 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,8 @@
Updates: +22 Mar 2024: Added LRC capability via see: `'LRC_FOR_AUDIO_FILES' | True | Will generate LRC (instead of SRT) files for filetypes: '.mp3', '.flac', '.wav', '.alac', '.ape', '.ogg', '.wma', '.m4a', '.m4b', '.aac', '.aiff' |` + 21 Mar 2024: Added a 'wizard' into the launcher that will help standalone users get common Bazarr variables configured. See below in Launcher section. Removed 'Transformers' as an option. While I usually don't like to remove features, I don't think anyone is using this and the results are wildly unpredictable and often cause out of memory errors. Added two new environment variables called `USE_MODEL_PROMPT` and `CUSTOM_MODEL_PROMPT`. If `USE_MODEL_PROMPT` is `True` it will use `CUSTOM_MODEL_PROMPT` if set, otherwise will default to using the pre-configured language pairings, such as: `"en": "Hello, welcome to my lecture.", "zh": "你好,欢迎来到我的讲座。"` These pre-configurated translations are geared towards fixing some audio that may not have punctionation. We can prompt it to try to force the use of punctuation during transcription. From fa62d5a770bf191ea5092384b8b383fb5a83bc1c Mon Sep 17 00:00:00 2001 From: McCloudS <64094529+McCloudS@users.noreply.github.com> Date: Fri, 22 Mar 2024 16:10:18 -0600 Subject: [PATCH 11/26] Update launcher.py to try pip and pip3 for install --- launcher.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/launcher.py b/launcher.py index a0dae3d..fc5ee59 100644 --- a/launcher.py +++ b/launcher.py @@ -10,11 +10,16 @@ def convert_to_bool(in_bool): def install_packages_from_requirements(requirements_file): try: - download_from_github(f"https://raw.githubusercontent.com/McCloudS/subgen/main/requirements.txt", "requirements.txt") + # Try installing with pip3 subprocess.run(['pip3', 'install', '-r', requirements_file, '--upgrade'], check=True) - print(f"Requirements from {requirements_file} have been successfully installed.") - except subprocess.CalledProcessError as e: - print(f"Failed to install requirements: {e}") + print("Packages installed successfully using pip3.") + except subprocess.CalledProcessError: + try: + # If pip3 fails, try installing with pip + subprocess.run(['pip', 'install', '-r', requirements_file, '--upgrade'], check=True) + print("Packages installed successfully using pip.") + except subprocess.CalledProcessError: + print("Failed to install packages using both pip3 and pip.") def download_from_github(url, output_file): try: From 7b951d2a2ee0df2565885facd99202dc6d3a5806 Mon Sep 17 00:00:00 2001 From: GitHub Actions Date: Fri, 22 Mar 2024 22:10:29 +0000 Subject: [PATCH 12/26] Automated update subgen.py with version --- subgen.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subgen.py b/subgen.py index dc28066..5891d08 100644 --- a/subgen.py +++ b/subgen.py @@ -1,4 +1,4 @@ -subgen_version = '2024.3.22.49' +subgen_version = '2024.3.22.50' from datetime import datetime import subprocess From 19d31f2560a7d58a9034968f57a577a8965c42a0 Mon Sep 17 00:00:00 2001 From: McCloudS <64094529+McCloudS@users.noreply.github.com> Date: Fri, 22 Mar 2024 16:35:48 -0600 Subject: [PATCH 13/26] Fixed spacing for a special someone --- launcher.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/launcher.py b/launcher.py index fc5ee59..81221b0 100644 --- a/launcher.py +++ b/launcher.py @@ -100,7 +100,7 @@ def main(): # Construct the argument parser parser = argparse.ArgumentParser() - parser.add_argument( '-d', '--debug', default=False, action='store_true', help="Enable console debugging (default: False)") + parser.add_argument('-d', '--debug', default=False, action='store_true', help="Enable console debugging (default: False)") parser.add_argument('-i', '--install', default=False, action='store_true', help="Install/update all necessary packages (default: False)") parser.add_argument('-a', '--append', default=False, action='store_true', help="Append 'Transcribed by whisper' to generated subtitle (default: False)") parser.add_argument('-u', '--update', default=False, action='store_true', help="Update Subgen (default: False)") From 0fa03ed57165356975bfca53e33af7a5778161b2 Mon Sep 17 00:00:00 2001 From: GitHub Actions Date: Fri, 22 Mar 2024 22:35:59 +0000 Subject: [PATCH 14/26] Automated update subgen.py with version --- subgen.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subgen.py b/subgen.py index 5891d08..c54b508 100644 --- a/subgen.py +++ b/subgen.py @@ -1,4 +1,4 @@ -subgen_version = '2024.3.22.50' +subgen_version = '2024.3.22.51' from datetime import datetime import subprocess From b95a2ddce63e6de895b272beeee8e0bda1756ad5 Mon Sep 17 00:00:00 2001 From: McCloudS <64094529+McCloudS@users.noreply.github.com> Date: Fri, 22 Mar 2024 17:09:13 -0600 Subject: [PATCH 15/26] Simplified args --- launcher.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/launcher.py b/launcher.py index 81221b0..cfe51d9 100644 --- a/launcher.py +++ b/launcher.py @@ -104,17 +104,17 @@ def main(): parser.add_argument('-i', '--install', default=False, action='store_true', help="Install/update all necessary packages (default: False)") parser.add_argument('-a', '--append', default=False, action='store_true', help="Append 'Transcribed by whisper' to generated subtitle (default: False)") parser.add_argument('-u', '--update', default=False, action='store_true', help="Update Subgen (default: False)") - parser.add_argument('-dnr', '--donotrun', default=False, action='store_true', help="Do not run subgen.py (default: False)") - parser.add_argument('-b', '--bazarrsetup', default=False, action='store_true', help="Prompt for common Bazarr setup parameters and save them for future runs (default: False)") - parser.add_argument('--branch', type=str, default='main', help='Specify the branch to download from. (default: main)') - + parser.add_argument('-x', '--exitearly', default=False, action='store_true', help="Exit without running subgen.py (default: False)") + parser.add_argument('-s', '--setupbazarr', default=False, action='store_true', help="Prompt for common Bazarr setup parameters and save them for future runs (default: False)") + parser.add_argument('-b', '--branch', type=str, default='main', help='Specify the branch to download from. (default: main)') + args = parser.parse_args() # Set environment variables based on the parsed arguments os.environ['DEBUG'] = str(args.debug) os.environ['APPEND'] = str(args.append) - if args.bazarrsetup: + if args.setupbazarr: prompt_and_save_bazarr_env_variables() load_env_variables() @@ -124,6 +124,7 @@ def main(): # Install packages from requirements.txt if the install or packageupdate argument is True if args.install: + download_from_github(requirements_url, requirements_file) install_packages_from_requirements(requirements_file) # Get the branch name from the BRANCH environment variable or default to 'main' @@ -145,7 +146,7 @@ def main(): else: subprocess.run([f'{python_cmd}', '-u', 'subgen.py'], check=True) else: - print("Not running subgen.py: -dnr or --donotrun set") + print("Not running subgen.py: -x or --exitearly set") if __name__ == "__main__": main() From 2b0bc803316f904da2a32882314d5ebf798fa8e8 Mon Sep 17 00:00:00 2001 From: GitHub Actions Date: Fri, 22 Mar 2024 23:09:26 +0000 Subject: [PATCH 16/26] Automated update subgen.py with version --- subgen.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subgen.py b/subgen.py index c54b508..2220444 100644 --- a/subgen.py +++ b/subgen.py @@ -1,4 +1,4 @@ -subgen_version = '2024.3.22.51' +subgen_version = '2024.3.22.52' from datetime import datetime import subprocess From 3165f08138d985a1ab4a02c5c75f0ca140243f0b Mon Sep 17 00:00:00 2001 From: McCloudS <64094529+McCloudS@users.noreply.github.com> Date: Fri, 22 Mar 2024 17:09:53 -0600 Subject: [PATCH 17/26] Update launcher.py --- launcher.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/launcher.py b/launcher.py index cfe51d9..1166bd7 100644 --- a/launcher.py +++ b/launcher.py @@ -140,7 +140,7 @@ def main(): else: print("File exists and UPDATE is not set to True, skipping download.") - if not args.donotrun: + if not args.exitearly: if branch_name: subprocess.run([f'{python_cmd}', '-u', f'subgen-{branch_name}.py'], check=True) else: From d4a3b6edcd94e624a73beb7cc9ed7b2dde8394d2 Mon Sep 17 00:00:00 2001 From: GitHub Actions Date: Fri, 22 Mar 2024 23:10:05 +0000 Subject: [PATCH 18/26] Automated update subgen.py with version --- subgen.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subgen.py b/subgen.py index 2220444..d1b848a 100644 --- a/subgen.py +++ b/subgen.py @@ -1,4 +1,4 @@ -subgen_version = '2024.3.22.52' +subgen_version = '2024.3.22.53' from datetime import datetime import subprocess From 8dcb6b20f6d107c77957b28a39697e7d88c68993 Mon Sep 17 00:00:00 2001 From: McCloudS <64094529+McCloudS@users.noreply.github.com> Date: Fri, 22 Mar 2024 18:15:03 -0600 Subject: [PATCH 19/26] Added ability to update launcher --- launcher.py | 44 +++++++++++++++++++++++++++++++------------- 1 file changed, 31 insertions(+), 13 deletions(-) diff --git a/launcher.py b/launcher.py index 1166bd7..2b62a3c 100644 --- a/launcher.py +++ b/launcher.py @@ -104,17 +104,41 @@ def main(): parser.add_argument('-i', '--install', default=False, action='store_true', help="Install/update all necessary packages (default: False)") parser.add_argument('-a', '--append', default=False, action='store_true', help="Append 'Transcribed by whisper' to generated subtitle (default: False)") parser.add_argument('-u', '--update', default=False, action='store_true', help="Update Subgen (default: False)") - parser.add_argument('-x', '--exitearly', default=False, action='store_true', help="Exit without running subgen.py (default: False)") - parser.add_argument('-s', '--setupbazarr', default=False, action='store_true', help="Prompt for common Bazarr setup parameters and save them for future runs (default: False)") + parser.add_argument('-x', '--exit-early', default=False, action='store_true', help="Exit without running subgen.py (default: False)") + parser.add_argument('-s', '--setup-bazarr', default=False, action='store_true', help="Prompt for common Bazarr setup parameters and save them for future runs (default: False)") parser.add_argument('-b', '--branch', type=str, default='main', help='Specify the branch to download from. (default: main)') + parser.add_argument('-l', '--launcher-update', default=False, action='store_true', help="Update launcher.py and re-launch (default: False)") args = parser.parse_args() + # Get the branch name from the BRANCH environment variable or default to 'main' + branch_name = args.branch or os.getenv("BRANCH", "main") + + # Determine the script name based on the branch name + script_name = f"-{branch_name}.py" if branch_name != "main" else ".py" + + # Check if the script exists or if the UPDATE environment variable is set to True + if not os.path.exists(script_name) or convert_to_bool(os.getenv("UPDATE", "False")): + print(f"Downloading launcher.py from GitHub branch {branch_name}...") + download_from_github(f"https://raw.githubusercontent.com/McCloudS/subgen/{branch_name}/launcher.py", f'launcher{script_name}') + else: + print("File exists and UPDATE is not set to True, skipping download.") + + # Prepare the arguments to exclude update triggers + excluded_args = ['--launcher-update', '-l'] + new_args = [arg for arg in sys.argv[1:] if arg not in excluded_args] + if branch_name == 'main' and args.launcher_update: + print("Running launcher.py for the 'main' branch.") + os.execl(sys.executable, sys.executable, "launcher.py", *new_args) + else: + print(f"Running launcher-{branch_name}.py for the '{branch_name}' branch.") + os.execl(sys.executable, sys.executable, f"launcher-{branch_name}.py", *new_args) + # Set environment variables based on the parsed arguments os.environ['DEBUG'] = str(args.debug) os.environ['APPEND'] = str(args.append) - if args.setupbazarr: + if args.setup_bazarr: prompt_and_save_bazarr_env_variables() load_env_variables() @@ -126,21 +150,15 @@ def main(): if args.install: download_from_github(requirements_url, requirements_file) install_packages_from_requirements(requirements_file) - - # Get the branch name from the BRANCH environment variable or default to 'main' - branch_name = args.branch or os.getenv("BRANCH", "main") - - # Determine the script name based on the branch name - subgen_script_name = f"subgen-{branch_name}.py" if branch_name != "main" else "subgen.py" # Check if the script exists or if the UPDATE environment variable is set to True - if not os.path.exists(subgen_script_name) or convert_to_bool(os.getenv("UPDATE", "False")): - print(f"Downloading {subgen_script_name} from GitHub branch {branch_name}...") - download_from_github(f"https://raw.githubusercontent.com/McCloudS/subgen/{branch_name}/subgen.py", subgen_script_name) + if not os.path.exists(script_name) or convert_to_bool(os.getenv("UPDATE", "False")): + print(f"Downloading subgen.py from GitHub branch {branch_name}...") + download_from_github(f"https://raw.githubusercontent.com/McCloudS/subgen/{branch_name}/subgen.py", f'subgen{script_name}') else: print("File exists and UPDATE is not set to True, skipping download.") - if not args.exitearly: + if not args.exit_early: if branch_name: subprocess.run([f'{python_cmd}', '-u', f'subgen-{branch_name}.py'], check=True) else: From 2448224a48d67746d827182c014ca9322f353fec Mon Sep 17 00:00:00 2001 From: GitHub Actions Date: Sat, 23 Mar 2024 00:15:13 +0000 Subject: [PATCH 20/26] Automated update subgen.py with version --- subgen.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subgen.py b/subgen.py index d1b848a..4b515ae 100644 --- a/subgen.py +++ b/subgen.py @@ -1,4 +1,4 @@ -subgen_version = '2024.3.22.53' +subgen_version = '2024.3.23.54' from datetime import datetime import subprocess From 5a3bd4da20ee4653593be5b4620833fbc1661f4f Mon Sep 17 00:00:00 2001 From: McCloudS <64094529+McCloudS@users.noreply.github.com> Date: Fri, 22 Mar 2024 18:18:22 -0600 Subject: [PATCH 21/26] Update launcher.py --- launcher.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/launcher.py b/launcher.py index 2b62a3c..832c92a 100644 --- a/launcher.py +++ b/launcher.py @@ -159,7 +159,7 @@ def main(): print("File exists and UPDATE is not set to True, skipping download.") if not args.exit_early: - if branch_name: + if branch_name != 'main': subprocess.run([f'{python_cmd}', '-u', f'subgen-{branch_name}.py'], check=True) else: subprocess.run([f'{python_cmd}', '-u', 'subgen.py'], check=True) From 1f33c8411a8bb1c572ad261f601ed2b425f03139 Mon Sep 17 00:00:00 2001 From: GitHub Actions Date: Sat, 23 Mar 2024 00:18:32 +0000 Subject: [PATCH 22/26] Automated update subgen.py with version --- subgen.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subgen.py b/subgen.py index 4b515ae..ed4c9a7 100644 --- a/subgen.py +++ b/subgen.py @@ -1,4 +1,4 @@ -subgen_version = '2024.3.23.54' +subgen_version = '2024.3.23.55' from datetime import datetime import subprocess From ac9d27b853596d0146067d6d925bdb4ae8e0e3ce Mon Sep 17 00:00:00 2001 From: McCloudS <64094529+McCloudS@users.noreply.github.com> Date: Fri, 22 Mar 2024 19:04:01 -0600 Subject: [PATCH 23/26] Update launcher.py --- launcher.py | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/launcher.py b/launcher.py index 832c92a..5223ca7 100644 --- a/launcher.py +++ b/launcher.py @@ -112,17 +112,14 @@ def main(): args = parser.parse_args() # Get the branch name from the BRANCH environment variable or default to 'main' - branch_name = args.branch or os.getenv("BRANCH", "main") - + branch_name = args.branch if args.branch != 'main' else os.getenv('BRANCH', 'main') # Determine the script name based on the branch name script_name = f"-{branch_name}.py" if branch_name != "main" else ".py" - - # Check if the script exists or if the UPDATE environment variable is set to True - if not os.path.exists(script_name) or convert_to_bool(os.getenv("UPDATE", "False")): - print(f"Downloading launcher.py from GitHub branch {branch_name}...") + # Check we need to update the launcher + + if args.launcher_update or convert_to_bool(os.getenv('LAUNCHER_UPDATE')): + print(f"Updating launcher.py from GitHub branch {branch_name}...") download_from_github(f"https://raw.githubusercontent.com/McCloudS/subgen/{branch_name}/launcher.py", f'launcher{script_name}') - else: - print("File exists and UPDATE is not set to True, skipping download.") # Prepare the arguments to exclude update triggers excluded_args = ['--launcher-update', '-l'] @@ -130,9 +127,9 @@ def main(): if branch_name == 'main' and args.launcher_update: print("Running launcher.py for the 'main' branch.") os.execl(sys.executable, sys.executable, "launcher.py", *new_args) - else: + elif args.launcher_update: print(f"Running launcher-{branch_name}.py for the '{branch_name}' branch.") - os.execl(sys.executable, sys.executable, f"launcher-{branch_name}.py", *new_args) + os.execl(sys.executable, sys.executable, f"launcher{script_name}", *new_args) # Set environment variables based on the parsed arguments os.environ['DEBUG'] = str(args.debug) @@ -152,15 +149,15 @@ def main(): install_packages_from_requirements(requirements_file) # Check if the script exists or if the UPDATE environment variable is set to True - if not os.path.exists(script_name) or convert_to_bool(os.getenv("UPDATE", "False")): + if not os.path.exists(f'subgen{script_name}') or args.update or convert_to_bool(os.getenv('UPDATE')): print(f"Downloading subgen.py from GitHub branch {branch_name}...") download_from_github(f"https://raw.githubusercontent.com/McCloudS/subgen/{branch_name}/subgen.py", f'subgen{script_name}') else: - print("File exists and UPDATE is not set to True, skipping download.") + print("subgen.py exists and UPDATE is set to False, skipping download.") if not args.exit_early: if branch_name != 'main': - subprocess.run([f'{python_cmd}', '-u', f'subgen-{branch_name}.py'], check=True) + subprocess.run([f'{python_cmd}', '-u', f'subgen{script_name}'], check=True) else: subprocess.run([f'{python_cmd}', '-u', 'subgen.py'], check=True) else: From fd73bf21480c06791850ac24eb3ccbea31ac3208 Mon Sep 17 00:00:00 2001 From: GitHub Actions Date: Sat, 23 Mar 2024 01:04:11 +0000 Subject: [PATCH 24/26] Automated update subgen.py with version --- subgen.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subgen.py b/subgen.py index ed4c9a7..c0adf2a 100644 --- a/subgen.py +++ b/subgen.py @@ -1,4 +1,4 @@ -subgen_version = '2024.3.23.55' +subgen_version = '2024.3.23.56' from datetime import datetime import subprocess From cd0b043ef1c827a824de0c876bf46510a493c4d3 Mon Sep 17 00:00:00 2001 From: McCloudS <64094529+McCloudS@users.noreply.github.com> Date: Fri, 22 Mar 2024 19:07:13 -0600 Subject: [PATCH 25/26] Add which script I'm launching --- launcher.py | 1 + 1 file changed, 1 insertion(+) diff --git a/launcher.py b/launcher.py index 5223ca7..1673f6d 100644 --- a/launcher.py +++ b/launcher.py @@ -156,6 +156,7 @@ def main(): print("subgen.py exists and UPDATE is set to False, skipping download.") if not args.exit_early: + print(f'Launching subgen{script_name}') if branch_name != 'main': subprocess.run([f'{python_cmd}', '-u', f'subgen{script_name}'], check=True) else: From e2c77cf70fd448d8c2edb57563432c410b0fefdb Mon Sep 17 00:00:00 2001 From: GitHub Actions Date: Sat, 23 Mar 2024 01:07:30 +0000 Subject: [PATCH 26/26] Automated update subgen.py with version --- subgen.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subgen.py b/subgen.py index c0adf2a..ba6dcb0 100644 --- a/subgen.py +++ b/subgen.py @@ -1,4 +1,4 @@ -subgen_version = '2024.3.23.56' +subgen_version = '2024.3.23.57' from datetime import datetime import subprocess