Skip to content

Commit

Permalink
enforce "5.1" surround sound matching in quality profile
Browse files Browse the repository at this point in the history
  • Loading branch information
lardbit committed Aug 4, 2024
1 parent 45e0a1f commit 11e814b
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.0.2 on 2024-08-04 13:49

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('nefarious', '0088_auto_20240802_1551'),
]

operations = [
migrations.AddField(
model_name='qualityprofile',
name='require_five_point_one',
field=models.BooleanField(default=False, help_text='media must be in 5.1 surround sound (e.g. Dolby 5.1)'),
),
]
1 change: 1 addition & 0 deletions src/nefarious/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class QualityProfile(models.Model):
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')
require_hdr = models.BooleanField(default=False, help_text='media must be in HDR (High Dynamic Range)')
require_five_point_one = models.BooleanField(default=False, help_text='media must be in 5.1 surround sound (e.g. Dolby 5.1)')

def __str__(self):
if self.name == self.profile:
Expand Down
40 changes: 29 additions & 11 deletions src/nefarious/parsers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
from nefarious import quality
from nefarious.quality import Resolution, Profile


# TODO add tags in the parsing: "5.1 dolby", release type ...

# piracy nomenclature
# https://en.wikipedia.org/wiki/Pirated_movie_release_types

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

def __init__(self, title):
self.title_query = title
Expand All @@ -78,16 +78,30 @@ def parse(self):
if 'title' in self.match and self.match['title']:
self.match['title'] = self.normalize_media_title(self.match['title'][0])

# quality
title_quality = self.parse_quality(self.title_query)
self.match['quality'] = title_quality.name
self.match['resolution'] = self.parse_resolution(self.title_query)
self.parse_tags()

return self.match

def parse_tags(self):

# quality
title_quality = self.parse_quality(self.title_query)
self.match['quality'] = title_quality.name
self.match['resolution'] = self.parse_resolution(self.title_query)

# hardcoded subs
self.match['hc'] = self.parse_hardcoded_subs()
# hardcoded subs
self.match['hc'] = self.parse_hardcoded_subs()

# hdr
self.match['hdr'] = self.parse_hdr()
# hdr (high dynamic range)
self.match['hdr'] = self.parse_hdr()

# 5.1 surround sound
self.match['five_point_one'] = self.parse_five_point_one()

def parse_five_point_one(self):
# 5.1 surround sound
match = self.five_point_one_regex.search(self.title_query)
return True if match else False

def parse_hdr(self):
match = self.hdr_regex.search(self.title_query)
Expand Down Expand Up @@ -278,6 +292,10 @@ def is_match(self, title, *args, **kwargs) -> bool:
return False
return self._is_match(title, *args, **kwargs)

def is_five_point_one_match(self, needs_five_point_one = False):
# 5.1 surround sound
return self.match['five_point_one'] if needs_five_point_one else True

def is_hdr_match(self, needs_hdr = False):
return self.match['hdr'] if needs_hdr else True

Expand Down
8 changes: 1 addition & 7 deletions src/nefarious/parsers/tv.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,13 +271,7 @@ def parse(self):
for i, episode in enumerate(self.match['episode']):
self.match['episode'][i] = self.normalize_season_episode(episode)

# quality
title_quality = self.parse_quality(self.title_query)
self.match['quality'] = title_quality.name
self.match['resolution'] = self.parse_resolution(self.title_query)

# hardcoded subs
self.match['hc'] = self.parse_hardcoded_subs()
self.parse_tags()

return self.match

Expand Down
3 changes: 3 additions & 0 deletions src/nefarious/processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ def is_match(self, title: str, size_kb: int) -> bool:
# hdr
elif not parser.is_hdr_match(quality_profile.require_hdr):
mismatch = 'hdr'
# 5.1 surround sound
elif not parser.is_five_point_one_match(quality_profile.require_five_point_one):
mismatch = 'five_point_one'
# keyword filters
elif not parser.is_keyword_search_filter_match(
self.nefarious_settings.keyword_search_filters.keys() if self.nefarious_settings.keyword_search_filters else []
Expand Down

0 comments on commit 11e814b

Please sign in to comment.