From 8e50a6837f725d9da47146e24ad555f548f3cfb6 Mon Sep 17 00:00:00 2001 From: LimeDrive Date: Fri, 12 Jul 2024 15:21:01 +0200 Subject: [PATCH] Fix: prased audio type --- stream_fusion/utils/detection.py | 108 +++++++++++++----- stream_fusion/utils/jackett/jackett_result.py | 4 - .../utils/jackett/jackett_service.py | 4 - stream_fusion/utils/torrent/torrent_item.py | 8 +- stream_fusion/utils/zilean/zilean_result.py | 8 -- .../web/root/search/stremio_parser.py | 30 +++-- 6 files changed, 98 insertions(+), 64 deletions(-) diff --git a/stream_fusion/utils/detection.py b/stream_fusion/utils/detection.py index 043f7c2..911ea98 100644 --- a/stream_fusion/utils/detection.py +++ b/stream_fusion/utils/detection.py @@ -28,39 +28,85 @@ def detect_languages(torrent_name): return languages -def detect_french_languages(torrent_name): - french_patterns = { - "VFF": r"\b(?:VFF|TRUEFRENCH)\b", - "VF2": r"\b(?:VF2)\b", - "VFQ": r"\b(?:VFQ)\b", - "VFI": r"\b(?:VFI)\b", - "VOSTFR ": r"\b(?:VOSTFR|SUBFRENCH)\b", +def detect_audios_type(raw_title, languages): + language_specific_patterns = { + "fr": { + "VFF": r"\b(?:VFF|TRUEFRENCH)\b", + "VF2": r"\b(?:VF2)\b", + "VFQ": r"\b(?:VFQ)\b", + "VFI": r"\b(?:VFI)\b", + "VOF": r"\b(?:VOF)\b", + "VQ": r"\b(?:VOQ|VQ)\b", + "VOSTFR": r"\b(?:VOSTFR|SUBFRENCH)\b", + "FRENCH": r"\b(?:FRENCH|FR)\b" + }, + "en": { + "ENG": r"\b(?:ENG|ENGLISH)\b", + "VO": r"\b(?:VO|OV)\b", + "SUBBED": r"\b(?:SUB|SUBBED|SUBTITLE[SD])\b" + }, + "es": { + "ESP": r"\b(?:ESP|SPANISH)\b" + }, + "de": { + "GER": r"\b(?:GER|GERMAN|DEUTSCH)\b" + }, + "it": { + "ITA": r"\b(?:ITA|ITALIAN)\b" + }, + "ja": { + "JAP": r"\b(?:JAP|JAPANESE)\b" + }, + "ko": { + "KOR": r"\b(?:KOR|KOREAN)\b" + }, + "zh": { + "CHI": r"\b(?:CHI|CHINESE|MANDARIN)\b" + }, + "ru": { + "RUS": r"\b(?:RUS|RUSSIAN)\b" + }, + "pt": { + "POR": r"\b(?:POR|PORTUGUESE)\b" + }, + "nl": { + "DUT": r"\b(?:DUT|DUTCH)\b" + }, + "sv": { + "SWE": r"\b(?:SWE|SWEDISH)\b" + }, + "da": { + "DAN": r"\b(?:DAN|DANISH)\b" + }, + "no": { + "NOR": r"\b(?:NOR|NORWEGIAN)\b" + }, + "fi": { + "FIN": r"\b(?:FIN|FINNISH)\b" + } } - - myfrench = "" - for french, pattern in french_patterns.items(): - if re.search(pattern, torrent_name, re.IGNORECASE): - myfrench = french - - if len(myfrench) == 0: + + if not languages: return "VF" + + if isinstance(languages, str): + languages = [languages] - return myfrench - + if "multi" in languages: + for lang_patterns in language_specific_patterns.values(): + for audio_type, pattern in lang_patterns.items(): + if re.search(pattern, raw_title, re.IGNORECASE): + return audio_type + else: + for language in languages: + patterns = language_specific_patterns.get(language, {}) + for audio_type, pattern in patterns.items(): + if re.search(pattern, raw_title, re.IGNORECASE): + return audio_type -def detect_hdr(torrent_name): - hdr_patterns = { - "HDR": r"\bHDR(?:10\+?|10Plus|10p?)?\b", - "DV": r"\bDV|DoVi\b", - "IMAX": r"\bIMAX\b", + default_types = { + "fr": "VF", + "en": "VO", + "multi": "MULTI" } - - hdrs = [] - for hdr, pattern in hdr_patterns.items(): - if re.search(pattern, torrent_name, re.IGNORECASE): - hdrs.append(hdr) - - if len(hdrs) == 0: - return [""] - - return hdrs \ No newline at end of file + return default_types.get(languages[0], "VO") \ No newline at end of file diff --git a/stream_fusion/utils/jackett/jackett_result.py b/stream_fusion/utils/jackett/jackett_result.py index 74b8d4c..7375232 100644 --- a/stream_fusion/utils/jackett/jackett_result.py +++ b/stream_fusion/utils/jackett/jackett_result.py @@ -17,8 +17,6 @@ def __init__(self): # Extra processed details for further filtering self.languages = None # Language of the torrent - self.frenchlanguage = None # French Language Type - self.typehdr = None # HDR / DV self.type = None # series or movie self.parsed_data = None # Ranked result @@ -32,8 +30,6 @@ def convert_to_torrent_item(self): self.link, self.seeders, self.languages, - self.frenchlanguage, - self.typehdr, self.indexer, self.privacy, self.type, diff --git a/stream_fusion/utils/jackett/jackett_service.py b/stream_fusion/utils/jackett/jackett_service.py index 72531b1..13ddbc4 100644 --- a/stream_fusion/utils/jackett/jackett_service.py +++ b/stream_fusion/utils/jackett/jackett_service.py @@ -12,8 +12,6 @@ from stream_fusion.utils.models.movie import Movie from stream_fusion.utils.models.series import Series from stream_fusion.utils.detection import detect_languages -from stream_fusion.utils.detection import detect_french_languages -from stream_fusion.utils.detection import detect_hdr from stream_fusion.logging_config import logger from stream_fusion.settings import settings @@ -273,8 +271,6 @@ def __post_process_results(self, results, media): result.parsed_data = parsed_result result.languages = detect_languages(result.raw_title) - result.frenchlanguage = detect_french_languages(result.raw_title) - result.typehdr = detect_hdr(result.raw_title) result.type = media.type if isinstance(media, Series): diff --git a/stream_fusion/utils/torrent/torrent_item.py b/stream_fusion/utils/torrent/torrent_item.py index 844687c..b1737d5 100644 --- a/stream_fusion/utils/torrent/torrent_item.py +++ b/stream_fusion/utils/torrent/torrent_item.py @@ -7,7 +7,7 @@ class TorrentItem: - def __init__(self, raw_title, size, magnet, info_hash, link, seeders, languages, frenchlanguage, typehdr, indexer, + def __init__(self, raw_title, size, magnet, info_hash, link, seeders, languages, indexer, privacy, type=None, parsed_data=None): self.logger = logger @@ -19,8 +19,6 @@ def __init__(self, raw_title, size, magnet, info_hash, link, seeders, languages, self.seeders = seeders # The number of seeders self.languages = languages # Language of the torrent self.indexer = indexer # Indexer of the torrent - self.frenchlanguage = frenchlanguage # French Language Type - self.typehdr = typehdr # HDR / DV self.type = type # "series" or "movie" self.privacy = privacy # "public" or "private" @@ -53,8 +51,6 @@ def to_dict(self): 'link': self.link, 'seeders': self.seeders, 'languages': self.languages, - 'frenchlanguage' : self.frenchlanguage, - 'typehdr' : self.typehdr, 'indexer': self.indexer, 'type': self.type, 'privacy': self.privacy, @@ -80,8 +76,6 @@ def from_dict(cls, data): link=data['link'], seeders=data['seeders'], languages=data['languages'], - frenchlanguage=data['frenchlanguage'], - typehdr=data['typehdr'], indexer=data['indexer'], privacy=data['privacy'], type=data['type'] diff --git a/stream_fusion/utils/zilean/zilean_result.py b/stream_fusion/utils/zilean/zilean_result.py index 8a83b31..14da751 100644 --- a/stream_fusion/utils/zilean/zilean_result.py +++ b/stream_fusion/utils/zilean/zilean_result.py @@ -3,8 +3,6 @@ from stream_fusion.utils.torrent.torrent_item import TorrentItem from stream_fusion.logging_config import logger from stream_fusion.utils.detection import detect_languages -from stream_fusion.utils.detection import detect_french_languages -from stream_fusion.utils.detection import detect_hdr class ZileanResult: @@ -21,8 +19,6 @@ def __init__(self): # Extra processed details for further filtering self.languages = None # Language of the torrent - self.frenchlanguage = None # French Language Type - self.typehdr = None # HDR / DV self.type = None # series or movie self.parsed_data = None # Ranked result @@ -36,8 +32,6 @@ def convert_to_torrent_item(self): self.link, self.seeders, self.languages, - self.frenchlanguage, - self.typehdr, self.indexer, self.privacy, self.type, @@ -59,8 +53,6 @@ def from_api_cached_item(self, api_cached_item, media): self.magnet = "magnet:?xt=urn:btih:" + self.info_hash self.link = self.magnet self.languages = detect_languages(self.raw_title) - self.frenchlanguage = detect_french_languages(self.raw_title) - self.typehdr = detect_hdr(self.raw_title) self.seeders = 0 self.size = api_cached_item['filesize'] self.type = media.type diff --git a/stream_fusion/web/root/search/stremio_parser.py b/stream_fusion/web/root/search/stremio_parser.py index bb35caf..779d089 100644 --- a/stream_fusion/web/root/search/stremio_parser.py +++ b/stream_fusion/web/root/search/stremio_parser.py @@ -2,10 +2,13 @@ import queue import threading from typing import List +from RTN import ParsedData from stream_fusion.utils.models.media import Media from stream_fusion.utils.torrent.torrent_item import TorrentItem from stream_fusion.utils.string_encoding import encodeb64 +from stream_fusion.utils.detection import detect_audios_type +from stream_fusion.logging_config import logger INSTANTLY_AVAILABLE = "[⚡]" @@ -53,6 +56,7 @@ def parse_to_debrid_stream(torrent_item: TorrentItem, configb64, host, torrentin name = f"{DOWNLOAD_REQUIRED}\n" parsed_data = torrent_item.parsed_data.data + logger.debug(f"Parsed data: {parsed_data}") resolution = parsed_data.resolution[0] if parsed_data.resolution else "Unknow" name += f"{resolution}" @@ -62,24 +66,30 @@ def parse_to_debrid_stream(torrent_item: TorrentItem, configb64, host, torrentin size_in_gb = round(int(torrent_item.size) / 1024 / 1024 / 1024, 2) - title = f"{torrent_item.raw_title}\n" + title = f"{parsed_data.raw_title}\n" - #if torrent_item.file_name is not None: - # title += f"{torrent_item.file_name}\n" + if media.type == "series" and torrent_item.file_name is not None: + title += f"{torrent_item.file_name}\n" - title += f"👥 {torrent_item.seeders} 💾 {size_in_gb}GB 🔍 {torrent_item.indexer}\n" + title += f"👥 {torrent_item.seeders} 💾 {size_in_gb}GB 🔍 {torrent_item.indexer}\n" if parsed_data.codec: - title += f"🎥 {', '.join(parsed_data.codec)} {'.'.join(torrent_item.typehdr)}\n" + title += f"🎥 {', '.join(parsed_data.codec)} {'.'.join(parsed_data.hdr)}\n" else: - title += f"🎥 {'.'.join(torrent_item.typehdr)}\n" + title += f"🎥 {'.'.join(parsed_data.hdr)}\n" + + audio_type = detect_audios_type(parsed_data.raw_title, torrent_item.languages) + audio_info = [] + + if audio_type: + audio_info.append(audio_type) if parsed_data.audio: - title += f"🎧 {torrent_item.frenchlanguage} {', '.join(parsed_data.audio)}\n" - else: - title += f"🎧 {torrent_item.frenchlanguage}\n" + audio_info.extend(parsed_data.audio) - # Gestion des langues + if audio_info: + title += f"🎧 {' | '.join(audio_info)}\n" + if torrent_item.languages: title += "/".join(get_emoji(language) for language in torrent_item.languages) else: