diff --git a/backend/program/__init__.py b/backend/program/__init__.py index 1349560c..811cd1f7 100644 --- a/backend/program/__init__.py +++ b/backend/program/__init__.py @@ -40,7 +40,6 @@ def start(self): super().start() self.running = True - def run(self): while self.running: if self.validate(): diff --git a/backend/program/media/item.py b/backend/program/media/item.py index 6d3a1b32..627a4638 100644 --- a/backend/program/media/item.py +++ b/backend/program/media/item.py @@ -9,10 +9,7 @@ Library, LibraryPartial, ) -from utils.utils import parser -from program.scrapers import Scraping -from program.realdebrid import Debrid -from program.symlink import Symlinker +from utils.parser import parser class MediaItem: diff --git a/backend/program/realdebrid.py b/backend/program/realdebrid.py index 086ed03f..3a98fa5d 100644 --- a/backend/program/realdebrid.py +++ b/backend/program/realdebrid.py @@ -8,7 +8,7 @@ from utils.logger import logger from utils.request import get, post, ping from utils.settings import settings_manager -from utils.utils import parser +from utils.parser import parser WANTED_FORMATS = [".mkv", ".mp4", ".avi"] diff --git a/backend/program/scrapers/jackett.py b/backend/program/scrapers/jackett.py index 41f82653..2ae1ac11 100644 --- a/backend/program/scrapers/jackett.py +++ b/backend/program/scrapers/jackett.py @@ -1,11 +1,11 @@ """ Jackett scraper module """ from typing import Optional -from pydantic import BaseModel, Field +from pydantic import BaseModel from requests import RequestException from utils.logger import logger from utils.settings import settings_manager -from utils.utils import parser -from utils.request import RateLimitExceeded, get, ping, RateLimiter +from utils.parser import parser +from utils.request import RateLimitExceeded, get, RateLimiter class JackettConfig(BaseModel): diff --git a/backend/program/scrapers/orionoid.py b/backend/program/scrapers/orionoid.py index ee804a3b..3de6a629 100644 --- a/backend/program/scrapers/orionoid.py +++ b/backend/program/scrapers/orionoid.py @@ -1,12 +1,11 @@ """ Orionoid scraper module """ -from datetime import datetime from typing import Optional from pydantic import BaseModel from requests.exceptions import RequestException from utils.logger import logger from utils.request import RateLimitExceeded, RateLimiter, get from utils.settings import settings_manager -from utils.utils import parser +from utils.parser import parser KEY_APP = "D3CH6HMX9KD9EMD68RXRCDUNBDJV5HRR" diff --git a/backend/program/scrapers/torrentio.py b/backend/program/scrapers/torrentio.py index 4bfa4723..291678cd 100644 --- a/backend/program/scrapers/torrentio.py +++ b/backend/program/scrapers/torrentio.py @@ -5,7 +5,7 @@ from utils.logger import logger from utils.request import RateLimitExceeded, get, RateLimiter from utils.settings import settings_manager -from utils.utils import parser +from utils.parser import parser class TorrentioConfig(BaseModel): diff --git a/backend/utils/parser.py b/backend/utils/parser.py new file mode 100644 index 00000000..8b885872 --- /dev/null +++ b/backend/utils/parser.py @@ -0,0 +1,56 @@ +import PTN + + +class Parser: + def __init__(self): + self.resolution = ["1080p", "720p"] + self.language = ["English"] + + def _parse(self, string): + parse = PTN.parse(string) + + # episodes + episodes = [] + if parse.get("episode", False): + episode = parse.get("episode") + if type(episode) == list: + for sub_episode in episode: + episodes.append(int(sub_episode)) + else: + episodes.append(int(episode)) + + season = parse.get("season") + + resolution = parse.get("resolution") + quality = parse.get("quality") + language = parse.get("language") + if not language: + language = "English" + extended = parse.get("extended") + + return { + "episodes": episodes or [], + "resolution": resolution or [], + "language": language or [], + "extended": extended, + "season": season, + } + + def episodes(self, string): + parse = self._parse(string) + return parse["episodes"] + + def episodes_in_season(self, season, string): + parse = self._parse(string) + if parse["season"] == season: + return parse["episodes"] + return [] + + def parse(self, string): + parse = self._parse(string) + return ( + parse["resolution"] in self.resolution + and parse["language"] in self.language + ) + +parser = Parser() \ No newline at end of file diff --git a/backend/utils/utils.py b/backend/utils/utils.py index dfeeb193..b75d1c33 100644 --- a/backend/utils/utils.py +++ b/backend/utils/utils.py @@ -1,7 +1,6 @@ import os import threading import time -import PTN class Pickly(threading.Thread): @@ -38,57 +37,3 @@ def run(self): break time.sleep(i) - -class Parser: - def __init__(self): - self.resolution = ["1080p", "720p"] - self.language = ["English"] - - def _parse(self, string): - parse = PTN.parse(string) - - # episodes - episodes = [] - if parse.get("episode", False): - episode = parse.get("episode") - if type(episode) == list: - for sub_episode in episode: - episodes.append(int(sub_episode)) - else: - episodes.append(int(episode)) - - season = parse.get("season") - - resolution = parse.get("resolution") - quality = parse.get("quality") - language = parse.get("language") - if not language: - language = "English" - extended = parse.get("extended") - - return { - "episodes": episodes or [], - "resolution": resolution or [], - "language": language or [], - "extended": extended, - "season": season, - } - - def episodes(self, string): - parse = self._parse(string) - return parse["episodes"] - - def episodes_in_season(self, season, string): - parse = self._parse(string) - if parse["season"] == season: - return parse["episodes"] - return [] - - def parse(self, string): - parse = self._parse(string) - return ( - parse["resolution"] in self.resolution - and parse["language"] in self.language - ) - -parser = Parser()