Ejemplo n.º 1
0
for artist in artist_list:
    print '{}\t{}\n'.format(datetime.datetime.today(), artist)
    log.write('{}\t{}\n'.format(datetime.datetime.today(), artist))
    if kr:
        count = 9999
    else:
        count = baidu.get_artist_song_count(artist)
    if count == 0:
        continue
    start = 0
    while start < count:
        song_list = baidu.get_song_list(artist, start)
        if not song_list or len(song_list) == 0:
            break
        for song in song_list:
            down_url, artist_name, song_name = baidu.get_download_url(song)
            try:
                lrc_url = 'http://music.baidu.com' + baidu.get_lrc_url(song)
            except:
                lrc_url = ''
            if not down_url or not down_url.startswith('http://yinyueshiting.baidu.com'):
                continue
            down.write('{}\n{}\n'.format(down_url, lrc_url))
            try:
                record.write('{}\t{}\t{}\t{}\n'.format(song_name, artist_name, down_url, lrc_url))
                b = Baidu(name=song_name.decode('utf8'), singer=artist_name.decode('utf8'), url=down_url, lrc=lrc_url)
                session.add(b)
            except Exception as e:
                continue
        start += 25
    try: