Skip to content

Commit

Permalink
save tv with custom quality profile, rename QualityProfile.quality ->…
Browse files Browse the repository at this point in the history
… profile, working processors
  • Loading branch information
lardbit committed Aug 1, 2024
1 parent f227d7e commit 8628b34
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/frontend/src/app/media/media-t-v.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ <h3 class="media-title">{{ tmdbShow.name }}</h3>
<label class="col-lg-6 col-form-label">Quality Profile</label>
<div class="col-lg-6">
<select class="form-select form-select-sm" [formControl]="qualityProfileControl">
<option *ngFor="let profile of qualityProfiles()" [value]="profile">{{ profile }}</option>
<option *ngFor="let profile of qualityProfiles()" [value]="profile.id">{{ profile.name }}</option>
</select>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/src/app/media/media-t-v.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ export class MediaTVComponent implements OnInit, OnDestroy {
}
}

public qualityProfiles(): string[] {
public qualityProfiles(): any[] {
return this.apiService.qualityProfiles;
}

Expand Down
18 changes: 18 additions & 0 deletions src/nefarious/migrations/0085_auto_20240801_1323.py
Original file line number Diff line number Diff line change
@@ -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',
),
]
6 changes: 3 additions & 3 deletions src/nefarious/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
16 changes: 9 additions & 7 deletions src/nefarious/processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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))))
Expand All @@ -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
Expand All @@ -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):
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 8628b34

Please sign in to comment.