Skip to content

Commit

Permalink
Merge pull request #28 from LimeDrive:develop
Browse files Browse the repository at this point in the history
Fix resolution filter and update pyproject.toml version
  • Loading branch information
LimeDrive authored Sep 12, 2024
2 parents 20d39b3 + fef60ca commit c9fe3f0
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 41 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "stream-fusion"
version = "1.1.0"
version = "1.1.2"
description = "StreamFusion is an advanced plugin for Stremio that significantly enhances its streaming capabilities with debrid service."
authors = ["LimeDrive <[email protected]>"]
readme = "README.md"
Expand Down
23 changes: 11 additions & 12 deletions stream_fusion/utils/filter/quality_exclusion_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,21 @@ def filter(self, data):
]

def _is_stream_allowed(self, stream) -> bool:
if any(q.upper() in self.excluded_qualities for q in stream.parsed_data.quality):
if stream.parsed_data.quality.upper() in self.excluded_qualities:
logger.debug(f"Stream excluded due to main quality: {stream.parsed_data.quality}")
return False

if stream.parsed_data.resolution:
for item in stream.parsed_data.resolution:
item_upper = item.upper()
if item_upper in self.excluded_qualities:
logger.debug(f"Stream excluded due to quality spec: {item}")
return False
if self.exclude_rips and item_upper in self.RIPS:
logger.debug(f"Stream excluded due to RIP: {item}")
return False
if self.exclude_cams and item_upper in self.CAMS:
logger.debug(f"Stream excluded due to CAM: {item}")
return False
resolution_upper = stream.parsed_data.resolution.upper()
if resolution_upper in self.excluded_qualities:
logger.debug(f"Stream excluded due to quality spec: {stream.parsed_data.resolution}")
return False
if self.exclude_rips and resolution_upper in self.RIPS:
logger.debug(f"Stream excluded due to RIP: {stream.parsed_data.resolution}")
return False
if self.exclude_cams and resolution_upper in self.CAMS:
logger.debug(f"Stream excluded due to CAM: {stream.parsed_data.resolution}")
return False

logger.debug("Stream allowed")
return True
Expand Down
2 changes: 1 addition & 1 deletion stream_fusion/utils/filter/results_per_quality_filter.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from stream_fusion.utils.filter.base_filter import BaseFilter
from stream_fusion.logging_config import logger


#TODO: Check if this filter is still needed and RTN changes for it.
class ResultsPerQualityFilter(BaseFilter):
def __init__(self, config):
super().__init__(config)
Expand Down
77 changes: 50 additions & 27 deletions stream_fusion/utils/zilean/zilean_api.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
import requests
from typing import List, Optional, Tuple
from pydantic import BaseModel, Field
from pydantic import BaseModel, ConfigDict, Field
from requests.adapters import HTTPAdapter
from urllib3.util.retry import Retry

from stream_fusion.settings import settings
from stream_fusion.logging_config import logger


class DMMQueryRequest(BaseModel):
queryText: Optional[str] = None


class DMMImdbFile(BaseModel):
imdbId: Optional[str] = None
category: Optional[str] = None
title: Optional[str] = None
adult: bool = False
year: int = 0

adult: Optional[bool] = None
year: Optional[int] = None

class DMMImdbSearchResult(BaseModel):
title: Optional[str] = None
Expand All @@ -27,29 +23,58 @@ class DMMImdbSearchResult(BaseModel):
score: float = 0.0
category: Optional[str] = None


class DMMTorrentInfo(BaseModel):
info_hash: Optional[str] = None
resolution: Tuple[str, ...] = Field(default_factory=tuple)
model_config = ConfigDict(populate_by_name=True)

info_hash: str
raw_title: str
size: str
parsed_title: Optional[str] = None
normalized_title: Optional[str] = None
trash: Optional[bool] = None
year: Optional[int] = None
remastered: Optional[bool] = None
codec: Tuple[str, ...] = Field(default_factory=tuple)
resolution: Optional[str] = None
seasons: Tuple[int, ...] = Field(default_factory=tuple)
episodes: Tuple[int, ...] = Field(default_factory=tuple)
complete: Optional[bool] = None
volumes: Tuple[int, ...] = Field(default_factory=tuple)
languages: Tuple[str, ...] = Field(default_factory=tuple)
quality: Optional[str] = None
hdr: Tuple[str, ...] = Field(default_factory=tuple)
codec: Optional[str] = None
audio: Tuple[str, ...] = Field(default_factory=tuple)
quality: Tuple[str, ...] = Field(default_factory=tuple)
episode: Tuple[int, ...] = Field(default_factory=tuple)
season: Tuple[int, ...] = Field(default_factory=tuple)
language: Tuple[str, ...] = Field(default_factory=tuple)
parsed_title: Optional[str] = None
raw_title: Optional[str] = None
size: int = 0
channels: Tuple[str, ...] = Field(default_factory=tuple)
dubbed: Optional[bool] = None
subbed: Optional[bool] = None
date: Optional[str] = None
group: Optional[str] = None
edition: Optional[str] = None
bit_depth: Optional[str] = None
bitrate: Optional[str] = None
network: Optional[str] = None
extended: Optional[bool] = None
converted: Optional[bool] = None
hardcoded: Optional[bool] = None
region: Optional[str] = None
ppv: Optional[bool] = None
three_d: Optional[bool] = Field(None, alias='_3d')
site: Optional[str] = None
proper: Optional[bool] = None
repack: Optional[bool] = None
retail: Optional[bool] = None
upscaled: Optional[bool] = None
remastered: Optional[bool] = None
unrated: Optional[bool] = None
documentary: Optional[bool] = None
episode_code: Optional[str] = None
country: Optional[str] = None
container: Optional[str] = None
extension: Optional[str] = None
torrent: Optional[bool] = None
category: Optional[str] = None
imdb_id: Optional[str] = None
imdb: Optional[DMMImdbFile] = None

class Config:
frozen = True


class ZileanAPI:
def __init__(
self,
Expand All @@ -61,8 +86,8 @@ def __init__(
if not self.base_url:
logger.error("Zilean API URL is not set in the environment variables.")
raise ValueError("Zilean API URL is not set in the environment variables.")
self.session = requests.Session()

self.session = requests.Session()
retry_strategy = Retry(
total=max_retries,
backoff_factor=0.1,
Expand Down Expand Up @@ -92,13 +117,11 @@ def _request(self, method: str, endpoint: str, **kwargs):
raise

def _convert_to_dmm_torrent_info(self, entry: dict) -> DMMTorrentInfo:
for key in ['resolution', 'codec', 'audio', 'quality', 'episode', 'season', 'language']:
for key in ['seasons', 'episodes', 'volumes', 'languages', 'hdr', 'audio', 'channels']:
if key in entry and isinstance(entry[key], list):
entry[key] = tuple(entry[key])

if 'imdb' in entry and entry['imdb']:
entry['imdb'] = DMMImdbFile(**entry['imdb'])

return DMMTorrentInfo(**entry)

def dmm_search(self, query: DMMQueryRequest) -> List[DMMTorrentInfo]:
Expand Down

0 comments on commit c9fe3f0

Please sign in to comment.