Enhance configuration files and ensure consistent behavior CLI/module

This make loading of user default configuration file, configuration files, and custom configuration files easier to reason about.

This also allow overriding advanced_configuration at runtime through options dict.

Rebulk rules are now lazily rebuilt when advanced_configuration is changed since previous call.

Close #553
This commit is contained in:
Rémi Alvergnat
2018-10-17 23:07:30 +02:00
parent b00fea6f3d
commit 74195f745c
12 changed files with 284 additions and 471 deletions
-353
View File
@@ -1,353 +0,0 @@
.. _advanced-configuration:
Advanced Configuration
======================
Guessit 3 supports advanced configuration of its internal parameters. This can be done using the
``-c``/``--config`` option. The provided config file should contain a section called ``advanced_config`` with all
parameters and values to be overridden.
Default Advanced Configuration
------------------------------
It's not possible to disable the default advanced configuration (``--no-embedded-config`` won't work for that).
This is by design since Guessit needs all these parameters in order to compile its internal rules and execute them.
Find bellow the internal advanced configuration parameters and their values:
.. code-block:: json
"advanced_config": {
"common_words": [
"de",
"it"
],
"groups": {
"starting": "([{",
"ending": ")]}"
},
"container": {
"subtitles": [
"srt",
"idx",
"sub",
"ssa",
"ass"
],
"info": [
"nfo"
],
"videos": [
"3g2",
"3gp",
"3gp2",
"asf",
"avi",
"divx",
"flv",
"m4v",
"mk2",
"mka",
"mkv",
"mov",
"mp4",
"mp4a",
"mpeg",
"mpg",
"ogg",
"ogm",
"ogv",
"qt",
"ra",
"ram",
"rm",
"ts",
"wav",
"webm",
"wma",
"wmv",
"iso",
"vob"
],
"torrent": [
"torrent"
],
"nzb": [
"nzb"
]
},
"country": {
"synonyms": {
"ES": [
"españa"
],
"GB": [
"UK"
],
"BR": [
"brazilian",
"bra"
],
"CA": [
"québec",
"quebec",
"qc"
],
"MX": [
"Latinoamérica",
"latin america"
]
}
},
"episodes": {
"season_max_range": 100,
"episode_max_range": 100,
"max_range_gap": 1,
"season_markers": [
"s"
],
"season_ep_markers": [
"x"
],
"disc_markers": [
"d"
],
"episode_markers": [
"xe",
"ex",
"ep",
"e",
"x"
],
"range_separators": [
"-",
"~",
"to",
"a"
],
"discrete_separators": [
"+",
"&",
"and",
"et"
],
"season_words": [
"season",
"saison",
"seizoen",
"serie",
"seasons",
"saisons",
"series",
"tem",
"temp",
"temporada",
"temporadas",
"stagione"
],
"episode_words": [
"episode",
"episodes",
"eps",
"ep",
"episodio",
"episodios",
"capitulo",
"capitulos"
],
"of_words": [
"of",
"sur"
],
"all_words": [
"All"
]
},
"language": {
"synonyms": {
"ell": [
"gr",
"greek"
],
"spa": [
"esp",
"español",
"espanol"
],
"fra": [
"français",
"vf",
"vff",
"vfi",
"vfq"
],
"swe": [
"se"
],
"por_BR": [
"po",
"pb",
"pob",
"ptbr",
"br",
"brazilian"
],
"deu_CH": [
"swissgerman",
"swiss german"
],
"nld_BE": [
"flemish"
],
"cat": [
"català",
"castellano",
"espanol castellano",
"español castellano"
],
"ces": [
"cz"
],
"ukr": [
"ua"
],
"zho": [
"cn"
],
"jpn": [
"jp"
],
"hrv": [
"scr"
],
"mul": [
"multi",
"dl"
]
},
"subtitle_affixes": [
"sub",
"subs",
"esub",
"esubs",
"subbed",
"custom subbed",
"custom subs",
"custom sub",
"customsubbed",
"customsubs",
"customsub",
"soft subtitles",
"soft subs"
],
"subtitle_prefixes": [
"st",
"v",
"vost",
"subforced",
"fansub",
"hardsub",
"legenda",
"legendas",
"legendado",
"subtitulado",
"soft",
"subtitles"
],
"subtitle_suffixes": [
"subforced",
"fansub",
"hardsub"
],
"language_affixes": [
"dublado",
"dubbed",
"dub"
],
"language_prefixes": [
"true"
],
"language_suffixes": [
"audio"
],
"weak_affixes": [
"v",
"audio",
"true"
]
},
"part": {
"prefixes": [
"pt",
"part"
]
},
"release_group": {
"forbidden_names": [
"rip",
"by",
"for",
"par",
"pour",
"bonus"
],
"ignored_seps": "[]{}()"
},
"screen_size": {
"frame_rates": [
"23.976",
"24",
"25",
"30",
"48",
"50",
"60",
"120"
],
"min_ar": 1.333,
"max_ar": 1.898,
"interlaced": [
"360",
"480",
"576",
"900",
"1080"
],
"progressive": [
"360",
"480",
"576",
"900",
"1080",
"368",
"720",
"1440",
"2160",
"4320"
]
},
"website": {
"safe_tlds": [
"com",
"org",
"net"
],
"safe_subdomains": [
"www"
],
"safe_prefixes": [
"co",
"com",
"org",
"net"
],
"prefixes": [
"from"
]
}
}
Backwards Compatibility
-----------------------
This is an advanced feature which exposes Guessit internal parameters. These parameters are exposed to help you
tweak Guessit results to fit your needs. We're willing to keep it backwards compatible, but in order to enhance Guessit,
these parameters might change without prior notice.
+36
View File
@@ -0,0 +1,36 @@
.. _configuration:
Configuration files
===================
Guessit supports configuration through configuration file.
This can be done using the ``-c``/``--config`` option, or by creating files at the following locations.
Default configuration file is bundled inside guessit package from `config/options.json <https://github.com/guessit-io/guessit/blob/develop/guessit/config/options.json/>`_ file.
It is possible to disable the default configuration with ``--no-default-config`` option, but you have then to provide a
full configuration file based on the default one.
Configuration files are also loaded from the following paths:
* ``~/.guessit/options.(json|yml|yaml)``
* ``~/.config/guessit/options.(json|yml|yaml)``
It is also possible to disable those user configuration files with ``no-user-config`` option.
As many configuration files can be involved, they are deeply merged to keep all values inside the effective
configuration.
Advanced configuration
======================
Configuration files contains all options available through the command line, but also an additional one named
``advanced_configuration``.
This advanced configuration contains all internal parameters and they are exposed to help you tweaking guessit to
better fit your needs.
If no ``advanced_configuration`` is declared through all effective configuration files, the default one will be used
even when ``--no-default-config`` is used.
We're willing to keep it backwards compatible, but in order to enhance Guessit, these parameters might change without
prior notice.
+20 -14
View File
@@ -68,10 +68,13 @@ GuessIt can be used from command line::
$ guessit
usage: guessit [-h] [-t TYPE] [-n] [-Y] [-D] [-L ALLOWED_LANGUAGES]
[-C ALLOWED_COUNTRIES] [-E] [-T EXPECTED_TITLE] [-G EXPECTED_GROUP]
[-f INPUT_FILE] [-v] [-P SHOW_PROPERTY] [-a] [-1] [-l] [-j] [-y]
[-c CONFIG] [--no-embedded-config] [-p] [-V] [--version]
[filename [filename ...]]
[-C ALLOWED_COUNTRIES] [-E] [-T EXPECTED_TITLE]
[-G EXPECTED_GROUP] [--includes INCLUDES]
[--excludes EXCLUDES] [-f INPUT_FILE] [-v]
[-P SHOW_PROPERTY] [-a] [-s] [-l] [-j] [-y] [-c CONFIG]
[--no-user-config] [--no-default-config] [-p] [-V]
[--version]
[filename [filename ...]]
positional arguments:
filename Filename or release name to guess
@@ -125,15 +128,18 @@ GuessIt can be used from command line::
Configuration:
-c CONFIG, --config CONFIG
Filepath to the configuration file. Configuration
contains the same options as those command line
Filepath to configuration file. Configuration file
contains the same options as those from command line
options, but option names have "-" characters replaced
with "_". If not defined, guessit tries to read a
configuration default configuration file at
with "_". This configuration will be merged with
default and user configuration files.
--no-user-config Disable user configuration. If not defined, guessit
tries to read configuration files at
~/.guessit/options.(json|yml|yaml) and
~/.config/guessit/options.(json|yml|yaml). Set to
"false" to disable default configuration file loading.
--no-embedded-config Disable default configuration.
~/.config/guessit/options.(json|yml|yaml)
--no-default-config Disable default configuration. This should be done
only if you are providing a full configuration through
user configuration or --config option.
Information:
-p, --properties Display properties that can be guessed.
@@ -151,10 +157,10 @@ It can also be used as a python module::
Command line options can be given as dict or string to the second argument.
Advanced Configuration
----------------------
Configuration
-------------
Find more about Guessit advanced configuration at :ref:`advanced configuration page<advanced-configuration>`.
Find more about Guessit configuration at :ref:`configuration page<configuration>`.
REST API