Beispiel #1
0
def __get_down_trial_songs(have_down_song_ids, only_trial_song_ids, song_ids):
    req = {
        "ids": [],
        "br": 999000,  # 码率,默认设置了 999000 即最大码率,如果要 320k 则可设置为 320000,其他类推
        "csrf_token": get_csrf()
    }

    split_arrays = ListUtil.list_split(song_ids, 500)

    for sa in split_arrays:
        req["ids"].clear()

        req["ids"].extend(sa)
        data = encrypted_request(req)
        response = get_session().post(playsheet_detail_url + get_csrf(),
                                      data=data,
                                      headers=headers)
        response.encoding = "UTF-8"
        r = response.json()
        details = r.get('data')

        for d in details:
            if d.get("code") == 404:  # 404表示歌曲已经下架
                have_down_song_ids.append(d.get("id"))
            if d.get("code") == -110:  # -110表示歌曲只能试听
                only_trial_song_ids.append(d.get("id"))

        print("休息休息5s...")
        time.sleep(5)
Beispiel #2
0
def __get_list(playlist_sheets):
    req_text = {
        "id": '',
        "offset": 1000,
        "total": True,
        "limit": 1000,
        "n": 1000,
        "csrf_token": csrf
    }

    song_ids = []

    try:
        for playlist_sheet in playlist_sheets:
            req_text['id'] = playlist_sheet

            data = encrypted_request(req_text)

            response = get_session().post(playlist_detail_url + get_csrf(),
                                          data=data,
                                          headers=headers)
            response.encoding = 'UTF-8'
            r = response.json()

            track_ids = r.get('playlist').get('trackIds')
            song_ids.extend(track_id.get('id') for track_id in track_ids)

            print("休息休息5s...")
            time.sleep(5)

        return song_ids
    except Exception as reason:
        print('__get_list方法捕获异常:', reason)
        raise Exception
Beispiel #3
0
def __get_playlist(response):
    user_id = response['account']['id']
    offset = 0
    song_list = set()

    while True:
        # 请求参数
        text = {
            "offset": offset,
            "uid": user_id,
            "limit": 100,
            "csrf_token": get_csrf()
        }

        data = encrypted_request(text)
        try:
            response = get_session().post(playlist_url + get_csrf(),
                                          data=data,
                                          headers=headers)
            response.encoding = 'utf-8'
            r = response.json()

            playlist = r.get("playlist")

            for s in playlist:
                # 在显示的歌单中会包含收藏的歌单,去除掉,一般前面全是自己的歌单,后面的则是收藏歌单
                if s['userId'] == user_id:
                    song_sheet = SongSheet(s['id'], s['name'], s['privacy'])
                    song_list.add(song_sheet)

                    if s['privacy'] == private_playlist_code:
                        private_playlist_sheets.append(song_sheet)
                        private_playlist_sheet_ids.append(s['id'])

                    if s['privacy'] == public_playlist_code:
                        public_playlist_sheets.append(song_sheet)
                        public_playlist_sheet_ids.append(s['id'])

                else:
                    break

            if r.get("more"):
                offset += 100
            else:
                break

            print("休息休息5s...")
            time.sleep(5)

        except Exception as reason:
            print(reason)

    for song_sheet in song_list:
        print(song_sheet)
    print('')
def __get_follows(user_id, offset):
    url = 'https://music.163.com/weapi/user/getfollows/{0}?csrf_token={1}'.format(
        user_id, csrf)
    headers['Referer'] = 'http://music.163.com/user/follows?id={0}'.format(
        user_id)
    req = {'offset': offset, 'limit': limit, 'csrf_token': csrf}
    response = get_session().post(url,
                                  data=encrypted_request(req),
                                  headers=headers)
    response.encoding = 'utf-8'
    return response.json()
def __logout(response):
    req_text = {"csrf_token": csrf}

    data = encrypted_request(req_text)
    response = get_session().post(logout_url, data=data, headers=headers)
    response.encoding = 'UTF-8'
    r = response.json()
    if r.get('code') == 200:
        exit(0)
    else:
        exit(-1)
Beispiel #6
0
def __get_songs_detail(song_ids):
    if len(song_ids) == 0:
        return dict(songs=[])

    req_text = {'ids': song_ids}
    data = encrypted_request(req_text)
    try:
        response = get_session().post(song_detail_url,
                                      data=data,
                                      headers=headers)
        response.encoding = 'UTF-8'
        r = response.json()

        print("休息休息5s...")
        time.sleep(5)

        return r
    except Exception as reason:
        print('__get_songs_detail方法捕获异常:', reason)
        raise Exception
Beispiel #7
0
def __remove_songs(song_sheet_id, song_ids):
    req_text = {'pid': song_sheet_id, 'trackIds': song_ids, 'op': 'del'}

    data = encrypted_request(req_text)
    try:
        response = get_session().post(add_and_remove_song_url_from_sheet,
                                      data=data,
                                      headers=headers)
        response.encoding = 'utf-8'
        r = response.json()

        print("休息休息5s...")
        time.sleep(5)

        if r.get('code') == 200:
            return
        else:
            print()
    except Exception as reason:
        print('__remove_songs方法捕获异常:', reason)
        raise Exception