mirror of
https://github.com/zoriya/guessit.git
synced 2026-06-05 11:19:19 +00:00
Add default configuration with OSS 117
This commit is contained in:
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"expected_title": [
|
||||||
|
"OSS 117"
|
||||||
|
]
|
||||||
|
}
|
||||||
+38
-25
@@ -5,6 +5,7 @@ Options
|
|||||||
"""
|
"""
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
|
import pkgutil
|
||||||
import shlex
|
import shlex
|
||||||
from argparse import ArgumentParser
|
from argparse import ArgumentParser
|
||||||
|
|
||||||
@@ -21,12 +22,6 @@ def build_argument_parser():
|
|||||||
opts.add_argument(dest='filename', help='Filename or release name to guess', nargs='*')
|
opts.add_argument(dest='filename', help='Filename or release name to guess', nargs='*')
|
||||||
|
|
||||||
naming_opts = opts.add_argument_group("Naming")
|
naming_opts = opts.add_argument_group("Naming")
|
||||||
naming_opts.add_argument('-c', '--config', dest='config', action='append', default=None,
|
|
||||||
help='Filepath to the configuration file. Configuration contains the same options as '
|
|
||||||
'those command line options, but option names have "-" characters replaced with "_". '
|
|
||||||
'If not defined, guessit tries to read a configuration default configuration file at '
|
|
||||||
'~/.guessit/options.(json|yml|yaml) and ~/.config/guessit/options.(json|yml|yaml). '
|
|
||||||
'Set to "false" to disable default configuration file loading.')
|
|
||||||
naming_opts.add_argument('-t', '--type', dest='type', default=None,
|
naming_opts.add_argument('-t', '--type', dest='type', default=None,
|
||||||
help='The suggested file type: movie, episode. If undefined, type will be guessed.')
|
help='The suggested file type: movie, episode. If undefined, type will be guessed.')
|
||||||
naming_opts.add_argument('-n', '--name-only', dest='name_only', action='store_true', default=None,
|
naming_opts.add_argument('-n', '--name-only', dest='name_only', action='store_true', default=None,
|
||||||
@@ -64,6 +59,17 @@ def build_argument_parser():
|
|||||||
output_opts.add_argument('-y', '--yaml', dest='yaml', action='store_true', default=None,
|
output_opts.add_argument('-y', '--yaml', dest='yaml', action='store_true', default=None,
|
||||||
help='Display information for filename guesses as yaml output')
|
help='Display information for filename guesses as yaml output')
|
||||||
|
|
||||||
|
conf_opts = opts.add_argument_group("Configuration")
|
||||||
|
conf_opts.add_argument('-c', '--config', dest='config', action='append', default=None,
|
||||||
|
help='Filepath to the configuration file. Configuration contains the same options as '
|
||||||
|
'those command line options, but option names have "-" characters replaced with "_". '
|
||||||
|
'If not defined, guessit tries to read a configuration default configuration file at '
|
||||||
|
'~/.guessit/options.(json|yml|yaml) and ~/.config/guessit/options.(json|yml|yaml). '
|
||||||
|
'Set to "false" to disable default configuration file loading.')
|
||||||
|
conf_opts.add_argument('--no-embedded-config', dest='no_embedded_config', action='store_true',
|
||||||
|
default=None,
|
||||||
|
help='Disable default configuration.')
|
||||||
|
|
||||||
information_opts = opts.add_argument_group("Information")
|
information_opts = opts.add_argument_group("Information")
|
||||||
information_opts.add_argument('-p', '--properties', dest='properties', action='store_true', default=None,
|
information_opts.add_argument('-p', '--properties', dest='properties', action='store_true', default=None,
|
||||||
help='Display properties that can be guessed.')
|
help='Display properties that can be guessed.')
|
||||||
@@ -111,33 +117,40 @@ def load_config(options):
|
|||||||
:return:
|
:return:
|
||||||
:rtype:
|
:rtype:
|
||||||
"""
|
"""
|
||||||
|
config_files_enabled = True
|
||||||
custom_config_files = None
|
custom_config_files = None
|
||||||
if options.get('config') is not None:
|
if options.get('config') is not None:
|
||||||
custom_config_files = options.get('config')
|
custom_config_files = options.get('config')
|
||||||
if not custom_config_files \
|
if not custom_config_files \
|
||||||
or not custom_config_files[0] \
|
or not custom_config_files[0] \
|
||||||
or custom_config_files[0].lower() in ['0', 'no', 'false', 'disabled']:
|
or custom_config_files[0].lower() in ['0', 'no', 'false', 'disabled']:
|
||||||
return options
|
config_files_enabled = False
|
||||||
|
|
||||||
home_directory = os.path.expanduser("~")
|
|
||||||
cwd = os.getcwd()
|
|
||||||
yaml_supported = False
|
|
||||||
try:
|
|
||||||
import yaml # pylint: disable=unused-variable
|
|
||||||
yaml_supported = True
|
|
||||||
except ImportError:
|
|
||||||
pass
|
|
||||||
config_file_locations = get_config_file_locations(home_directory, cwd, yaml_supported)
|
|
||||||
config_files = [f for f in config_file_locations if os.path.exists(f)]
|
|
||||||
|
|
||||||
if custom_config_files:
|
|
||||||
config_files = config_files + custom_config_files
|
|
||||||
|
|
||||||
configurations = []
|
configurations = []
|
||||||
for config_file in config_files:
|
if config_files_enabled:
|
||||||
config_file_options = load_config_file(config_file)
|
home_directory = os.path.expanduser("~")
|
||||||
if config_file_options:
|
cwd = os.getcwd()
|
||||||
configurations.append(config_file_options)
|
yaml_supported = False
|
||||||
|
try:
|
||||||
|
import yaml # pylint: disable=unused-variable
|
||||||
|
yaml_supported = True
|
||||||
|
except ImportError:
|
||||||
|
pass
|
||||||
|
config_file_locations = get_config_file_locations(home_directory, cwd, yaml_supported)
|
||||||
|
config_files = [f for f in config_file_locations if os.path.exists(f)]
|
||||||
|
|
||||||
|
if custom_config_files:
|
||||||
|
config_files = config_files + custom_config_files
|
||||||
|
|
||||||
|
for config_file in config_files:
|
||||||
|
config_file_options = load_config_file(config_file)
|
||||||
|
if config_file_options:
|
||||||
|
configurations.append(config_file_options)
|
||||||
|
|
||||||
|
if not options.get('no_embedded_config'):
|
||||||
|
embedded_options_data = pkgutil.get_data('guessit', 'config/options.json').decode("utf-8")
|
||||||
|
embedded_options = json.loads(embedded_options_data)
|
||||||
|
configurations.append(embedded_options)
|
||||||
|
|
||||||
if configurations:
|
if configurations:
|
||||||
configurations.append(options)
|
configurations.append(options)
|
||||||
|
|||||||
@@ -5,10 +5,12 @@ Episode title
|
|||||||
"""
|
"""
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
|
|
||||||
from rebulk import Rebulk, Rule, AppendMatch, RenameMatch
|
from rebulk import Rebulk, Rule, AppendMatch, RenameMatch, POST_PROCESS
|
||||||
|
|
||||||
from ..common import seps, title_seps
|
from ..common import seps, title_seps
|
||||||
from ..properties.title import TitleFromPosition, TitleBaseRule
|
|
||||||
from ..common.formatters import cleanup
|
from ..common.formatters import cleanup
|
||||||
|
from ..properties.title import TitleFromPosition, TitleBaseRule
|
||||||
|
from ..properties.type import TypeProcessor
|
||||||
|
|
||||||
|
|
||||||
def episode_title():
|
def episode_title():
|
||||||
@@ -21,7 +23,8 @@ def episode_title():
|
|||||||
AlternativeTitleReplace,
|
AlternativeTitleReplace,
|
||||||
TitleToEpisodeTitle,
|
TitleToEpisodeTitle,
|
||||||
Filepart3EpisodeTitle,
|
Filepart3EpisodeTitle,
|
||||||
Filepart2EpisodeTitle)
|
Filepart2EpisodeTitle,
|
||||||
|
RenameEpisodeTitleWhenMovieType)
|
||||||
return rebulk
|
return rebulk
|
||||||
|
|
||||||
|
|
||||||
@@ -130,9 +133,31 @@ class AlternativeTitleReplace(Rule):
|
|||||||
def then(self, matches, when_response, context):
|
def then(self, matches, when_response, context):
|
||||||
matches.remove(when_response)
|
matches.remove(when_response)
|
||||||
when_response.name = 'episode_title'
|
when_response.name = 'episode_title'
|
||||||
|
when_response.tags.append('alternative-replaced')
|
||||||
matches.append(when_response)
|
matches.append(when_response)
|
||||||
|
|
||||||
|
|
||||||
|
class RenameEpisodeTitleWhenMovieType(Rule):
|
||||||
|
"""
|
||||||
|
Rename episode_title by alternative_title when type is movie.
|
||||||
|
"""
|
||||||
|
priority = POST_PROCESS
|
||||||
|
|
||||||
|
dependency = TypeProcessor
|
||||||
|
consequence = RenameMatch
|
||||||
|
|
||||||
|
def when(self, matches, context):
|
||||||
|
if matches.named('episode_title', lambda m: 'alternative-replaced' not in m.tags) \
|
||||||
|
and not matches.named('type', lambda m: m.value == 'episode'):
|
||||||
|
return matches.named('episode_title')
|
||||||
|
|
||||||
|
def then(self, matches, when_response, context):
|
||||||
|
for match in when_response:
|
||||||
|
matches.remove(match)
|
||||||
|
match.name = 'alternative_title'
|
||||||
|
matches.append(match)
|
||||||
|
|
||||||
|
|
||||||
class Filepart3EpisodeTitle(Rule):
|
class Filepart3EpisodeTitle(Rule):
|
||||||
"""
|
"""
|
||||||
If we have at least 3 filepart structured like this:
|
If we have at least 3 filepart structured like this:
|
||||||
|
|||||||
@@ -296,11 +296,6 @@ def episodes():
|
|||||||
|
|
||||||
rebulk.regex(r'Minisodes?', name='episode_format', value="Minisode")
|
rebulk.regex(r'Minisodes?', name='episode_format', value="Minisode")
|
||||||
|
|
||||||
# Harcoded movie to disable weak season/eps
|
|
||||||
rebulk.regex('OSS-?117',
|
|
||||||
abbreviations=[dash], name="hardcoded-movies", marker=True,
|
|
||||||
conflict_solver=lambda match, other: None)
|
|
||||||
|
|
||||||
rebulk.rules(EpisodeNumberSeparatorRange(range_separators),
|
rebulk.rules(EpisodeNumberSeparatorRange(range_separators),
|
||||||
SeasonSeparatorRange(range_separators), RemoveWeakIfMovie, RemoveWeakIfSxxExx,
|
SeasonSeparatorRange(range_separators), RemoveWeakIfMovie, RemoveWeakIfSxxExx,
|
||||||
RemoveWeakDuplicate, EpisodeDetailValidator, RemoveDetachedEpisodeNumber, VersionValidator,
|
RemoveWeakDuplicate, EpisodeDetailValidator, RemoveDetachedEpisodeNumber, VersionValidator,
|
||||||
@@ -418,7 +413,7 @@ class RemoveWeakIfMovie(Rule):
|
|||||||
return context.get('type') != 'episode'
|
return context.get('type') != 'episode'
|
||||||
|
|
||||||
def when(self, matches, context):
|
def when(self, matches, context):
|
||||||
if matches.named('year') or matches.markers.named('hardcoded-movies'):
|
if matches.named('year'):
|
||||||
return matches.tagged('weak-movie')
|
return matches.tagged('weak-movie')
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ def title():
|
|||||||
|
|
||||||
expected_title = build_expected_function('expected_title')
|
expected_title = build_expected_function('expected_title')
|
||||||
|
|
||||||
rebulk.functional(expected_title, name='title', tags=['expected'],
|
rebulk.functional(expected_title, name='title', tags=['expected', 'title'],
|
||||||
validator=seps_surround,
|
validator=seps_surround,
|
||||||
formatter=formatters(cleanup, reorder_title),
|
formatter=formatters(cleanup, reorder_title),
|
||||||
conflict_solver=lambda match, other: other,
|
conflict_solver=lambda match, other: other,
|
||||||
|
|||||||
@@ -823,12 +823,13 @@
|
|||||||
video_codec: h264
|
video_codec: h264
|
||||||
year: 2015
|
year: 2015
|
||||||
|
|
||||||
? Hyena.Road.2015.German.Ep.Title.1080p.DL.DTSHD.Bluray.x264-pmHD
|
? Hyena.Road.2015.German.1080p.DL.DTSHD.Bluray.x264-pmHD
|
||||||
: audio_codec: DTS
|
: audio_codec: DTS
|
||||||
audio_profile: HD
|
audio_profile: HD
|
||||||
episode_title: German Ep Title
|
|
||||||
format: BluRay
|
format: BluRay
|
||||||
language: mul
|
language:
|
||||||
|
- de
|
||||||
|
- mul
|
||||||
release_group: pmHD
|
release_group: pmHD
|
||||||
screen_size: 1080p
|
screen_size: 1080p
|
||||||
title: Hyena Road
|
title: Hyena Road
|
||||||
|
|||||||
@@ -119,21 +119,22 @@ def test_load_config_file():
|
|||||||
|
|
||||||
|
|
||||||
def test_load_config():
|
def test_load_config():
|
||||||
config = load_config({'param1': 'test', 'config': [os.path.join(__location__, 'config', 'test.yml')]})
|
config = load_config({'no_embedded_config': True, 'param1': 'test',
|
||||||
|
'config': [os.path.join(__location__, 'config', 'test.yml')]})
|
||||||
|
|
||||||
assert config['param1'] == 'test'
|
assert config['param1'] == 'test'
|
||||||
|
|
||||||
assert config['expected_title'] == ['The 100', 'OSS 117']
|
assert config['expected_title'] == ['The 100', 'OSS 117']
|
||||||
assert config['yaml'] is True
|
assert config['yaml'] is True
|
||||||
|
|
||||||
config = load_config({'param1': 'test'})
|
config = load_config({'no_embedded_config': True, 'param1': 'test'})
|
||||||
|
|
||||||
assert config['param1'] == 'test'
|
assert config['param1'] == 'test'
|
||||||
|
|
||||||
assert 'expected_title' not in config
|
assert 'expected_title' not in config
|
||||||
assert 'yaml' not in config
|
assert 'yaml' not in config
|
||||||
|
|
||||||
config = load_config({'param1': 'test', 'config': ['false']})
|
config = load_config({'no_embedded_config': True, 'param1': 'test', 'config': ['false']})
|
||||||
|
|
||||||
assert config['param1'] == 'test'
|
assert config['param1'] == 'test'
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ import pytest
|
|||||||
from rebulk.remodule import re
|
from rebulk.remodule import re
|
||||||
from rebulk.utils import is_iterable
|
from rebulk.utils import is_iterable
|
||||||
|
|
||||||
from ..options import parse_options
|
from ..options import parse_options, load_config
|
||||||
from ..yamlutils import OrderedDictYAMLLoader
|
from ..yamlutils import OrderedDictYAMLLoader
|
||||||
from .. import guessit
|
from .. import guessit
|
||||||
|
|
||||||
@@ -209,6 +209,7 @@ class TestYml(object):
|
|||||||
if 'implicit' not in options:
|
if 'implicit' not in options:
|
||||||
options['implicit'] = True
|
options['implicit'] = True
|
||||||
options['config'] = False
|
options['config'] = False
|
||||||
|
options = load_config(options)
|
||||||
try:
|
try:
|
||||||
result = guessit(string, options)
|
result = guessit(string, options)
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
|
|||||||
@@ -25,6 +25,8 @@ dev_require = ['zest.releaser[recommended]', 'pylint', 'tox', 'sphinx', 'sphinx-
|
|||||||
|
|
||||||
tests_require = ['pytest>=2.7.3', 'pytest-benchmark', 'pytest-capturelog', 'PyYAML']
|
tests_require = ['pytest>=2.7.3', 'pytest-benchmark', 'pytest-capturelog', 'PyYAML']
|
||||||
|
|
||||||
|
package_data = ['config/*']
|
||||||
|
|
||||||
entry_points = {
|
entry_points = {
|
||||||
'console_scripts': [
|
'console_scripts': [
|
||||||
'guessit = guessit.__main__:main'
|
'guessit = guessit.__main__:main'
|
||||||
@@ -60,6 +62,7 @@ args = dict(name='guessit',
|
|||||||
download_url='https://pypi.python.org/packages/source/g/guessit/guessit-%s.tar.gz' % version,
|
download_url='https://pypi.python.org/packages/source/g/guessit/guessit-%s.tar.gz' % version,
|
||||||
license='LGPLv3',
|
license='LGPLv3',
|
||||||
packages=find_packages(),
|
packages=find_packages(),
|
||||||
|
package_data={'guessit': package_data},
|
||||||
include_package_data=True,
|
include_package_data=True,
|
||||||
install_requires=install_requires,
|
install_requires=install_requires,
|
||||||
setup_requires=setup_requires,
|
setup_requires=setup_requires,
|
||||||
|
|||||||
Reference in New Issue
Block a user