<s> import datetime <EOL> import re <EOL> from vidscraper . utils . mimetypes import is_accepted_filename , is_accepted_type <EOL> def struct_time_to_datetime ( struct_time ) : <EOL> """<STR_LIT>""" <EOL> return datetime . datetime ( * struct_time [ : <NUM_LIT:6> ] ) <EOL> def _is_accepted_enclosure ( enclosure ) : <EOL> return ( is_accepted_type ( enclosure . get ( '<STR_LIT:type>' , '<STR_LIT>' ) ) or <EOL> is_accepted_filename ( enclosure . get ( '<STR_LIT:url>' , '<STR_LIT>' ) ) ) <EOL> def get_entry_enclosures ( entry ) : <EOL> """<STR_LIT>""" <EOL> media_content = entry . get ( '<STR_LIT>' ) <EOL> if media_content and media_content [ <NUM_LIT:0> ] : <EOL> return media_content <EOL> enclosures = entry . get ( '<STR_LIT>' ) <EOL> if enclosures and enclosures [ <NUM_LIT:0> ] : <EOL> return enclosures <EOL> return [ ] <EOL> def get_accepted_enclosures ( entry ) : <EOL> """<STR_LIT>""" <EOL> return filter ( _is_accepted_enclosure , get_entry_enclosures ( entry ) ) <EOL> def get_default_enclosure ( enclosures ) : <EOL> for enclosure in enclosures : <EOL> if enclosure . get ( '<STR_LIT>' ) : <EOL> return enclosure <EOL> return None <EOL> def get_item_thumbnail_url ( item ) : <EOL> """<STR_LIT>""" <EOL> if '<STR_LIT>' in item : <EOL> return item [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT:url>' ] <EOL> blip_thumbnail_src = item . get ( '<STR_LIT>' , None ) <EOL> if blip_thumbnail_src : <EOL> return u'<STR_LIT>' . format ( blip_thumbnail_src ) <EOL> if '<STR_LIT>' in item : <EOL> return item [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> if '<STR_LIT:image>' in item : <EOL> return item [ '<STR_LIT:image>' ] [ '<STR_LIT>' ] <EOL> raise KeyError <EOL> def get_entry_thumbnail_url ( entry ) : <EOL> """<STR_LIT>""" <EOL> enclosures = get_accepted_enclosures ( entry ) <EOL> default_enclosure = get_default_enclosure ( enclosures ) <EOL> if default_enclosure is not None : <EOL> try : <EOL> return get_item_thumbnail_url ( default_enclosure ) <EOL> except KeyError : <EOL> pass <EOL> for enclosure in enclosures : <EOL> if enclosure is not default_enclosure : <EOL> try : <EOL> return get_item_thumbnail_url ( enclosure ) <EOL> except KeyError : <EOL> pass <EOL> try : <EOL> return get_item_thumbnail_url ( entry ) <EOL> except KeyError : <EOL> pass <EOL> if entry . get ( '<STR_LIT>' , '<STR_LIT>' ) . find ( u'<STR_LIT>' ) != - <NUM_LIT:1> : <EOL> if '<STR_LIT:content>' in entry : <EOL> content = entry [ '<STR_LIT:content>' ] [ <NUM_LIT:0> ] [ '<STR_LIT:value>' ] <EOL> elif '<STR_LIT>' in entry : <EOL> content = entry [ '<STR_LIT>' ] <EOL> else : <EOL> return None <EOL> match = re . search ( r'<STR_LIT>' , <EOL> content ) <EOL> if match : <EOL> return match . group ( <NUM_LIT:1> ) <EOL> return None </s>
