def parse_duration(duration):
    """ Parse and prettify duration from youtube duration format """
    duration_dict = re.search(DURATION_REGEX, duration).groupdict()
    converted_dict = {}
    # convert all values to ints, remove nones
    for a, x in duration_dict.iteritems():
        if x is not None:
            converted_dict[a] = int(NON_DECIMAL.sub('', x))
    return str(timedelta(**converted_dict))
def parse_duration ( duration ) : duration_dict = re . search ( DURATION_REGEX , duration ) . groupdict ( ) converted_dict = { } for a , x in duration_dict . iteritems ( ) : if x is not None : converted_dict [ a ] = int ( NON_DECIMAL . sub ( '' , x ) ) return str ( timedelta ( ** converted_dict ) )
Parse and prettify duration from youtube duration format