<s> __all__ = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> from common import * <EOL> def tudou_download_by_iid ( iid , title , merge = True ) : <EOL> xml = get_html ( '<STR_LIT>' + iid + '<STR_LIT>' ) <EOL> from xml . dom . minidom import parseString <EOL> doc = parseString ( xml ) <EOL> title = title or doc . firstChild . getAttribute ( '<STR_LIT>' ) or doc . firstChild . getAttribute ( '<STR_LIT:title>' ) <EOL> urls = [ ( int ( n . getAttribute ( '<STR_LIT>' ) ) , n . firstChild . nodeValue . strip ( ) ) for n in doc . getElementsByTagName ( '<STR_LIT:f>' ) ] <EOL> url = max ( urls , key = lambda x : x [ <NUM_LIT:0> ] ) [ <NUM_LIT:1> ] <EOL> assert '<STR_LIT>' in url <EOL> download_urls ( [ url ] , title , '<STR_LIT>' , total_size = None , merge = merge ) <EOL> def tudou_download_by_id ( id , title , merge = True ) : <EOL> html = get_html ( '<STR_LIT>' % id ) <EOL> iid = r1 ( r'<STR_LIT>' , html ) <EOL> tudou_download_by_iid ( iid , title , merge = merge ) <EOL> def tudou_download ( url , merge = True ) : <EOL> html = get_decoded_html ( url ) <EOL> iid = r1 ( r'<STR_LIT>' , html ) <EOL> assert iid <EOL> title = r1 ( r"<STR_LIT>" , html ) <EOL> assert title <EOL> title = unescape_html ( title ) <EOL> tudou_download_by_iid ( iid , title , merge = merge ) <EOL> def parse_playlist ( url ) : <EOL> raise NotImplementedError ( ) <EOL> def parse_playlist ( url ) : <EOL> aid = r1 ( '<STR_LIT>' , url ) <EOL> html = get_decoded_html ( url ) <EOL> if not aid : <EOL> aid = r1 ( r"<STR_LIT>" , html ) <EOL> if re . match ( r'<STR_LIT>' , url ) : <EOL> atitle = r1 ( r"<STR_LIT>" , html ) <EOL> elif re . match ( r'<STR_LIT>' , url ) : <EOL> atitle = r1 ( r'<STR_LIT>' , html ) <EOL> else : <EOL> raise NotImplementedError ( url ) <EOL> assert aid <EOL> assert atitle <EOL> import json <EOL> url = '<STR_LIT>' + aid <EOL> return [ ( atitle + '<STR_LIT:->' + x [ '<STR_LIT:title>' ] , str ( x [ '<STR_LIT>' ] ) ) for x in json . loads ( get_html ( url ) ) [ '<STR_LIT:message>' ] ] <EOL> def tudou_download_playlist ( url , create_dir = False , merge = True ) : <EOL> if create_dir : <EOL> raise NotImplementedError ( '<STR_LIT>' ) <EOL> videos = parse_playlist ( url ) <EOL> for i , ( title , id ) in enumerate ( videos ) : <EOL> print '<STR_LIT>' % ( i + <NUM_LIT:1> , len ( videos ) ) <EOL> tudou_download_by_iid ( id , title , merge = merge ) <EOL> download = tudou_download <EOL> download_playlist = tudou_download_playlist <EOL> def main ( ) : <EOL> script_main ( '<STR_LIT>' , tudou_download , tudou_download_playlist ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> main ( ) </s>
