diff --git a/src/trackers/ANT.py b/src/trackers/ANT.py index 9e06f931f..71078ecb0 100644 --- a/src/trackers/ANT.py +++ b/src/trackers/ANT.py @@ -12,6 +12,7 @@ from pathlib import Path from src.trackers.COMMON import COMMON from src.console import console +import re class ANT(): @@ -119,14 +120,48 @@ def calculate_pieces_and_file_size(total_size, pathname_bytes, piece_size): else: anon = 1 + def extract_audio_languages(bd_summary): + audio_pattern = re.compile(r'Audio: ([\w\s]+) /') + audio_languages = audio_pattern.findall(bd_summary) + return audio_languages + + def extract_subtitle_languages(bd_summary): + subtitle_pattern = re.compile(r'Subtitle: ([\w\s]+) /') + subtitle_languages = subtitle_pattern.findall(bd_summary) + return subtitle_languages + + def insert_languages_into_mediainfo(mi_dump, audio_languages, subtitle_languages): + mi_lines = mi_dump.splitlines() + + audio_index = 0 + subtitle_index = 0 + + for i, line in enumerate(mi_lines): + if "Audio" in line: + if audio_index < len(audio_languages): + mi_lines.insert(i + 1, f"Language : {audio_languages[audio_index]}") + audio_index += 1 + + elif "Text" in line: + if subtitle_index < len(subtitle_languages): + mi_lines.insert(i + 1, f"Language : {subtitle_languages[subtitle_index]}") + subtitle_index += 1 + + return "\n".join(mi_lines) + if meta['bdinfo'] is not None: - bd_dump = open(f"{meta['base_dir']}/tmp/{meta['uuid']}/BD_SUMMARY_00.txt", 'r', encoding='utf-8').read() + bd_summary_file = f"{meta['base_dir']}/tmp/{meta['uuid']}/BD_SUMMARY_00.txt" + bd_dump = open(bd_summary_file, 'r', encoding='utf-8').read() + audio_languages = extract_audio_languages(bd_dump) + subtitle_languages = extract_subtitle_languages(bd_dump) bd_dump = f'[spoiler=BDInfo][pre]{bd_dump}[/pre][/spoiler]' path = os.path.join(meta['bdinfo']['path'], 'STREAM') file_name = meta['bdinfo']['files'][0]['file'].lower() m2ts = os.path.join(path, file_name) media_info_output = str(MediaInfo.parse(m2ts, output="text", full=False)) - mi_dump = media_info_output.replace('\r\n', '\n') + mi_dump_replace = media_info_output.replace('\r\n', '\n') + mi_dump_with_languages = insert_languages_into_mediainfo(mi_dump_replace, audio_languages, subtitle_languages) + mi_dump = mi_dump_with_languages else: mi_dump = open(f"{meta['base_dir']}/tmp/{meta['uuid']}/MEDIAINFO.txt", 'r', encoding='utf-8').read() open_torrent = open(f"{meta['base_dir']}/tmp/{meta['uuid']}/[{self.tracker}]{meta['clean_name']}.torrent", 'rb') diff --git a/src/trackers/OE.py b/src/trackers/OE.py index e536179fc..0f5ad62cf 100644 --- a/src/trackers/OE.py +++ b/src/trackers/OE.py @@ -228,7 +228,7 @@ def process_languages(tracks): if track.get('@type') == 'Audio': language = track.get('Language') if not language or language is None: - audio_lang = cli_ui.ask_string('No audio language present, you must enter one:') + audio_lang = cli_ui.ask_string('No audio language present, you must enter one [English, French, Whatever]:') if audio_lang: audio_languages.append(audio_lang) else: @@ -236,7 +236,7 @@ def process_languages(tracks): elif track.get('@type') == 'Text': language = track.get('Language') if not language or language is None: - subtitle_lang = cli_ui.ask_string('No subtitle language present, you must enter one:') + subtitle_lang = cli_ui.ask_string('No subtitle language present, you must enter one [English, French, Whatever]:') if subtitle_lang: subtitle_languages.append(subtitle_lang) else: