Esempio n. 1
0
def get_song_lyric(song_id):
    url = 'http://music.163.com/api/song/lyric?os=pc&id=' + str(song_id) + '&lv=-1&kv=-1&tv=-1'
    res = requestUrl(url)
    try:
        data = json.loads(res)
        song_info = data['songs'][0]
        dic = {}
        dic['name'] = song_info['name']
        dic['id'] = song_info['id']
        dic['position'] = song_info['position']
        dic['artist'] = song_info['artists'][0]['name']
        dic['score'] = song_info['score']
        dic['popularity'] = song_info['popularity']
        DB.hmset('songs:' + str(song_id), dic)
    except Exception, e:
        print e
Esempio n. 2
0
def get_song_info(song_id):
    url = 'http://music.163.com/api/song/detail/?id=' + str(song_id) + '&ids=%5B' + str(song_id) + '%5D'
    res = requestUrl(url)
    try:
        data = json.loads(res)
        song_info = data['songs'][0]
        dic = {}
        print song_info['name']
        dic['name'] = song_info['name']
        dic['id'] = song_info['id']
        dic['position'] = song_info['position']
        dic['artist'] = song_info['artists'][0]['name']
        dic['score'] = song_info['score']
        dic['popularity'] = song_info['popularity']
        DB.hmset('songs:' + str(song_id), dic)
    except Exception, e:
        print e
Esempio n. 3
0
def get_user_info(user_id):
    url = 'http://music.163.com/user/home?id=' + str(user_id)
    data = requestUrl(url)
    try:
        soup = BeautifulSoup(data, 'html.parser')
        dic = {}
        city= soup.find('div', attrs={'class': 'inf'}).find('span')
        name = soup.find('span', attrs={'class': 'tit f-ff2 s-fc0 f-thide'})
        if name:
            dic['name']=name.text
        if city:
            dic['city']=city.text[5:]
        dic['img'] = soup.find('dt', attrs={'id': 'ava'}).find('img').get('src')

        DB.hmset('user:' + str(user_id), dic)

    except Exception, e:
        print e