From aba054a6ec684a4ae437d59c7ddff43f30534f2e Mon Sep 17 00:00:00 2001 From: Toilal Date: Thu, 5 Nov 2015 21:46:41 +0100 Subject: [PATCH] Add mimetype property --- guessit/rules/processors.py | 4 +++- guessit/rules/properties/mimetype.py | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 guessit/rules/properties/mimetype.py diff --git a/guessit/rules/processors.py b/guessit/rules/processors.py index d349292..ab51d4e 100644 --- a/guessit/rules/processors.py +++ b/guessit/rules/processors.py @@ -12,6 +12,7 @@ from .common.comparators import marker_sorted from .common.date import valid_year from .properties.type import type_processor +from .properties.mimetype import mimetype_processor import six @@ -163,4 +164,5 @@ def enlarge_group_matches(matches): PROCESSORS = Rebulk().processor(enlarge_group_matches).post_processor(equivalent_holes, remove_ambiguous, - country_in_title, season_year, type_processor) + country_in_title, season_year, mimetype_processor, + type_processor) diff --git a/guessit/rules/properties/mimetype.py b/guessit/rules/properties/mimetype.py new file mode 100644 index 0000000..1572c47 --- /dev/null +++ b/guessit/rules/properties/mimetype.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +""" +mimetype property +""" +import mimetypes + +from rebulk.match import Match + + +def mimetype_processor(matches): + """ + Mimetype post processor + :param matches: + :type matches: + :return: + :rtype: + """ + mime, _ = mimetypes.guess_type(matches.input_string, strict=False) + if mime is not None: + matches.append(Match(0, len(matches.input_string), name='mimetype', value=mime))