From 415ceab7b7cc22f5d7c1dbf68bc276eca4746809 Mon Sep 17 00:00:00 2001 From: Audionut Date: Thu, 12 Sep 2024 17:04:12 +1000 Subject: [PATCH 1/3] Look for audio tracks rather than a hardcoded track number --- .github/workflows/docker-image.yml | 2 +- src/trackers/AITHER.py | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index b1b1e33bd..f3534c521 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -5,7 +5,7 @@ on: branches: - master - develop - - dvd-seasons + - aither_language env: REGISTRY: ghcr.io diff --git a/src/trackers/AITHER.py b/src/trackers/AITHER.py index 7da76fe81..11973429f 100644 --- a/src/trackers/AITHER.py +++ b/src/trackers/AITHER.py @@ -130,8 +130,14 @@ def has_english_audio(tracks, is_bdmv=False): def get_audio_lang(tracks, is_bdmv=False): if is_bdmv: return tracks[0].get('language', '').upper() if tracks else "" - return tracks[2].get('Language_String', '').upper() if len(tracks) > 2 else "" + # For regular files, find the first audio track and return the language string + for track in tracks: + if track['@type'] == "Audio": + return track.get('Language', '').upper() # Correctly retrieve the language + return "" # Return an empty string if no audio track is found + + # Handle non-BDMV cases if meta['is_disc'] != "BDMV": try: with open(f"{meta.get('base_dir')}/tmp/{meta.get('uuid')}/MediaInfo.json", 'r', encoding='utf-8') as f: @@ -139,9 +145,12 @@ def get_audio_lang(tracks, is_bdmv=False): audio_tracks = mi['media']['track'] has_eng_audio = has_english_audio(audio_tracks) + + # If English audio is not present, get the audio language if not has_eng_audio: audio_lang = get_audio_lang(audio_tracks) if audio_lang: + # Insert the audio language before the resolution in the name aither_name = aither_name.replace(meta['resolution'], f"{audio_lang} {meta['resolution']}", 1) except (FileNotFoundError, KeyError, IndexError) as e: print(f"Error processing MediaInfo: {e}") From ca5b3d773c53f59983d696cd504ff8745214087b Mon Sep 17 00:00:00 2001 From: Audionut Date: Fri, 13 Sep 2024 23:50:01 +1000 Subject: [PATCH 2/3] Use the text file with full language instead of meta with 2 digit --- src/trackers/AITHER.py | 67 ++++++++++++++++++------------------------ 1 file changed, 28 insertions(+), 39 deletions(-) diff --git a/src/trackers/AITHER.py b/src/trackers/AITHER.py index 11973429f..4382e47d8 100644 --- a/src/trackers/AITHER.py +++ b/src/trackers/AITHER.py @@ -3,8 +3,8 @@ import asyncio import requests from str2bool import str2bool -import json import platform +import re from src.trackers.COMMON import COMMON from src.console import console @@ -40,6 +40,8 @@ async def upload(self, meta): resolution_id = await self.get_res_id(meta['resolution']) modq = await self.get_flag(meta, 'modq') name = await self.edit_name(meta) + region_id = await common.unit3d_region_ids(meta.get('region')) + distributor_id = await common.unit3d_distributor_ids(meta.get('distributor')) if meta['anon'] == 0 and bool(str2bool(str(self.config['TRACKERS'][self.tracker].get('anon', "False")))) is False: anon = 0 else: @@ -89,7 +91,10 @@ async def upload(self, meta): if self.config['TRACKERS'][self.tracker].get('internal', False) is True: if meta['tag'] != "" and (meta['tag'][1:] in self.config['TRACKERS'][self.tracker].get('internal_groups', [])): data['internal'] = 1 - + if region_id != 0: + data['region_id'] = region_id + if distributor_id != 0: + data['distributor_id'] = distributor_id if meta.get('category') == "TV": data['season_number'] = meta.get('season_int', '0') data['episode_number'] = meta.get('episode_int', '0') @@ -115,57 +120,41 @@ async def get_flag(self, meta, flag_name): async def edit_name(self, meta): aither_name = meta['name'] - # Helper function to check if English audio is present - def has_english_audio(tracks, is_bdmv=False): - for track in tracks: - if is_bdmv and track.get('language') == 'English': + # Helper function to check if English audio is present in the text-based MediaInfo + def has_english_audio(media_info_text): + # Look for the audio section and extract the language line + audio_section = re.search(r'Audio[\s\S]+?Language\s+:\s+(\w+)', media_info_text) + if audio_section: + language = audio_section.group(1) + if language.lower().startswith('en'): # Check if it's English return True - if not is_bdmv and track['@type'] == "Audio": - # Ensure Language is not None and is a string before checking startswith - if isinstance(track.get('Language'), str) and track.get('Language').startswith('en'): - return True return False - # Helper function to get audio language - def get_audio_lang(tracks, is_bdmv=False): - if is_bdmv: - return tracks[0].get('language', '').upper() if tracks else "" - - # For regular files, find the first audio track and return the language string - for track in tracks: - if track['@type'] == "Audio": - return track.get('Language', '').upper() # Correctly retrieve the language - return "" # Return an empty string if no audio track is found + # Helper function to extract the audio language from the text-based MediaInfo + def get_audio_lang(media_info_text): + # Find the audio section and extract the language + audio_section = re.search(r'Audio[\s\S]+?Language\s+:\s+(\w+)', media_info_text) + if audio_section: + return audio_section.group(1).upper() # Return the language in uppercase + return "" # Return empty if not found # Handle non-BDMV cases if meta['is_disc'] != "BDMV": try: - with open(f"{meta.get('base_dir')}/tmp/{meta.get('uuid')}/MediaInfo.json", 'r', encoding='utf-8') as f: - mi = json.load(f) + with open(f"{meta.get('base_dir')}/tmp/{meta.get('uuid')}/MEDIAINFO.txt", 'r', encoding='utf-8') as f: + media_info_text = f.read() - audio_tracks = mi['media']['track'] - has_eng_audio = has_english_audio(audio_tracks) + # Check for English audio + has_eng_audio = has_english_audio(media_info_text) # If English audio is not present, get the audio language if not has_eng_audio: - audio_lang = get_audio_lang(audio_tracks) + audio_lang = get_audio_lang(media_info_text) if audio_lang: # Insert the audio language before the resolution in the name aither_name = aither_name.replace(meta['resolution'], f"{audio_lang} {meta['resolution']}", 1) - except (FileNotFoundError, KeyError, IndexError) as e: - print(f"Error processing MediaInfo: {e}") - - else: - bdinfo_audio = meta.get('bdinfo', {}).get('audio', []) - has_eng_audio = has_english_audio(bdinfo_audio, is_bdmv=True) - if not has_eng_audio: - audio_lang = get_audio_lang(bdinfo_audio, is_bdmv=True) - if audio_lang: - aither_name = aither_name.replace(meta['resolution'], f"{audio_lang} {meta['resolution']}", 1) - - # Handle TV show episode title inclusion - if meta['category'] == "TV" and meta.get('tv_pack', 0) == 0 and meta.get('episode_title_storage', '').strip() and meta['episode'].strip(): - aither_name = aither_name.replace(meta['episode'], f"{meta['episode']} {meta['episode_title_storage']}", 1) + except (FileNotFoundError, KeyError) as e: + print(f"Error processing MEDIAINFO.txt: {e}") return aither_name From b7bfcf1e0c5ed2702c4998efc9d7223a96e84563 Mon Sep 17 00:00:00 2001 From: Audionut Date: Sat, 14 Sep 2024 00:38:28 +1000 Subject: [PATCH 3/3] Correct BDMV handling --- src/trackers/AITHER.py | 65 +++++++++++++++++++++++++----------------- 1 file changed, 39 insertions(+), 26 deletions(-) diff --git a/src/trackers/AITHER.py b/src/trackers/AITHER.py index 4382e47d8..39f58df65 100644 --- a/src/trackers/AITHER.py +++ b/src/trackers/AITHER.py @@ -120,38 +120,51 @@ async def get_flag(self, meta, flag_name): async def edit_name(self, meta): aither_name = meta['name'] - # Helper function to check if English audio is present in the text-based MediaInfo - def has_english_audio(media_info_text): - # Look for the audio section and extract the language line - audio_section = re.search(r'Audio[\s\S]+?Language\s+:\s+(\w+)', media_info_text) - if audio_section: - language = audio_section.group(1) - if language.lower().startswith('en'): # Check if it's English - return True + # Helper function to check if English audio is present + def has_english_audio(tracks=None, media_info_text=None): + if meta['is_disc'] == "BDMV" and tracks: + for track in tracks: + if track.get('language', '').lower() == 'english': + return True + elif media_info_text: + audio_section = re.search(r'Audio[\s\S]+?Language\s+:\s+(\w+)', media_info_text) + if audio_section: + language = audio_section.group(1) + if language.lower().startswith('en'): # Check if it's English + return True return False - # Helper function to extract the audio language from the text-based MediaInfo - def get_audio_lang(media_info_text): - # Find the audio section and extract the language - audio_section = re.search(r'Audio[\s\S]+?Language\s+:\s+(\w+)', media_info_text) - if audio_section: - return audio_section.group(1).upper() # Return the language in uppercase - return "" # Return empty if not found - - # Handle non-BDMV cases - if meta['is_disc'] != "BDMV": + # Helper function to extract the audio language from MediaInfo text or BDMV structure + def get_audio_lang(tracks=None, is_bdmv=False, media_info_text=None): + if meta['is_disc'] == "BDMV" and tracks: + return tracks[0].get('language', '').upper() if tracks else "" + elif media_info_text: + match = re.search(r'Audio[\s\S]+?Language\s+:\s+(\w+)', media_info_text) + if match: + return match.group(1).upper() + return "" # Return empty string if no audio track is found + + is_bdmv = meta['is_disc'] == "BDMV" # noqa #F841 + media_info_tracks = meta.get('media_info_tracks', []) # noqa #F841 + + if meta['is_disc'] == "BDMV": + bdinfo_audio = meta.get('bdinfo', {}).get('audio', []) + has_eng_audio = has_english_audio(bdinfo_audio, is_bdmv=True) + if not has_eng_audio: + audio_lang = get_audio_lang(bdinfo_audio, is_bdmv=True) + if audio_lang: + aither_name = aither_name.replace(meta['resolution'], f"{audio_lang} {meta['resolution']}", 1) + else: + # Handle non-BDMV content try: - with open(f"{meta.get('base_dir')}/tmp/{meta.get('uuid')}/MEDIAINFO.txt", 'r', encoding='utf-8') as f: + media_info_path = f"{meta['base_dir']}/tmp/{meta['uuid']}/MEDIAINFO.txt" + with open(media_info_path, 'r', encoding='utf-8') as f: media_info_text = f.read() - # Check for English audio - has_eng_audio = has_english_audio(media_info_text) - - # If English audio is not present, get the audio language - if not has_eng_audio: - audio_lang = get_audio_lang(media_info_text) + # Check for English audio in the text-based MediaInfo + if not has_english_audio(media_info_text=media_info_text): + audio_lang = get_audio_lang(media_info_text=media_info_text) if audio_lang: - # Insert the audio language before the resolution in the name aither_name = aither_name.replace(meta['resolution'], f"{audio_lang} {meta['resolution']}", 1) except (FileNotFoundError, KeyError) as e: print(f"Error processing MEDIAINFO.txt: {e}")