'Return processed and validated list of recently added items.
Parameters required:    count { number of results to return }
Output: array'

def get_recently_added_details(self, section_id='', start='0', count='0'):

    if section_id:
        recent = self.get_library_recently_added(section_id, start, count, output_format='xml')
    else:
        recent = self.get_recently_added(start, count, output_format='xml')
    try:
        xml_head = recent.getElementsByTagName('MediaContainer')
    except Exception as e:
        logger.warn((u'PlexPy    Pmsconnect    ::    Unable    to    parse    XML    for    get_recently_added:    %s.' % e))
        return []
    recents_list = []
    for a in xml_head:
        if a.getAttribute('size'):
            if (a.getAttribute('size') == '0'):
                output = {'recently_added': []}
                return output
        if a.getElementsByTagName('Directory'):
            recents_main = a.getElementsByTagName('Directory')
            for item in recents_main:
                recent_items = {'media_type': helpers.get_xml_attr(item, 'type'), 'rating_key': helpers.get_xml_attr(item, 'ratingKey'), 'parent_rating_key': helpers.get_xml_attr(item, 'parentRatingKey'), 'grandparent_rating_key': helpers.get_xml_attr(item, 'grandparentRatingKey'), 'title': helpers.get_xml_attr(item, 'title'), 'parent_title': helpers.get_xml_attr(item, 'parentTitle'), 'grandparent_title': helpers.get_xml_attr(item, 'grandparentTitle'), 'media_index': helpers.get_xml_attr(item, 'index'), 'parent_media_index': helpers.get_xml_attr(item, 'parentIndex'), 'section_id': (section_id if section_id else helpers.get_xml_attr(item, 'librarySectionID')), 'library_name': helpers.get_xml_attr(item, 'librarySectionTitle'), 'year': helpers.get_xml_attr(item, 'year'), 'thumb': helpers.get_xml_attr(item, 'thumb'), 'parent_thumb': helpers.get_xml_attr(item, 'parentThumb'), 'grandparent_thumb': helpers.get_xml_attr(item, 'grandparentThumb'), 'added_at': helpers.get_xml_attr(item, 'addedAt')}
                recents_list.append(recent_items)
        if a.getElementsByTagName('Video'):
            recents_main = a.getElementsByTagName('Video')
            for item in recents_main:
                recent_items = {'media_type': helpers.get_xml_attr(item, 'type'), 'rating_key': helpers.get_xml_attr(item, 'ratingKey'), 'parent_rating_key': helpers.get_xml_attr(item, 'parentRatingKey'), 'grandparent_rating_key': helpers.get_xml_attr(item, 'grandparentRatingKey'), 'title': helpers.get_xml_attr(item, 'title'), 'parent_title': helpers.get_xml_attr(item, 'parentTitle'), 'grandparent_title': helpers.get_xml_attr(item, 'grandparentTitle'), 'media_index': helpers.get_xml_attr(item, 'index'), 'parent_media_index': helpers.get_xml_attr(item, 'parentIndex'), 'section_id': (section_id if section_id else helpers.get_xml_attr(item, 'librarySectionID')), 'library_name': helpers.get_xml_attr(item, 'librarySectionTitle'), 'year': helpers.get_xml_attr(item, 'year'), 'thumb': helpers.get_xml_attr(item, 'thumb'), 'parent_thumb': helpers.get_xml_attr(item, 'parentThumb'), 'grandparent_thumb': helpers.get_xml_attr(item, 'grandparentThumb'), 'added_at': helpers.get_xml_attr(item, 'addedAt')}
                recents_list.append(recent_items)
    output = {'recently_added': sorted(recents_list, key=(lambda k: k['added_at']), reverse=True)}
    return output
