API References

nemcore.api

网易云音乐的核心 HTTP API 客户端模块

class nemcore.api.NetEaseApi(*, cookie_path=None, cache_path=None, cache_ttl=300, cache_size=100, logger=None)

网易云音乐api客户端

Parameters:
  • cookie_path – 本地保存路径。如果不设置,则不会持久化。
  • cache_path – 网络请求的本地缓存路径,如果不设置,则只在内存缓存。
  • cache_ttl – 请求缓存的保留时间。
  • logger – 日志记录器。
clear_cache()

清除请求缓存

daily_task(is_mobile: bool = True)

每日签到

Parameters:is_mobile – 是否是手机签到
Returns:正常返回字典{point,code},错误抛出异常
fm_like(songid: int, like: bool = True, time: int = 25, alg: str = 'itembased') → nemcore.types.fm_like_resp.FMLikeResp

私人FM操作:喜欢

Parameters:
  • songid – 歌曲id
  • like – 喜欢或不喜欢
  • time – 未知
  • alg – 未知。fm推荐算法类型?
fm_trash(songid: int, time: int = 25, alg: str = 'RT') → nemcore.types.fm_trash_resp.FMTrashResp

私人FM操作:不喜欢

NOTE: 这个API可能影响云音乐今后的日推和FM结果。 :param songid: 歌曲id :param time: 未知 :param alg: 未知

get_album_info(album_id: int) → nemcore.types.get_album_info_resp.GetAlbumInfoResp

获取专辑信息

Parameters:album_id – 专辑ID
get_artist_albums(artist_id: int, offset: int = 0, limit: int = 50) → nemcore.types.get_artist_albums_resp.GetArtistAlbumsResp

获取歌手专辑

Parameters:
  • artist_id – 歌手ID
  • offset – 结果偏移,和Limit结合做分页
  • limit – 结果集大小,和offset结合做分页
get_artist_info(artist_id: int) → nemcore.types.get_artist_info_resp.GetArtistInfoResp

获取歌手信息

包括热门单曲等。

Parameters:artist_id – 歌手ID
get_dj_channels(offset: int = 0, limit: int = 50) → nemcore.types.get_dj_channels_resp.GetDjChannelsResp

热门主播电台

今日最热(0), 本周最热(10),历史最热(20),最新节目(30)

对应[首页>>发现音乐>>主播电台](https://music.163.com/#/discover/djradio)

Parameters:
  • offset – 分页选项,偏移值
  • limit – 分页选项,一次获取的项目数限制。
get_dj_programs(radio_id: int, asc: bool = False, offset: int = 0, limit: int = 50) → nemcore.types.get_dj_programs_resp.GetDjProgramsResp

获取电台频道信息

Parameters:
  • radio_id – id
  • asc – 按升序排序, defaults to False
  • offset – 分页选项,偏移值, defaults to 0
  • limit – 分页选项,一次获取的项目数限制, defaults to 50
Returns:

电台信息

get_new_albums(offset: int = 0, limit: int = 50) → nemcore.types.new_album_resp.GetNewAlbumsResp

新碟上架

Parameters:
  • offset – 结果偏移,和limit结合做分页
  • limit – 结果集大小,和offset结合做分页
get_personal_fm() → nemcore.types.get_personal_fm_resp.GetPersonalFMResp

私人FM

get_playlist_detail(playlist_id: int, offset=0, limit=100) → nemcore.types.get_playlist_detail_resp.GetPlaylistDetailResp

歌单详情

Parameters:
  • limit – 用于分页
  • offset – 用于分页
  • playlist_id – 歌单ID
get_recommend_resource() → nemcore.types.get_recommend_resource_resp.GetRecommendResourceResp

获得日推歌单列表。

注意,这个不是日推。

日推请转到 nemcore.api.NetEaseApi.get_recommend_songs()

get_recommend_songs(total: bool = True, offset: int = 0, limit: int = 20) → nemcore.types.get_recommend_songs_resp.GetRecommendSongsResp

获得每日推荐歌曲

Parameters:
  • total – 未知。是否一次获取全部?
  • offset – 分页选项,偏移值。
  • limit – 分页选项,一次获取的项目数限制。
Returns:

返回今日推荐歌曲清单

get_song_comments(music_id: int, total: bool = False, offset: int = 0, limit: int = 100) → nemcore.types.get_song_comments_resp.GetSongCommentsResp

获取歌曲评论

Parameters:
  • music_id – 歌曲ID
  • offset – 结果偏移,和Limit结合做分页
  • total – TODO
  • limit – 结果集大小,和offset结合做分页
get_song_lyric(music_id: int) → nemcore.types.get_song_lyric_resp.GetSongLyricResp

获取歌词

ApiEndpoint: http://music.163.com/api/song/lyric?os=osx&id= &lv=-1&kv=-1&tv=-1

Parameters:music_id – 歌曲ID
get_songs_detail(ids: Sequence[int]) → nemcore.types.get_song_detail_resp.GetSongDetailResp

获取歌曲详情

Parameters:ids – 歌曲ID列表
get_songs_url(ids: Union[Sequence[int], int], quality: int) → nemcore.types.get_song_url_resp.GetSongURLResp

获取歌曲播放url

Parameters:
  • ids – 单个或多个歌曲 id
  • quality – 音质档次,可选值0-2,分别对应 320kbps,192kbps,128kbps 三种质量
get_top_artists(offset: int = 0, limit: int = 100) → nemcore.types.get_top_artists_resp.GetTopArtistsResp

热门歌手

对应[首页>>发现音乐>>歌手](https://music.163.com/#/discover/artist/)

Parameters:
  • offset – 结果偏移,和Limit结合做分页
  • limit – 结果集大小,和offset结合做分页
get_top_playlists(category: str = '全部', order: str = 'hot', offset: int = 0, limit: int = 50) → nemcore.types.get_top_playlists_resp.GetTopPlaylistsResp

歌单(网友精选碟)

对应[首页>>发现音乐>>歌单](http://music.163.com/#/discover/playlist/)

Parameters:
  • category – 歌单分类
  • order – 排序方法,可选值 TODO
  • offset – 结果偏移,和Limit结合做分页
  • limit – 结果集大小,和offset结合做分页
get_top_songs(idx: int = 0, offset: int = 0, limit: int = 100) → nemcore.types.get_playlist_detail_resp.GetPlaylistDetailResp

热门单曲榜

对应[首页>>发现音乐>>排行榜](https://music.163.com/#/discover/toplist?id=3779629)

Parameters:
  • idx – 榜单ID,参考 netease.TOP_LIST_ALL
  • offset – 结果偏移,和Limit结合做分页
  • limit – 结果集大小,和offset结合做分页
get_user_playlist(uid=None, offset=0, limit=50) → nemcore.types.get_user_playlist_resp.GetUserPlaylistResp

查看用户歌单

Parameters:
  • uid – 用户ID,不传递时指自己的歌单
  • offset – 分页选项,偏移值。
  • limit – 分页选项,一次获取的项目数限制。
Returns:

正常返回字典

login(username: str, password: str, country_code: str = '86') → nemcore.types.login_resp.LoginResp

登录网易云音乐账号

支持邮箱登录和手机号码登录,返回登录结果。

Parameters:
  • username – 用户名,如果是纯数字字符串,自动使用手机号码登录接口
  • password – 密码
  • country_code – 国家码
Returns:

正常返回字典,否则抛出异常

login_if_need(username: str, password: str, country_code: str = '86') → Union[nemcore.types.login_resp.LoginResp, nemcore.types.get_user_account_resp.GetUserAccountResp]

需要时登录

如果已经登录,相当于调用 get_user_account。

如果未登录,相当于调用 login

Parameters:
  • username – 邮箱或者手机号
  • password – 密码
  • country_code – 国家码
Return type:

Union[LoginResp, GetUserAccountResp]

login_refresh()

刷新登录状态

Returns:不返回
logout()

登出

清除所有cookie和storage里的用户信息

search(keywords: str, stype: int = 1, total: bool = True, offset: int = 0, limit: int = 50) → nemcore.types.search_resp.SearchResp

搜索歌曲

Parameters:
  • keywords – 搜索关键词
  • stype – 搜索类型,可选值:单曲(1),歌手(100),专辑(10),歌单(1000),用户(1002) (type)
  • total – TODO
  • offset – 搜索结果偏移,和limit结合做分页
  • limit – 搜索结果集大小,和ofset结合做分页

nemcore.exceptions

exception nemcore.exceptions.NetEaseError(code, message=None, data=None, url=None, method=None, payload=None)