diff --git a/guessit/rules/__init__.py b/guessit/rules/__init__.py index ba8c734..a1b3da7 100644 --- a/guessit/rules/__init__.py +++ b/guessit/rules/__init__.py @@ -9,7 +9,7 @@ from .markers.path import PATH_MARKER from .markers.groups import GROUPS_MARKER from .properties.episodes import EPISODES -from .properties.extension import EXTENSION +from .properties.container import CONTAINER from .properties.format import FORMAT from .properties.video_codec import VIDEO_CODEC from .properties.audio_codec import AUDIO_CODEC @@ -37,7 +37,7 @@ REBULK.rebulk(PATH_MARKER) REBULK.rebulk(GROUPS_MARKER) REBULK.rebulk(EPISODES) -REBULK.rebulk(EXTENSION) +REBULK.rebulk(CONTAINER) REBULK.rebulk(FORMAT) REBULK.rebulk(VIDEO_CODEC) REBULK.rebulk(AUDIO_CODEC) diff --git a/guessit/rules/common/comparators.py b/guessit/rules/common/comparators.py index 529ee98..c6912ec 100644 --- a/guessit/rules/common/comparators.py +++ b/guessit/rules/common/comparators.py @@ -11,7 +11,8 @@ def marker_comparator_predicate(match): Match predicate used in comparator """ return not match.private and \ - match.name not in ['extension', 'properCount', 'title', 'episodeTitle', 'alternativeTitle'] + match.name not in ['properCount', 'title', 'episodeTitle', 'alternativeTitle'] and \ + not (match.name == 'container' and 'extension' in match.tags) def marker_weight(matches, marker): diff --git a/guessit/rules/properties/container.py b/guessit/rules/properties/container.py new file mode 100644 index 0000000..18beef0 --- /dev/null +++ b/guessit/rules/properties/container.py @@ -0,0 +1,43 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +""" +Container support +""" +from rebulk import Rebulk + +import regex as re + +from ..common.validators import seps_surround + +CONTAINER = Rebulk().regex_defaults(flags=re.IGNORECASE).string_defaults(ignore_case=True) +CONTAINER.defaults(name='container', + formatter=lambda value: value[1:], + tags=['extension'], + conflict_solver=lambda match, other: other + if other.name in ['format', 'videoCodec'] or + other.name == 'container' and 'extension' not in other.tags + else '__default__') + +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'] + +CONTAINER.regex(r'\.\L$', exts=subtitles, tags=['extension', 'subtitle']) +CONTAINER.regex(r'\.\L$', exts=info, tags=['extension', 'info']) +CONTAINER.regex(r'\.\L$', exts=videos, tags=['extension', 'video']) +CONTAINER.regex(r'\.\L$', exts=torrent, tags=['extension', 'torrent']) + + +CONTAINER.defaults(name='container', + validator=seps_surround, + conflict_solver=lambda match, other: match + if other.name in ['format', 'videoCodec'] or other.name == 'container' and 'extension' in other.tags + else '__default__') + +CONTAINER.string(*[sub for sub in subtitles if sub not in ['sub']], tags=['subtitle']) +CONTAINER.string(*videos, tags=['video']) +CONTAINER.string(*torrent, tags=['torrent']) diff --git a/guessit/rules/properties/country.py b/guessit/rules/properties/country.py index 376a929..7236bf6 100644 --- a/guessit/rules/properties/country.py +++ b/guessit/rules/properties/country.py @@ -1,7 +1,7 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- """ -Contry +Country """ # pylint: disable=no-member from __future__ import unicode_literals diff --git a/guessit/rules/properties/extension.py b/guessit/rules/properties/extension.py deleted file mode 100644 index 960dbcc..0000000 --- a/guessit/rules/properties/extension.py +++ /dev/null @@ -1,41 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -''' -Season/Episode numbering support -''' -from rebulk import Rebulk - -import regex as re - -from ..common.validators import seps_surround - -EXTENSION = Rebulk().regex_defaults(flags=re.IGNORECASE).string_defaults(ignore_case=True) -EXTENSION.defaults(name='extension', - formatter=lambda value: value[1:], - conflict_solver=lambda match, other: other - if other.name in ['container', 'format', 'videoCodec'] - else '__default__') - -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'] - -EXTENSION.regex(r'\.\L$', exts=subtitles, tags=['subtitle']) -EXTENSION.regex(r'\.\L$', exts=info, tags=['info']) -EXTENSION.regex(r'\.\L$', exts=videos, tags=['video']) -EXTENSION.regex(r'\.\L$', exts=torrent, tags=['torrent']) - - -EXTENSION.defaults(name='container', - validator=seps_surround, - conflict_solver=lambda match, other: match - if other.name in ['extension', 'format', 'videoCodec'] - else '__default__') - -EXTENSION.string(*subtitles, tags=['subtitle']) -EXTENSION.string(*videos, tags=['video']) -EXTENSION.string(*torrent, tags=['torrent']) diff --git a/guessit/rules/properties/language.py b/guessit/rules/properties/language.py index d266e98..b7b9330 100644 --- a/guessit/rules/properties/language.py +++ b/guessit/rules/properties/language.py @@ -11,7 +11,6 @@ import regex as re import babelfish from rebulk import Rebulk, Rule, RemoveMatch, RenameMatch - from ..common.words import iter_words, COMMON_WORDS from ..common.validators import seps_surround @@ -217,7 +216,9 @@ class SubtitleExtensionRule(Rule): consequence = RenameMatch('subtitleLanguage') def when(self, matches, context): - subtitle_extension = matches.named('extension', lambda match: 'subtitle' in match.tags, 0) + subtitle_extension = matches.named('container', + lambda match: 'extension' in match.tags and'subtitle' in match.tags, + 0) if subtitle_extension: subtitle_language = matches.previous(subtitle_extension, lambda match: match.name == 'language', 0) if subtitle_language: diff --git a/guessit/test/episodes.yml b/guessit/test/episodes.yml index c9b34b8..050ff56 100644 --- a/guessit/test/episodes.yml +++ b/guessit/test/episodes.yml @@ -9,7 +9,7 @@ format: HDTV videoCodec: XviD releaseGroup: 0TV - extension: avi + container: avi ? Series/dexter/Dexter.5x02.Hello,.Bandit.ENG.-.sub.FR.HDTV.XviD-AlFleNi-TeaM.[tvu.org.ru].avi : title: Dexter @@ -22,7 +22,7 @@ videoCodec: XviD releaseGroup: AlFleNi-TeaM website: tvu.org.ru - extension: avi + container: avi ? Series/Treme/Treme.1x03.Right.Place,.Wrong.Time.HDTV.XviD-NoTV.avi : title: Treme @@ -782,7 +782,7 @@ season: 2 title: Something episodeTitle: Title - extension: torrent + container: torrent ? Something.Season.2of5.3of9.Ep.Title.HDTV.torrent : episodeCount: 9 @@ -792,7 +792,7 @@ seasonCount: 5 title: Something episodeTitle: Title - extension: torrent + container: torrent ? Something.Other.Season.3of5.Complete.HDTV.torrent : format: HDTV @@ -800,7 +800,7 @@ season: 3 seasonCount: 5 title: Something Other - extension: torrent + container: torrent ? Something.Other.Season.1-3.avi : season: [1, 2, 3] diff --git a/guessit/test/movies.yml b/guessit/test/movies.yml index a2096ca..592e2f0 100644 --- a/guessit/test/movies.yml +++ b/guessit/test/movies.yml @@ -8,7 +8,7 @@ format: HD-DVD audioCodec: DTS videoCodec: h264 - extension: mkv + container: mkv releaseGroup: ESiR ? Movies/El Dia de la Bestia (1995)/El.dia.de.la.bestia.DVDrip.Spanish.DivX.by.Artik[SEDG].avi @@ -18,7 +18,7 @@ language: spanish videoCodec: DivX releaseGroup: Artik[SEDG] - extension: avi + container: avi ? Movies/Dark City (1998)/Dark.City.(1998).DC.BDRip.720p.DTS.X264-CHD.mkv : title: Dark City diff --git a/guessit/test/rules/processors.yml b/guessit/test/rules/processors.yml index fbbfc84..ee906b2 100644 --- a/guessit/test/rules/processors.yml +++ b/guessit/test/rules/processors.yml @@ -5,4 +5,4 @@ ? Some movie (2000)/Some movie (2001).mkv ? Some movie (2001)/Some movie.mkv : year: 2001 - extension: mkv + container: mkv diff --git a/guessit/test/various.yml b/guessit/test/various.yml index 29ecb66..996d29a 100644 --- a/guessit/test/various.yml +++ b/guessit/test/various.yml @@ -374,7 +374,7 @@ title: Something episodeTitle: Title type: episode - extension: torrent + container: torrent ? Show-A (US) - Episode Title S02E09 hdtv : options: -n