最强大的高音质音乐搜索接口

  • 内容
  • 相关

懂写代理的可以写个代理玩玩,我就不写了。多品质,速度快

index.html->

<!doctype html>    
<html>    
<head>    
<meta charset="utf-8" />    
<title>鬼少高音质音乐盒</title>    
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0,user-scalable=no" />    
<meta name="mobileOptimized" content="240" />    
<meta name="format-detection" content="telephone=no" />    
<meta name="apple-touch-fullscreen" content="YES" />    
<meta name="apple-mobile-web-app-capable" content="yes"/>    
<style type="text/css">    
/* reset */    
*{ margin: 0; padding: 0; }    
ul,ol,li{ list-style:none;}    
.clearfix { *zoom:1;}    
a, a:visited { text-decoration: none; }    
:focus{outline:none;}    
.clearfix:after { content: ''; display: block; height: 0; clear: both;}    
.text-overflow { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }    
body{margin:0 auto;width:800px;min-width:320px;font:14px/2em "宋体" "微软雅黑" ;background:#f7f7f7;color:#838383;-webkit-user-select:none;-webkit-text-size-adjust:none;}    
#footer{text-align:center;}    
/*topBar*/    
.topBar{display:-webkit-box;height:45px;position: relative;border-bottom:1px solid #e3e3e3;background:#f5f6f8;}    
.search{-webkit-box-flex:1; text-align:left;margin:5px;}    
.search div{max-width:100%;margin: 0 auto;border:1px solid #b9bdbe;border-radius: 3px;text-align: left;background: white;height: 34px;padding-right:72px;}    
.search .searchText{float:left;display:block;width:100%;border:none;text-indent:5px;padding:9px 0;color:#080808;}    
.search .searchSubmit{float:right;width:70px;height:30px;line-height:30px;margin:2px -70px 0 0;text-align:center; letter-spacing:1px;color:#fff;background:#9b9b9b;cursor:pointer;}    
/* list */    
.listArea{}    
.listArea li{display:-webkit-box;height:55px;padding:0 12px 0 5px;border-bottom:1px solid #d6d6d6;}    
.listArea .rank{width: 36px;height: 25px;line-height: 25px;margin:5px 0 0;text-align: center;font-weight: bold;}    
.listArea .rank01{color:#b9764b;}    
.listArea .rank02{color:#d9ba6a;}    
.listArea .rank03{color:#739115;}    
.listArea .details{-webkit-box-flex:1;overflow: hidden;}    
.listArea .songName{height:25px;margin-top:3px;font-weight:normal;font-size:14px;white-space: nowrap;overflow: hidden;text-overflow: ellipsis;color:#080808;}    
.listArea .singerName{height:25px;line-height:25px;font-size:12px;}    
.listArea .heartNum {margin-left: 8px;color: #FF4200;font-size: 12px;padding-left: 14px;}    
.listArea .btnDown{display:block;width:24px;overflow: hidden;background:url(http://so.bq.yymommy.com/appsearch/styles/images/iconDown.png) no-repeat center center;cursor:pointer;}    
.listArea .Playing{display:block;margin-top:20px;height:30px;width:30px;overflow: hidden;background-position: 28px 20px;background:url(http://asset.dongting.com/app/fm/styles/images/icon.png) no-repeat ;cursor:pointer;}    
/*弹层下载*/    
.downLayer{width:280px;height:auto;position:fixed;left:50%;top:50px;margin-left:-140px;box-shadow:0 0 15px #888;overflow:hidden;}    
.downLayer .tit{height:37px;line-height:38px;text-indent:15px;font-weight:normal;font-size:18px;color:#fff;background:#888;}    
.downLayer .downList{padding:0 5px;background:#fff;}    
.downLayer .downList a{display:block;height:54px;line-height:54px;border-bottom:1px solid #9e9e9e;font-size:16px;color:#5a5a5a;}    
.downLayer .downList a:nth-last-child(1){border-bottom:none;}    
.downLayer .downList .icon{float:left;width:14px;height:16px;margin:19px 7px 0 2px;background:url( http://so.bq.yymommy.com/appsearch/styles/images/iconDown.png) no-repeat 0 0;background-size:14px 16px;}    
#tipText{text-align:center;margin-top:30px;display:none;}    
#maskLayer{display:none;position:fixed;top:0;right:0;bottom:0;left:0;background:rgba(0,0,0,0.66);}    
</style>    
</head>    
	<body>    
<noscript>    
<div id="noScript">你的浏览器不支持或者禁用JavaScript功能。 </div>    
</noscript>    
<div id="page">     
<!--页头-->    
<header id="header">    
<div class="topBar">    
<!--搜索-->    
<section class="search" id="searchBar">    
<div>    
<input type="text" id="searchValue" class="searchText" maxlength="64" placeholder="请输入歌曲名、歌手名">    
<p id="searchBtn" class="searchSubmit">鬼少搜索</p>    
</div>    
</section>    
<!--/搜索-->     
</div>    
   	</header>    
<!--/页头-->     
<!--页中-->    
<div id="content">    
   	</div>    
<div id="tipText">您还没有搜索!</div>    
<!--/页中-->     
<!--页尾 -->    
<footer id="footer"></footer>    
<!--/页尾 -->     
<!-- 弹层下载 -->    
<div id="maskLayer"></div>    
<div id="downLayer">    
</div>    
<!-- 弹层下载 -->    
</div>    
<script>    
(function(){    
	//初始化变量    
	var _jsonPID = 1,    
		page = 1,    
		searchValue = '',    
		songIdStr = "",    
		_isShowDownload = false,    
		_isBoole = false,    
		_songList = {},    
		os = getOS(),    
		_clickEventType = 'click';    
		_tmpl = {    
			list : '<li>\    
						<figure class="rank rank{rank}">{rank}</figure>\    
						<div class="details">\    
							<h6 class="songName">{song_name}</h6>\    
							<p class="singerName">{singer_name}</p>\    
						</div>\    
						<a class="Playing" href="/?id={song_id}" target="_blank"></a>\    
						<span class="btnDown" onclick="Ttpod.download({song_id});"></span>\    
              		</li>',    
			layer : '<a href="{url}"><span class="icon"></span><span class="text">{type_description}{size} ({format} {bitrate}kbps)</span></a>'    
		};    
	//获取id的DOM    
	function $(id){    
		return document.getElementById(id);    
	};    
	//跨域请求数据    
	function jsonP(options) {    
		var head = document.getElementsByTagName("head")[0] || document.documentElement,    
			callbackName = options.callbackName || 'jsonp_callback' + (++_jsonPID),    
			abortTimeout = "",    
			context,    
			script = document.createElement("script"),    
			abort = function() {    
				head.removeChild(script);    
				if (window[callbackName])    
					window[callbackName] = empty;    
			};    
		script.src = options.url.replace(/=\?/, '=' + callbackName);    
		window[callbackName] = function(data) {    
			clearTimeout(abortTimeout);    
			head.removeChild(script);    
			delete window[callbackName];    
			options.success.call(context, data);    
		};    
		if(options.error)    
		{    
		script.onerror = function(){    
			clearTimeout(abortTimeout);    
			options.error.call(context, "", 'error');    
		}    
		}    
		head.appendChild(script);    
		if (options.timeout > 0)    
			abortTimeout = setTimeout(function() {    
				options.error.call(context, "", 'timeout');    
			}, options.timeout);    
		return {};    
	}    
	function _getArg(key,url) {	    
		return (url.match(new RegExp("(?:\\?|#|&)" + key + "=(.*?)(?=&|$)")) || ['', ''])[1];    
	}    
	/**    
	* CRC加密    
	* @param  lrcid+title+artist    
	*/    
	function CRC32(str){    
		str=encodeURIComponent(str);    
		var Crc32Table=new Array(256);    
		var i,j;    
		var Crc;    
		for(i=0; i<256; i++)    
		{    
			Crc=i;    
			for(j=0; j<8; j++)    
			{    
				if(Crc & 1)    
					Crc=((Crc >> 1)& 0x7FFFFFFF) ^ 0xEDB88320;    
				else    
					Crc=((Crc >> 1)& 0x7FFFFFFF);    
			}    
			Crc32Table[i]=Crc;    
		}    
		if (typeof str != "string") str = "" + str;    
		Crc=0xFFFFFFFF;    
		for(i=0; i<str.length; i++)    
			Crc=((Crc >> 8)&0x00FFFFFF) ^ Crc32Table[(Crc & 0xFF)^ str.charCodeAt(i)];    
		Crc ^=0xFFFFFFFF;    
		return (Crc >> 3).toString(16);    
	}    
	//格式化字符串{}    
	function formatByVal(str,params,isEncode){    
		if(typeof params == "object"){    
			for(var key in params){    
				if(params[key]==undefined || params[key]==null  || params[key]=="undefined" || params[key]=="null") {    
					params[key] = "";    
				}    
				str = str.replace(new RegExp("\\{" + key + "\\}", "ig"), isEncode ? encodeURIComponent(params[key]) : params[key]);    
			}    
		}			    
		return str.replace(/\{\w*\}/ig, "");    
	}    
	//系统的判断    
	function getOS() {    
		var os={},userAgent=navigator.userAgent,type="";    
		os.webkit = userAgent.match(/WebKit\/([\d.]+)/) ? true : false;    
		os.android = userAgent.match(/(Android)\s+([\d.]+)/) || userAgent.match(/Silk-Accelerated/) ? true : false;    
		os.ipad = userAgent.match(/(iPad).*OS\s([\d_]+)/) ? true : false;    
		os.iphone = !os.ipad && userAgent.match(/(iPhone\sOS)\s([\d_]+)/) ? true : false;    
		os.webos = userAgent.match(/(webOS|hpwOS)[\s\/]([\d.]+)/) ? true : false;    
		os.touchpad = os.webos && userAgent.match(/TouchPad/) ? true : false;    
		os.ios = os.ipad || os.iphone;    
		os.blackberry = userAgent.match(/BlackBerry/) || userAgent.match(/PlayBook/) ? true : false;    
		os.opera = userAgent.match(/Opera Mobi/) ? true : false;    
		os.fennec = userAgent.match(/fennec/i) ? true : false;    
		os.desktop = !(os.ios ||os.android ||os.blackberry ||os.opera ||os.fennec);    
		return os;    
}    
	//初始化搜索词    
	function _initSearch(){    
		var q = _getArg("q",location.hash) || _getArg("q",location.search);    
		$("searchValue").value = decodeURIComponent(q);    
		searchValue = $("searchValue").value.replace(/^\s+|\s+$/g, "");    
		if(searchValue==''){    
			$("tipText").style.display = "block";    
			$("searchValue").focus();    
		}else{    
			_getList();    
		}    
	}    
	//初始化列表    
	function _getList(bool){    
		var _actions = 'http://so.bq.yymommy.com/songs/search?q={q}'+'&page='+page+'&size=20&callback=?';    
		if(bool){    
			var newSearchValue = $("searchValue").value.replace(/^\s+|\s+$/g, "");    
			if(searchValue==newSearchValue || newSearchValue==""){    
				window.removeEventListener('scroll',_scrollEvent,false);    
				$("tipText").innerHTML = "您的搜索内容为空或重复!";	    
				$("tipText").style.display = "block";    
				return $("searchValue").focus();    
			}else{    
				searchValue=newSearchValue;    
				page = 1;    
			}    
		}    
		jsonP({    
			url : formatByVal(_actions,{q:searchValue}),    
			timeout : 10*1000,    
			callbackName : "jsonp_search",    
			success : function(result){    
				$("tipText").style.display = "none";    
				if(result.allPage < page){    
					$("footer").innerHTML = "数据加载完了!";    
					return;    
				}    
				if(result.allPage==0){    
					$("tipText").innerHTML = "没有搜索到相关歌曲!";	    
					$("tipText").style.display = "block";    
					$("content").innerHTML = "";    
					return;    
				}    
				var data = result.data;    
				//输出列表模板    
				var listHtml = '';    
				for(var i=0; i<data.length; i++){    
					_songList[data[i].song_id] = data[i];    
					var s = (page-1)*20+i;    
					if(s<9){    
						data[i].rank = '0'+(s+1);    
					}else{    
						data[i].rank = (s+1);    
					}	    
					listHtml += formatByVal(_tmpl.list,data[i]);						    
				}    
				if(bool){    
					$("content").innerHTML = "";    
				}    
				var newnode=document.createElement('ul');    
				newnode.setAttribute('class','listArea');    
				$("content").appendChild(newnode);    
				newnode.innerHTML = listHtml;    
				page++;    
				window.addEventListener('scroll',_scrollEvent,false);    
			}    
		});    
	}    
	//滚动加载    
	function _scrollEvent(){    
		if((window.innerHeight+window.scrollY) >= document.body.scrollHeight-5){    
			_getList();    
			$("footer").innerHTML = "加载中···";    
		}    
	};    
	//点击搜索    
	function _searchSong(){    
			_getList(true);    
	};    
	//按回车键搜索    
	function _enterSearch(){    
		var e = window.event;    
		if(e.keyCode==13){    
			_getList(true);    
		}    
	}    
	//点击下载按钮-列表    
	function _downBtn(songId){    
		_isBoole = false;    
		if(songId == songIdStr){    
			_showDown();    
			return;    
		}    
		songIdStr = songId;    
		if(_songList[songId]){    
			_renderDown(_songList[songId]);    
			//return;    
		}    
		if(_isBoole){    
			var codeId = CRC32(songId);    
			jsonP({    
				url:"http://so.bq.yymommy.com/website/ting?song_id="+songId+"&code="+codeId+"&from=search&callback=?",    
				timeout:10*1000,    
				callbackName:'jsonp_download',    
				success:function(result){    
					if(result.code==1){    
						var data = result.data[0];    
						_renderDown(data);    
					}    
				}    
			});    
		}    
	}    
	function _renderDown(data){    
			var layerHtml = '<div class="downLayer"><h3 class="tit">'+data.song_name+'</h3><p class="downList">',    
			tagHtml = '',    
			singerName = data.singer_name,    
			songName = data.song_name,    
			obj = data.url_list;    
			if(obj === undefined){    
				_isBoole = true;    
			}else if(obj == null){    
				layerHtml = layerHtml + '此歌曲没有资源!' + '</p></div>';    
				$("downLayer").innerHTML = layerHtml;    
				_showDown();    
			}else{    
				for(var i=0; i<obj.length; i++){    
					if(os.ios){    
						obj[i].url = obj[i].url+'&n='+encodeURIComponent(singerName+'-'+songName)+'.'+obj[i].format;    
					}    
					tagHtml += formatByVal(_tmpl.layer,obj[i]);    
				}    
				layerHtml = layerHtml + tagHtml + '</p></div>';    
				$("downLayer").innerHTML = layerHtml;    
				_showDown();    
			}    
	}    
	function _showDown(){		    
		_isShowDownload = false;    
		$("maskLayer").style.display = "block";    
		$("downLayer").style.display = "block";		    
		setTimeout(function(){    
			_isShowDownload = true;    
		},100);    
	}    
	function _bodyEvent(){    
		if(_isShowDownload){    
			$("downLayer").style.display = "none";    
			$("maskLayer").style.display = "none";    
			_isShowDownload = false;    
		}    
	}    
	//初始化方法    
	function init(){    
		_initSearch();    
		$("searchBtn").addEventListener(_clickEventType,_searchSong,false);			    
		document.addEventListener(_clickEventType,_bodyEvent,false);	    
		window.addEventListener('keydown',_enterSearch,false);    
		$("maskLayer").addEventListener(_clickEventType,function(){this.style.display = "none";$("downLayer").style.display = "none";},false);		    
	};    
	Ttpod = {    
		download : _downBtn    
	};    
	init();    
}());    
</script>    
</body>    
</html>

请各位低调使用,失效不再更新。

本文标签:

版权声明:若无特殊注明,本文皆为《鬼少》原创,转载请保留文章出处。

本文链接:最强大的高音质音乐搜索接口 - http://tv1314.com/post-103.html

发表评论

电子邮件地址不会被公开。 必填项已用*标注

00:00 / 00:00
顺序播放