Parse media filename for metadata.

    :param str filename: the name of media file
    :returns: dict of metadata attributes found in filename
              or None if no matching expression.
    :rtype: dict

def parse_filename(filename):
    """Parse media filename for metadata.

    :param str filename: the name of media file
    :returns: dict of metadata attributes found in filename
              or None if no matching expression.
    :rtype: dict
    """

    _patterns = patterns.get_expressions()
    result = {}

    for cmatcher in _patterns:
        match = cmatcher.match(filename)
        if match:
            namedgroups = match.groupdict().keys()

            result['pattern'] = cmatcher.pattern
            result['series_name'] = match.group('seriesname')
            result['season_number'] = _get_season_no(match, namedgroups)
            result['episode_numbers'] = _get_episodes(match, namedgroups)
            break
    else:
        result = None

    return result