'Return processed and validated metadata list for all children of requested item.
Parameters required:    rating_key { Plex ratingKey }
Output: array'

def get_metadata_children_details(self, rating_key='', get_children=False, get_media_info=False):

    metadata = self.get_metadata_children(str(rating_key), output_format='xml')
    try:
        xml_head = metadata.getElementsByTagName('MediaContainer')
    except Exception as e:
        logger.warn((u'PlexPy    Pmsconnect    ::    Unable    to    parse    XML    for    get_metadata_children:    %s.' % e))
        return {'metadata': []}
    metadata_list = []
    for a in xml_head:
        if a.getAttribute('size'):
            if (a.getAttribute('size') == '0'):
                metadata_list = {'metadata': []}
                return metadata_list
        if a.getElementsByTagName('Video'):
            metadata_main = a.getElementsByTagName('Video')
            for item in metadata_main:
                child_rating_key = helpers.get_xml_attr(item, 'ratingKey')
                metadata = self.get_metadata_details(str(child_rating_key), get_media_info)
                if metadata:
                    metadata_list.append(metadata['metadata'])
        elif a.getElementsByTagName('Track'):
            metadata_main = a.getElementsByTagName('Track')
            for item in metadata_main:
                child_rating_key = helpers.get_xml_attr(item, 'ratingKey')
                metadata = self.get_metadata_details(str(child_rating_key), get_media_info)
                if metadata:
                    metadata_list.append(metadata['metadata'])
        elif (get_children and a.getElementsByTagName('Directory')):
            dir_main = a.getElementsByTagName('Directory')
            metadata_main = [d for d in dir_main if helpers.get_xml_attr(d, 'ratingKey')]
            for item in metadata_main:
                child_rating_key = helpers.get_xml_attr(item, 'ratingKey')
                metadata = self.get_metadata_children_details(str(child_rating_key), get_children, get_media_info)
                if metadata:
                    metadata_list.extend(metadata['metadata'])
    output = {'metadata': metadata_list}
    return output
