Skip to content

Commit 11e814b

Browse files
committed
enforce "5.1" surround sound matching in quality profile
1 parent 45e0a1f commit 11e814b

File tree

5 files changed

+52
-18
lines changed

5 files changed

+52
-18
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-04 13:49
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('nefarious', '0088_auto_20240802_1551'),
10+
]
11+
12+
operations = [
13+
migrations.AddField(
14+
model_name='qualityprofile',
15+
name='require_five_point_one',
16+
field=models.BooleanField(default=False, help_text='media must be in 5.1 surround sound (e.g. Dolby 5.1)'),
17+
),
18+
]

src/nefarious/models.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class QualityProfile(models.Model):
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')
2828
require_hdr = models.BooleanField(default=False, help_text='media must be in HDR (High Dynamic Range)')
29+
require_five_point_one = models.BooleanField(default=False, help_text='media must be in 5.1 surround sound (e.g. Dolby 5.1)')
2930

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

src/nefarious/parsers/base.py

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
from nefarious import quality
44
from nefarious.quality import Resolution, Profile
55

6-
7-
# TODO add tags in the parsing: "5.1 dolby", release type ...
8-
6+
# piracy nomenclature
7+
# https://en.wikipedia.org/wiki/Pirated_movie_release_types
98

109
# regex parsing taken from:
1110
# https://github.com/Sonarr/Sonarr/blob/537e4d7c39e839e75e7a7ad84e95cd582ec1d20e/src/NzbDrone.Core/Parser/QualityParser.cs
@@ -61,6 +60,7 @@ class ParserBase:
6160
raw_hd_regex = regex.compile(r"\b(?<rawhd>RawHD|1080i[-_. ]HDTV|Raw[-_. ]HD|MPEG[-_. ]?2)\b", regex.I)
6261
hardcoded_subs_regex = regex.compile(r"\b(?<hc>hc|korsub)\b", regex.I)
6362
hdr_regex = regex.compile(r"\bhdr\b", regex.I)
63+
five_point_one_regex = regex.compile(r'\b(ddp?)?5[. ]1\b', regex.I) # # 5.1 surround sound
6464

6565
def __init__(self, title):
6666
self.title_query = title
@@ -78,16 +78,30 @@ def parse(self):
7878
if 'title' in self.match and self.match['title']:
7979
self.match['title'] = self.normalize_media_title(self.match['title'][0])
8080

81-
# quality
82-
title_quality = self.parse_quality(self.title_query)
83-
self.match['quality'] = title_quality.name
84-
self.match['resolution'] = self.parse_resolution(self.title_query)
81+
self.parse_tags()
82+
83+
return self.match
84+
85+
def parse_tags(self):
86+
87+
# quality
88+
title_quality = self.parse_quality(self.title_query)
89+
self.match['quality'] = title_quality.name
90+
self.match['resolution'] = self.parse_resolution(self.title_query)
8591

86-
# hardcoded subs
87-
self.match['hc'] = self.parse_hardcoded_subs()
92+
# hardcoded subs
93+
self.match['hc'] = self.parse_hardcoded_subs()
8894

89-
# hdr
90-
self.match['hdr'] = self.parse_hdr()
95+
# hdr (high dynamic range)
96+
self.match['hdr'] = self.parse_hdr()
97+
98+
# 5.1 surround sound
99+
self.match['five_point_one'] = self.parse_five_point_one()
100+
101+
def parse_five_point_one(self):
102+
# 5.1 surround sound
103+
match = self.five_point_one_regex.search(self.title_query)
104+
return True if match else False
91105

92106
def parse_hdr(self):
93107
match = self.hdr_regex.search(self.title_query)
@@ -278,6 +292,10 @@ def is_match(self, title, *args, **kwargs) -> bool:
278292
return False
279293
return self._is_match(title, *args, **kwargs)
280294

295+
def is_five_point_one_match(self, needs_five_point_one = False):
296+
# 5.1 surround sound
297+
return self.match['five_point_one'] if needs_five_point_one else True
298+
281299
def is_hdr_match(self, needs_hdr = False):
282300
return self.match['hdr'] if needs_hdr else True
283301

src/nefarious/parsers/tv.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -271,13 +271,7 @@ def parse(self):
271271
for i, episode in enumerate(self.match['episode']):
272272
self.match['episode'][i] = self.normalize_season_episode(episode)
273273

274-
# quality
275-
title_quality = self.parse_quality(self.title_query)
276-
self.match['quality'] = title_quality.name
277-
self.match['resolution'] = self.parse_resolution(self.title_query)
278-
279-
# hardcoded subs
280-
self.match['hc'] = self.parse_hardcoded_subs()
274+
self.parse_tags()
281275

282276
return self.match
283277

src/nefarious/processors.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ def is_match(self, title: str, size_kb: int) -> bool:
139139
# hdr
140140
elif not parser.is_hdr_match(quality_profile.require_hdr):
141141
mismatch = 'hdr'
142+
# 5.1 surround sound
143+
elif not parser.is_five_point_one_match(quality_profile.require_five_point_one):
144+
mismatch = 'five_point_one'
142145
# keyword filters
143146
elif not parser.is_keyword_search_filter_match(
144147
self.nefarious_settings.keyword_search_filters.keys() if self.nefarious_settings.keyword_search_filters else []

0 commit comments

Comments
 (0)