From 8628b34990fc120bb4b9ed5fb1f43bed678292cf Mon Sep 17 00:00:00 2001 From: lardbit Date: Thu, 1 Aug 2024 08:34:04 -0500 Subject: [PATCH] save tv with custom quality profile, rename QualityProfile.quality -> profile, working processors --- .../src/app/media/media-t-v.component.html | 2 +- .../src/app/media/media-t-v.component.ts | 2 +- .../migrations/0085_auto_20240801_1323.py | 18 ++++++++++++++++++ src/nefarious/models.py | 6 +++--- src/nefarious/processors.py | 16 +++++++++------- 5 files changed, 32 insertions(+), 12 deletions(-) create mode 100644 src/nefarious/migrations/0085_auto_20240801_1323.py diff --git a/src/frontend/src/app/media/media-t-v.component.html b/src/frontend/src/app/media/media-t-v.component.html index d5f58bf9..5796db8f 100644 --- a/src/frontend/src/app/media/media-t-v.component.html +++ b/src/frontend/src/app/media/media-t-v.component.html @@ -43,7 +43,7 @@

{{ tmdbShow.name }}

diff --git a/src/frontend/src/app/media/media-t-v.component.ts b/src/frontend/src/app/media/media-t-v.component.ts index 6a3c3fee..402215cc 100644 --- a/src/frontend/src/app/media/media-t-v.component.ts +++ b/src/frontend/src/app/media/media-t-v.component.ts @@ -352,7 +352,7 @@ export class MediaTVComponent implements OnInit, OnDestroy { } } - public qualityProfiles(): string[] { + public qualityProfiles(): any[] { return this.apiService.qualityProfiles; } diff --git a/src/nefarious/migrations/0085_auto_20240801_1323.py b/src/nefarious/migrations/0085_auto_20240801_1323.py new file mode 100644 index 00000000..166771d7 --- /dev/null +++ b/src/nefarious/migrations/0085_auto_20240801_1323.py @@ -0,0 +1,18 @@ +# Generated by Django 3.0.2 on 2024-08-01 13:23 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('nefarious', '0084_auto_20240728_1752'), + ] + + operations = [ + migrations.RenameField( + model_name='qualityprofile', + old_name='quality', + new_name='profile', + ), + ] diff --git a/src/nefarious/models.py b/src/nefarious/models.py index 84504d6e..249620a1 100644 --- a/src/nefarious/models.py +++ b/src/nefarious/models.py @@ -20,16 +20,16 @@ class QualityProfile(models.Model): name = models.CharField(max_length=500, unique=True) - quality = models.CharField(max_length=500, choices=zip(quality.PROFILE_NAMES, quality.PROFILE_NAMES)) + profile = models.CharField(max_length=500, choices=zip(quality.PROFILE_NAMES, quality.PROFILE_NAMES)) min_size_gb = models.DecimalField( null=True, blank=True, max_digits=10, decimal_places=2, validators=[MinValueValidator(0)], help_text='minimum size (gb) to download') max_size_gb = models.DecimalField( null=True, blank=True, max_digits=10, decimal_places=2, validators=[MinValueValidator(0)], help_text='maximum size (gb) to download') def __str__(self): - if self.name == self.quality: + if self.name == self.profile: return self.name - return f'{self.name} ({self.quality})' + return f'{self.name} ({self.profile})' class NefariousSettings(models.Model): diff --git a/src/nefarious/processors.py b/src/nefarious/processors.py index 67221273..b67ee3de 100644 --- a/src/nefarious/processors.py +++ b/src/nefarious/processors.py @@ -6,7 +6,7 @@ from django.utils import dateparse, timezone from transmissionrpc import Torrent -from nefarious.models import WatchMovie, NefariousSettings, TorrentBlacklist, WatchTVEpisode, WatchTVSeason +from nefarious.models import WatchMovie, NefariousSettings, TorrentBlacklist, WatchTVEpisode, WatchTVSeason, QualityProfile from nefarious.parsers.movie import MovieParser from nefarious.parsers.tv import TVParser from nefarious.quality import Profile @@ -61,7 +61,7 @@ def fetch(self): logger_background.info('Valid Search Results: {}'.format(len(valid_search_results))) - # find the torrent result with the highest weight (i.e seeds) + # find the torrent result with the highest weight (e.g. seeds) best_result = self._get_best_torrent_result(valid_search_results) transmission_client = get_transmission_client(self.nefarious_settings) @@ -99,7 +99,7 @@ def fetch(self): continue else: logger_background.info('No valid search results for {}'.format(self._sanitize_title(str(self.watch_media)))) - # try again without possessive apostrophes (ie. The Handmaids Tale vs The Handmaid's Tale) + # try again without possessive apostrophes (e.g. The Handmaids Tale vs The Handmaid's Tale) if not self._reprocess_without_possessive_apostrophes and self._possessive_apostrophes_regex.search(str(self.watch_media)): self._reprocess_without_possessive_apostrophes = True logger_background.warning('Retrying without possessive apostrophes: "{}"'.format(self._sanitize_title(str(self.watch_media)))) @@ -117,7 +117,9 @@ def fetch(self): def is_match(self, title: str) -> bool: parser = self._get_parser(title) quality_profile = self._get_quality_profile() - profile = Profile.get_from_name(quality_profile) + profile = Profile.get_from_name(quality_profile.profile) + + # TODO - test other profile attributes (min/max size, HDR, etc) return ( self._is_match(parser) and @@ -144,7 +146,7 @@ def _results_with_valid_urls(self, results: list): def _get_best_torrent_result(self, results: list): return get_best_torrent_result(results) - def _get_quality_profile(self): + def _get_quality_profile(self) -> QualityProfile: raise NotImplementedError def _get_watch_media(self, watch_media_id: int): @@ -179,7 +181,7 @@ def _get_search_results(self): class WatchMovieProcessor(WatchProcessorBase): - def _get_quality_profile(self): + def _get_quality_profile(self) -> QualityProfile: # try custom quality profile then fallback to global setting return self.watch_media.quality_profile or self.nefarious_settings.quality_profile_movies @@ -222,7 +224,7 @@ def _get_search_results(self): class WatchTVProcessorBase(WatchProcessorBase): - def _get_quality_profile(self): + def _get_quality_profile(self) -> QualityProfile: # try custom quality profile then fallback to global setting watch_media = self.watch_media # type: WatchTVEpisode|WatchTVSeason return watch_media.watch_tv_show.quality_profile or self.nefarious_settings.quality_profile_tv