Skip to content

Commit

Permalink
Update guessit to 3.0.0 (+subliminal update) (#4244)
Browse files Browse the repository at this point in the history
* Update guessit to v3.0.0

* Initial update to guessit 3

* Mostly format => source changes and renames

* Fix SourceStandardizer rule

* Remove ScreenSizeStandardizer - fixed upstream

* Discard custom 4320p screen_size match - fixed upstream

* Remove FixSeasonRangeWithGap - fixed upstream

* Remove unused `website_rebulk`

* 'DolbyDigital' => 'Dolby Digital' => 'AC3'

Update docstrings for color_depth and audio_codec

* Fix `Quality.to_guessit_source`

* Split Rip/Mux from plain

- Split BR/BD and BRRip/BDRip
- Split DVB and DVBRip

* Workarounds - temporary!

* Update guessit_map and 4K => 2160p

* Fix Quality.to_guessit_source

* Update guessit conversions to support 4320p (8K)

Remove `'source': 'Web', 'other': 'Rip'` from guessit tests

* Fix test_common.py

* Remove ignore from renovate.json

* Update vendored packages list

* Fix test with invalid release group and absolute numbering

* guessit changes that don't need fixes

* Fix invalid episode titles between ep ranges

* Stop testing absurd naming

* Update guessit result

* Fix wrong season parsed from year

* Remove clean_groupname workaround

* Remove workaround note

* Python 2/3 compatibility

* without -> with

* Update tests

* Use custom subliminal version that supports guessit v3

* video.source -> video.source

* video.format -> video.source

* video.format -> video.source

* Fix subtitles download tests

* format -> source

* Fix parent folder replacing episode title, add test

* Revert subtitles download test fix (not needed anymore)

* Improve previous fix

* Optimized previous fix

* Fix audio profile messing up title. Fixes #3300

* Make fix more generic to fix more invalid guesses

* Update ext/readme.md

* Update CHANGELOG.md
  • Loading branch information
sharkykh authored and medariox committed Sep 6, 2018
1 parent ea69d31 commit c71d8c9
Show file tree
Hide file tree
Showing 86 changed files with 9,816 additions and 3,942 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
## Unreleased

#### New Features

#### Improvements
- Updated `guessit` to version 3.0.0 ([#4244](https://github.com/pymedusa/Medusa/pull/4244))

#### Fixes
- Fixed many release name parsing issues as a result of updating `guessit` ([#4244](https://github.com/pymedusa/Medusa/pull/4244))

-----

## 0.2.9 (2018-09-06)
Expand Down
1 change: 1 addition & 0 deletions ext/guessit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
"""
from .api import guessit, GuessItApi
from .options import ConfigurationException
from .rules.common.quantity import Size

from .__version__ import __version__
8 changes: 7 additions & 1 deletion ext/guessit/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
from guessit.options import argument_parser, parse_options, load_config


try:
from collections import OrderedDict
except ImportError: # pragma: no-cover
from ordereddict import OrderedDict # pylint:disable=import-error


def guess_filename(filename, options):
"""
Guess a single filename using given options
Expand All @@ -45,7 +51,7 @@ def guess_filename(filename, options):
import yaml
from guessit import yamlutils

ystr = yaml.dump({filename: dict(guess)}, Dumper=yamlutils.CustomDumper, default_flow_style=False,
ystr = yaml.dump({filename: OrderedDict(guess)}, Dumper=yamlutils.CustomDumper, default_flow_style=False,
allow_unicode=True)
i = 0
for yline in ystr.splitlines():
Expand Down
2 changes: 1 addition & 1 deletion ext/guessit/__version__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
Version module
"""
# pragma: no cover
__version__ = '2.1.4'
__version__ = '3.0.0'
117 changes: 84 additions & 33 deletions ext/guessit/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,21 @@
"""
API functions that can be used by external software
"""

try:
from collections import OrderedDict
except ImportError: # pragma: no-cover
from ordereddict import OrderedDict # pylint:disable=import-error

import os
import traceback

import six

from rebulk.introspector import introspect

from .rules import rebulk_builder
from .options import parse_options
from .options import parse_options, load_config
from .__version__ import __version__


Expand All @@ -41,12 +43,25 @@ def __init__(self, string, options):
self.options = options


def configure(options, rules_builder=rebulk_builder):
"""
Load rebulk rules according to advanced configuration in options dictionary.
:param options:
:type options: dict
:param rules_builder:
:type rules_builder:
:return:
"""
default_api.configure(options, rules_builder=rules_builder, force=True)


def guessit(string, options=None):
"""
Retrieves all matches from string as a dict
:param string: the filename or release name
:type string: str
:param options: the filename or release name
:param options:
:type options: str|dict
:return:
:rtype:
Expand All @@ -58,7 +73,7 @@ def properties(options=None):
"""
Retrieves all properties with possible values that can be guessed
:param options:
:type options:
:type options: str|dict
:return:
:rtype:
"""
Expand All @@ -70,53 +85,88 @@ class GuessItApi(object):
An api class that can be configured with custom Rebulk configuration.
"""

def __init__(self, rebulk):
"""
:param rebulk: Rebulk instance to use.
:type rebulk: Rebulk
:return:
:rtype:
"""
self.rebulk = rebulk
def __init__(self):
"""Default constructor."""
self.rebulk = None

@staticmethod
def _fix_option_encoding(value):
@classmethod
def _fix_encoding(cls, value):
if isinstance(value, list):
return [GuessItApi._fix_option_encoding(item) for item in value]
return [cls._fix_encoding(item) for item in value]
if isinstance(value, dict):
return {cls._fix_encoding(k): cls._fix_encoding(v) for k, v in value.items()}
if six.PY2 and isinstance(value, six.text_type):
return value.encode("utf-8")
return value.encode('utf-8')
if six.PY3 and isinstance(value, six.binary_type):
return value.decode('ascii')
return value

def guessit(self, string, options=None):
def configure(self, options, rules_builder=rebulk_builder, force=False):
"""
Load rebulk rules according to advanced configuration in options dictionary.
:param options:
:type options: str|dict
:param rules_builder:
:type rules_builder:
:param force:
:return:
:rtype: dict
"""
options = parse_options(options, True)
should_load = force or not self.rebulk
advanced_config = options.pop('advanced_config', None)

if should_load and not advanced_config:
advanced_config = load_config(options)['advanced_config']

options = self._fix_encoding(options)

if should_load:
advanced_config = self._fix_encoding(advanced_config)
self.rebulk = rules_builder(advanced_config)

return options

def guessit(self, string, options=None): # pylint: disable=too-many-branches
"""
Retrieves all matches from string as a dict
:param string: the filename or release name
:type string: str
:param options: the filename or release name
:type string: str|Path
:param options:
:type options: str|dict
:return:
:rtype:
"""
try:
options = parse_options(options, True)
from pathlib import Path
if isinstance(string, Path):
try:
# Handle path-like object
string = os.fspath(string)
except AttributeError:
string = str(string)
except ImportError:
pass

try:
options = self.configure(options)
result_decode = False
result_encode = False

fixed_options = {}
for (key, value) in options.items():
key = GuessItApi._fix_option_encoding(key)
value = GuessItApi._fix_option_encoding(value)
fixed_options[key] = value
options = fixed_options

if six.PY2 and isinstance(string, six.text_type):
string = string.encode("utf-8")
result_decode = True
if six.PY3 and isinstance(string, six.binary_type):
string = string.decode('ascii')
result_encode = True
if six.PY2:
if isinstance(string, six.text_type):
string = string.encode("utf-8")
result_decode = True
elif isinstance(string, six.binary_type):
string = six.binary_type(string)
if six.PY3:
if isinstance(string, six.binary_type):
string = string.decode('ascii')
result_encode = True
elif isinstance(string, six.text_type):
string = six.text_type(string)

matches = self.rebulk.matches(string, options)
if result_decode:
for match in matches:
Expand All @@ -139,6 +189,7 @@ def properties(self, options=None):
:return:
:rtype:
"""
options = self.configure(options)
unordered = introspect(self.rebulk, options).properties
ordered = OrderedDict()
for k in sorted(unordered.keys(), key=six.text_type):
Expand All @@ -148,4 +199,4 @@ def properties(self, options=None):
return ordered


default_api = GuessItApi(rebulk_builder())
default_api = GuessItApi()
Loading

0 comments on commit c71d8c9

Please sign in to comment.