<s> from urlparse import urlparse , parse_qs <EOL> import requests <EOL> import re <EOL> def youtube_video_id ( url ) : <EOL> """<STR_LIT>""" <EOL> query = urlparse ( url ) <EOL> if query . hostname == '<STR_LIT>' : <EOL> return query . path [ <NUM_LIT:1> : ] <EOL> if query . hostname in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> if query . path == '<STR_LIT>' : <EOL> p = parse_qs ( query . query ) <EOL> return p [ '<STR_LIT:v>' ] [ <NUM_LIT:0> ] <EOL> if query . path [ : <NUM_LIT:7> ] == '<STR_LIT>' : <EOL> return query . path . split ( '<STR_LIT:/>' ) [ <NUM_LIT:2> ] <EOL> if query . path [ : <NUM_LIT:3> ] == '<STR_LIT>' : <EOL> return query . path . split ( '<STR_LIT:/>' ) [ <NUM_LIT:2> ] <EOL> return None <EOL> def twitch_channel ( url ) : <EOL> query = urlparse ( url ) <EOL> path_elements = query . path . strip ( '<STR_LIT:/>' ) . split ( '<STR_LIT:/>' ) <EOL> if len ( path_elements ) == <NUM_LIT:1> : <EOL> channel = path_elements [ <NUM_LIT:0> ] if re . match ( r'<STR_LIT>' , query . hostname ) else None <EOL> return channel if channel else None <EOL> else : <EOL> return None <EOL> def wpc_channel ( url ) : <EOL> query = urlparse ( url ) <EOL> path_elements = query . path . strip ( '<STR_LIT:/>' ) . split ( '<STR_LIT:/>' ) <EOL> if query . hostname in ( '<STR_LIT>' , '<STR_LIT>' ) and len ( path_elements ) == <NUM_LIT:2> and path_elements [ <NUM_LIT:0> ] == '<STR_LIT>' : <EOL> return path_elements [ <NUM_LIT:1> ] <EOL> def requests_get_with_retries ( url , retries_num = <NUM_LIT:5> ) : <EOL> session = requests . Session ( ) <EOL> session . mount ( "<STR_LIT>" , requests . adapters . HTTPAdapter ( max_retries = retries_num ) ) <EOL> session . mount ( "<STR_LIT>" , requests . adapters . HTTPAdapter ( max_retries = retries_num ) ) <EOL> return session . get ( url = url ) </s>
