y.qq.com-php获取QQ音乐外链源码

作者:matrix 发布时间:2015 年 5 月 18 日 分类:零零星星

QQ音乐
MP3接口

http://tsmusic24.tc.qq.com/{音乐ID}.mp3
http:/ /stream.qqmusic.tc.qq.com/{音乐ID}.mp3
http:/ /stream{1-30都可以}.qqmusic.qq.com/{音乐ID}.mp3
http://tsmusic128.tc.qq.com/{音乐ID+30000000}.mp3 (请计算出结果)
QQ音乐高品质ogg
http://tsmusic128.tc.qq.com/{音乐ID+40000000}.ogg (请计算出结果)

M4A接口

http://tsmusic24.tc.qq.com/{音乐ID}.m4a
http://thirdparty.gtimg.com/{音乐ID}.m4a?fromtag=38
http://thirdparty.gtimg.com/C100{音乐MID}.m4a?fromtag=38
http://cc.stream.qqmusic.qq.com/C200{音乐MID}.m4a?vkey={VKEY的值}&guid=1830679348

过程

示例获取单曲页面的MP3或M4A文件链接
http://y.QQ.com/#type=song&mid=002G0sJY2wThyx
其中的002G0sJY2wThyx就是歌曲的mid
打开上面的URl浏览器会加载iframe框架http://s.plcloud.music.QQ.com/fcgi-bin/fcg_yqq_song_detail_info.fcg?songmid=002G0sJY2wThyx
Ctrl +U查看源码

var g_SongData = { id: 7168586, songmid: '002G0sJY2wThyx', songname: '喜欢你', singer:'G.E.M. 邓紫棋', singerid:13948,singermid:'001fNHEf1SFEFN',albumname:'喜欢你', albumid:654246,albummid:'000cFPKx3ZGzks', status:31, fnote:0};/*status:非0(true)表示正常歌曲,0(false)表示下架歌曲或者歌曲不存在*/

说明:其中的7168586就是对应歌曲的id,而002G0sJY2wThyx是歌曲的mid,每首歌曲的信息都不同,这需要使用正则匹配数据

php代码:

<?php
$u = $_GET['u'];
$type = $_GET['t']?$_GET['t']:'mp3';
$con = 'http://s.plcloud.music.qq.com/fcgi-bin/fcg_yqq_song_detail_info.fcg?songmid='.$u;
preg_match('|var g_SongData = ({.*});|',file_get_contents($con),$data);
$obj = json_decode(format_ErrorJson(iconv('GBK', 'UTF-8', $data[1])));
$id = $obj->id;
//$mid = $obj->songmid;
$url = 'http://tsmusic24.tc.qq.com/'.$id.'.'.$type;
header('Location: '.$url);
function format_ErrorJson($data)
{
    $con = str_replace('\'','"',$data);//替换单引号为双引号
    $con = preg_replace('/(\w+):[ {]?((?<YinHao>"?).*?\k<YinHao>[,}]?)/is', '"$1": $2',$con );//若键名没有双引号则添加
    return $con;
}

说明:
上面代码只是用了MP3和M4A的第一种接口
代码保存为php文件,调用/xxx.php?u=音乐ID&t=格式
例如001yJypt4E8GW0歌曲的m4a地址
/xxx.php?u=001yJypt4E8GW0&t=m4a
阅读剩余部分 »