Skip to content

Commit 371ee88

Browse files
committed
enforce HDR quality profile setting in processor
1 parent a2bc7d3 commit 371ee88

File tree

5 files changed

+64
-4
lines changed

5 files changed

+64
-4
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Generated by Django 3.0.2 on 2024-08-02 14:16
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('nefarious', '0085_auto_20240801_1323'),
10+
]
11+
12+
operations = [
13+
migrations.AddField(
14+
model_name='qualityprofile',
15+
name='is_hdr',
16+
field=models.BooleanField(default=False),
17+
),
18+
]
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Generated by Django 3.0.2 on 2024-08-02 14:57
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('nefarious', '0086_qualityprofile_is_hdr'),
10+
]
11+
12+
operations = [
13+
migrations.RemoveField(
14+
model_name='qualityprofile',
15+
name='is_hdr',
16+
),
17+
migrations.AddField(
18+
model_name='qualityprofile',
19+
name='hdr',
20+
field=models.BooleanField(default=False, help_text='media must be in HDR (High Dynamic Range)'),
21+
),
22+
]

src/nefarious/models.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class QualityProfile(models.Model):
2525
null=True, blank=True, max_digits=10, decimal_places=2, validators=[MinValueValidator(0)], help_text='minimum size (gb) to download')
2626
max_size_gb = models.DecimalField(
2727
null=True, blank=True, max_digits=10, decimal_places=2, validators=[MinValueValidator(0)], help_text='maximum size (gb) to download')
28+
hdr = models.BooleanField(default=False, help_text='media must be in HDR (High Dynamic Range)')
2829

2930
def __str__(self):
3031
if self.name == self.profile:

src/nefarious/parsers/base.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
from nefarious.quality import Resolution, Profile
55

66

7+
# TODO add tags in the parsing: "5.1 dolby", release type ...
8+
9+
710
# regex parsing taken from:
811
# https://github.com/Sonarr/Sonarr/blob/537e4d7c39e839e75e7a7ad84e95cd582ec1d20e/src/NzbDrone.Core/Parser/QualityParser.cs
912
# https://github.com/Radarr/Radarr/blob/e01900628f86696469875dcb79f60071278100ba/src/NzbDrone.Core/Parser/QualityParser.cs
@@ -57,6 +60,7 @@ class ParserBase:
5760
high_def_pdtv_regex = regex.compile(r"hr[-_. ]ws", regex.I)
5861
raw_hd_regex = regex.compile(r"\b(?<rawhd>RawHD|1080i[-_. ]HDTV|Raw[-_. ]HD|MPEG[-_. ]?2)\b", regex.I)
5962
hardcoded_subs_regex = regex.compile(r"\b(?<hc>hc|korsub)\b", regex.I)
63+
hdr_regex = regex.compile(r"\bhdr\b", regex.I)
6064

6165
def __init__(self, title):
6266
self.title_query = title
@@ -82,6 +86,13 @@ def parse(self):
8286
# hardcoded subs
8387
self.match['hc'] = self.parse_hardcoded_subs()
8488

89+
# hdr
90+
self.match['hdr'] = self.parse_hdr()
91+
92+
def parse_hdr(self):
93+
match = self.hdr_regex.search(self.title_query)
94+
return True if match else False
95+
8596
def parse_hardcoded_subs(self):
8697
match = self.hardcoded_subs_regex.search(self.title_query)
8798
return True if match else False
@@ -267,6 +278,9 @@ def is_match(self, title, *args, **kwargs) -> bool:
267278
return False
268279
return self._is_match(title, *args, **kwargs)
269280

281+
def is_hdr_match(self, needs_hdr = False):
282+
return self.match['hdr'] if needs_hdr else True
283+
270284
def is_quality_match(self, profile: Profile) -> bool:
271285
return self.match['quality'] in profile.qualities
272286

src/nefarious/processors.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from transmissionrpc import Torrent
88

99
from nefarious.models import WatchMovie, NefariousSettings, TorrentBlacklist, WatchTVEpisode, WatchTVSeason, QualityProfile
10+
from nefarious.parsers.base import ParserBase
1011
from nefarious.parsers.movie import MovieParser
1112
from nefarious.parsers.tv import TVParser
1213
from nefarious.quality import Profile
@@ -119,7 +120,7 @@ def is_match(self, title: str, size_kb: int) -> bool:
119120
size_gb = size_kb / (1024**2)
120121
mismatch_reason = ''
121122

122-
# TODO - test other profile attributes (min/max size, HDR, etc)
123+
# TODO - test other profile attributes (dolby 5.1, etc)
123124

124125
# title
125126
if not self._is_match(parser):
@@ -135,6 +136,10 @@ def is_match(self, title: str, size_kb: int) -> bool:
135136
# subs
136137
elif not parser.is_hardcoded_subs_match(self.nefarious_settings.allow_hardcoded_subs):
137138
mismatch_reason = f'hardcoded subs'
139+
# hdr
140+
elif not parser.is_hdr_match(quality_profile.hdr):
141+
mismatch_reason = 'hdr'
142+
138143
# keyword filters
139144
elif not parser.is_keyword_search_filter_match(
140145
self.nefarious_settings.keyword_search_filters.keys() if self.nefarious_settings.keyword_search_filters else []
@@ -177,7 +182,7 @@ def _get_download_dir(self, transmission_session):
177182
def _get_tmdb_media(self):
178183
raise NotImplementedError
179184

180-
def _get_parser(self, title: str):
185+
def _get_parser(self, title: str) -> ParserBase:
181186
raise NotImplementedError
182187

183188
def _get_tmdb_title_key(self):
@@ -204,7 +209,7 @@ def _get_quality_profile(self) -> QualityProfile:
204209
# try custom quality profile then fallback to global setting
205210
return self.watch_media.quality_profile or self.nefarious_settings.quality_profile_movies
206211

207-
def _get_parser(self, title: str):
212+
def _get_parser(self, title: str) -> MovieParser:
208213
return MovieParser(title)
209214

210215
def _is_match(self, parser):
@@ -248,7 +253,7 @@ def _get_quality_profile(self) -> QualityProfile:
248253
watch_media = self.watch_media # type: WatchTVEpisode|WatchTVSeason
249254
return watch_media.watch_tv_show.quality_profile or self.nefarious_settings.quality_profile_tv
250255

251-
def _get_parser(self, title: str):
256+
def _get_parser(self, title: str) -> TVParser:
252257
return TVParser(title)
253258

254259
def _get_media_type(self) -> str:

0 commit comments

Comments
 (0)