跳转至

mv

MV 相关 API

MV

MV(vid: str)

MV 类

ATTRIBUTE DESCRIPTION
vid

mv id

初始化 MV 类

PARAMETER DESCRIPTION
vid

视频 id

TYPE: str

Source code in qqmusic_api/mv.py
def __init__(self, vid: str):
    """初始化 MV 类

    Args:
        vid: 视频 id
    """
    self.vid = vid

get_detail async

get_detail() -> dict

获取 MV 详细信息

RETURNS DESCRIPTION
dict

视频信息

Source code in qqmusic_api/mv.py
async def get_detail(self) -> dict:
    """获取 MV 详细信息

    Returns:
        视频信息
    """
    param = {
        "vidlist": [self.vid],
        "required": [
            "vid",
            "type",
            "sid",
            "cover_pic",
            "duration",
            "singers",
            "video_switch",
            "msg",
            "name",
            "desc",
            "playcnt",
            "pubdate",
            "isfav",
            "gmid",
            "uploader_headurl",
            "uploader_nick",
            "uploader_encuin",
            "uploader_uin",
            "uploader_hasfollow",
            "uploader_follower_num",
            "uploader_hasfollow",
        ],
    }
    return (await Api(**API["detail"]).update_params(**param).result)[self.vid]
get_related_song() -> list[dict]

获取 MV 相关歌曲

RETURNS DESCRIPTION
list[dict]

歌曲基本信息

Source code in qqmusic_api/mv.py
async def get_related_song(self) -> list[dict]:
    """获取 MV 相关歌曲

    Returns:
        歌曲基本信息
    """
    param = {
        "vidlist": [self.vid],
        "required": ["related_songs"],
    }
    song_id = (await Api(**API["detail"]).update_params(**param).result)[self.vid]["related_songs"]
    return await query_song(song_id)

get_url async

get_url() -> dict

获取 MV 播放链接

RETURNS DESCRIPTION
dict

视频播放链接

Source code in qqmusic_api/mv.py
async def get_url(self) -> dict:
    """获取 MV 播放链接

    Returns:
        视频播放链接
    """
    return (await get_mv_urls([self.vid]))[self.vid]

get_mv_urls async

get_mv_urls(vid: list[str]) -> dict

获取 MV 播放链接

PARAMETER DESCRIPTION
vid

视频 vid 列表

TYPE: list[str]

RETURNS DESCRIPTION
dict

视频播放链接

Source code in qqmusic_api/mv.py
async def get_mv_urls(vid: list[str]) -> dict:
    """获取 MV 播放链接

    Args:
        vid: 视频 vid 列表

    Returns:
        视频播放链接
    """
    param = {
        "vids": vid,
        "request_type": 10003,
        "guid": get_guid(),
        "videoformat": 1,
        "format": 265,
        "dolby": 1,
        "use_new_domain": 1,
        "use_ipv6": 1,
    }
    result = await Api(**API["url"]).update_params(**param).result
    urls: dict[str, dict] = {}

    def get_play_urls(data):
        play_urls = {}
        for url_info in data:
            if url_info["freeflow_url"]:
                play_url = random.choice(url_info["freeflow_url"])
                play_urls[url_info["filetype"]] = play_url
        return play_urls

    for _, data in result.items():
        urls[_] = {}
        urls[_]["mp4"] = get_play_urls(data["mp4"])
        urls[_]["hls"] = get_play_urls(data["hls"])

    return urls