Skip to content

Commit

Permalink
feat(week): add week property
Browse files Browse the repository at this point in the history
  • Loading branch information
Toilal committed Feb 18, 2023
1 parent ff0a327 commit 8309bf1
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 2 deletions.
4 changes: 4 additions & 0 deletions docs/properties.md
Expand Up @@ -42,6 +42,10 @@ Main properties

Year of movie (or episode).

- **week**

Week number, from 1 to 52, of episode.

- **release\_group**

Name of (non)scene group that released the file.
Expand Down
3 changes: 3 additions & 0 deletions guessit/config/options.json
Expand Up @@ -839,6 +839,9 @@
"Yahoo": "YHOO",
"YouTube Red": "RED",
"ZDF": "ZDF"
},
"date": {
"week_words": ["week"]
}
}
}
5 changes: 5 additions & 0 deletions guessit/rules/common/date.py
Expand Up @@ -34,6 +34,11 @@ def valid_year(year):
return 1920 <= year < 2030


def valid_week(week):
"""Check if number is a valid week"""
return 1 <= week < 53


def _is_int(string):
"""
Check if the input string is an integer
Expand Down
17 changes: 15 additions & 2 deletions guessit/rules/properties/date.py
@@ -1,13 +1,17 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
date and year properties
date, week and year properties
"""
import re

from rebulk import Rebulk, RemoveMatch, Rule

from ..common.date import search_date, valid_year
from ..common import dash
from ..common.date import search_date, valid_year, valid_week
from ..common.pattern import is_disabled
from ..common.validators import seps_surround
from ...reutils import build_or_pattern


def date(config): # pylint:disable=unused-argument
Expand All @@ -28,6 +32,15 @@ def date(config): # pylint:disable=unused-argument
else '__default__',
validator=lambda match: seps_surround(match) and valid_year(match.value))

rebulk.regex(build_or_pattern(config.get('week_words')) + r"-?(\d{1,2})",
name="week", formatter=int,
children=True,
flags=re.IGNORECASE, abbreviations=[dash],
conflict_solver=lambda match, other: other
if other.name in ('episode', 'season') and len(other.raw) < len(match.raw)
else '__default__',
validator=lambda match: seps_surround(match) and valid_week(match.value))

def date_functional(string, context): # pylint:disable=inconsistent-return-statements
"""
Search for date in the string and retrieves match
Expand Down
7 changes: 7 additions & 0 deletions guessit/test/rules/episodes.yml
Expand Up @@ -330,7 +330,14 @@
season: 2010
episode: 2

? Show Name - S32-Dummy 45-Ep 6478
: title: Show Name
episode_title: Dummy 45
season: 32
episode: 6478

? Show Name - S32-Week 45-Ep 6478
: title: Show Name
season: 32
week: 45
episode: 6478

0 comments on commit 8309bf1

Please sign in to comment.