Skip to content

Commit

Permalink
Fix: prased audio type
Browse files Browse the repository at this point in the history
  • Loading branch information
LimeDrive authored and TEALC82 committed Jul 12, 2024
1 parent 680566b commit c61d691
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 64 deletions.
108 changes: 77 additions & 31 deletions stream_fusion/utils/detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
return default_types.get(languages[0], "VO")
4 changes: 0 additions & 4 deletions stream_fusion/utils/jackett/jackett_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down
4 changes: 0 additions & 4 deletions stream_fusion/utils/jackett/jackett_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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):
Expand Down
8 changes: 1 addition & 7 deletions stream_fusion/utils/torrent/torrent_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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"

Expand Down Expand Up @@ -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,
Expand All @@ -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']
Expand Down
8 changes: 0 additions & 8 deletions stream_fusion/utils/zilean/zilean_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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,
Expand All @@ -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
Expand Down
30 changes: 20 additions & 10 deletions stream_fusion/web/root/search/stremio_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "[⚡]"
Expand Down Expand Up @@ -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}"
Expand All @@ -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:
Expand Down

0 comments on commit c61d691

Please sign in to comment.