-
-
Save fushang318/1063524 to your computer and use it in GitHub Desktop.
xiami
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
http://www.xiami.com/song/1769497449 | |
http://www.xiami.com/widget/json-single/uid/0/sid/1769497449 | |
{"location":"5h3%.i%5F%21%643%.tA2x.2615F%594%5mt%FinF96E%2E495Epp2fae2%985519_E53%F1mt323%E277121"} | |
http://f1.xiami.net/23569/169308/01%201769497449_1302051.mp3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "cgi" | |
def rtan(str) | |
CGI::unescape(str) | |
end | |
def sospa(str) | |
totle = str.to_i | |
new_str = str[1..-1] | |
chu = (new_str.length.to_f / totle).floor | |
yu = new_str.length % totle | |
stor = [] | |
i = 0 | |
while i<yu do | |
index = (chu+1)*i | |
length = chu+1 | |
stor[i] = new_str[index...index+length] | |
i+=1 | |
end | |
i = yu | |
while i<totle do | |
index = chu*(i-yu)+(chu+1)*yu | |
length = chu | |
stor[i] = new_str[index...index+length] | |
i+=1 | |
end | |
pin_str = "" | |
0.upto(stor[0].length-1) do |ii| | |
0.upto(stor.length-1) do |jj| | |
pin_str += stor[jj][ii...ii+1] | |
end | |
end | |
pin_str = rtan(pin_str) | |
return_str = "" | |
0.upto(pin_str.length-1) do |iii| | |
if pin_str[iii...iii+1]=='^' | |
return_str<<"0" | |
else | |
return_str<<pin_str[iii...iii+1] | |
end | |
end | |
return_str | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var group = 5; | |
function jiami(s) | |
{ | |
var temp = []; | |
var groupSize,bot; | |
// 把 0 替换成 ^ | |
s.indexOf('0') > -1 ? s = s.split('0').join('^') : void(0); | |
// encodeURI | |
s.indexOf('+') > -1 ? s = encodeURIComponent(s.split('+').join('0')).split('0').join('+') : encodeURIComponent(s); | |
groupSize = Math.floor(s.length / group); | |
bot = s.length % group; | |
for(var i=0;i<groupSize;++i) | |
{ | |
for(var j=0;j<group;++j) | |
{ | |
temp[j] == undefined ? temp[j] = '' : void(0); | |
temp[j] += s.charAt(i*group+j); | |
} | |
} | |
for(var i=0;i<bot;++i) | |
{ | |
temp[i] += s.charAt((groupSize*group+i)); | |
} | |
s = group + temp.join(''); | |
return s; | |
} | |
function jiemi(sourceString) | |
{ | |
var _loc9 = Number(sourceString.charAt(0)); | |
var _loc7 = sourceString.substring(1); | |
var _loc5 = Math.floor(_loc7.length / _loc9); | |
var _loc6 = _loc7.length % _loc9; | |
var _loc2 = new Array(); | |
for (var _loc3 = 0; _loc3 < _loc6; ++_loc3) | |
{ | |
if (_loc2[_loc3] == undefined) | |
{ | |
_loc2[_loc3] = ""; | |
} // end if | |
_loc2[_loc3] = _loc7.substr((_loc5 + 1) * _loc3, _loc5 + 1); | |
} // end of for | |
for (var _loc3 = _loc6; _loc3 < _loc9; ++_loc3) | |
{ | |
_loc2[_loc3] = _loc7.substr(_loc5 * (_loc3 - _loc6) + (_loc5 + 1) * _loc6, _loc5); | |
} // end of for | |
var _loc4 = ""; | |
for (var _loc3 = 0; _loc3 < _loc2[0].length; ++_loc3) | |
{ | |
for (var _loc1 = 0; _loc1 < _loc2.length; ++_loc1) | |
{ | |
_loc4 = _loc4 + _loc2[_loc1].charAt(_loc3); | |
} // end of for | |
} // end of for | |
_loc4 = unescape(_loc4); | |
var _loc8 = ""; | |
for (var _loc3 = 0; _loc3 < _loc4.length; ++_loc3) | |
{ | |
if (_loc4.charAt(_loc3) == "^") | |
{ | |
_loc8 = _loc8 + "0"; | |
continue; | |
} // end if | |
_loc8 = _loc8 + _loc4.charAt(_loc3); | |
} // end of for //trans ^ to 0 | |
return (_loc8); | |
} | |
function test() | |
{ | |
var $=document, | |
$$='getElementById', | |
testurl = $[$$]('url').value, | |
encode = jiami(testurl), | |
decode = jiemi(encode); | |
alert('URL明文为:'+testurl+'\n' | |
+'加 密后为:'+encode+'\n' | |
+'解 密后为:'+decode); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var song_id='1769497449'; | |
function rtan(str){ | |
var ret=""; | |
for(var i=0;i<str.length;i++){ | |
var chr = str.charAt(i); | |
if(chr == "+"){ | |
ret+=" "; | |
}else if(chr=="%"){ | |
var asc = str.substring(i+1,i+3); | |
if(parseInt("0x"+asc)>0x7f){ | |
ret+=String.fromCharCode(parseInt("0x"+asc+str.substring(i+4,i+6))); | |
i+=5; | |
}else{ | |
ret+=String.fromCharCode(parseInt("0x"+asc)); | |
i+=2; | |
} | |
}else{ | |
ret+= chr; | |
} | |
} | |
return ret; | |
} | |
function sospa(str) | |
{ | |
var totle = parseInt(str); | |
var newString = str.substr(1); | |
var chu = Math.floor(newString.length / totle); | |
var yu = newString.length % totle; | |
var stor = new Array(); | |
var i; | |
for(i = 0;i<yu;i++) | |
{ | |
stor[i] = newString.substr((chu+1)*i,chu+1); | |
} | |
for(i=yu;i<totle;i++) | |
{ | |
stor[i] = newString.substr(chu*(i-yu)+(chu+1)*yu,chu); | |
} | |
var pinString = ''; | |
for(i=0;i<stor[0].length;i++) | |
{ | |
for(j=0;j<stor.length;j++) | |
{ | |
pinString += stor[j].substr(i,1); | |
} | |
} | |
pinString = rtan(pinString); | |
var returnString = ''; | |
for(i=0;i<pinString.length;i++) | |
{ | |
if(pinString.substr(i,1)=='^') | |
{ | |
returnString += "0"; | |
} else { | |
returnString += pinString.substr(i,1); | |
} | |
} | |
return returnString; | |
} | |
var addEvent = (function () { | |
if (document.addEventListener) { | |
return function (el, type, fn) { | |
if (el && el.nodeName || el === window) { | |
el.addEventListener(type, fn, false); | |
} else if (el && el.length) { | |
for (var i = 0; i < el.length; i++) { | |
addEvent(el[i], type, fn); | |
} | |
} | |
}; | |
} else { | |
return function (el, type, fn) { | |
if (el && el.nodeName || el === window) { | |
el.attachEvent('on' + type, function () { | |
return fn.call(el, window.event); | |
}); | |
} else if (el && el.length) { | |
for (var i = 0; i < el.length; i++) { | |
addEvent(el[i], type, fn); | |
} | |
} | |
}; | |
} | |
})(), | |
togglePlayClick = function() { | |
if(audio.paused){ | |
audio.play(); | |
}else { | |
audio.pause(); | |
} | |
}; | |
var audio = document.querySelector('#audio'), | |
togglePlay = document.querySelector('#buttonPlay'), | |
duration = document.querySelector('#duration'); | |
$(document).ready(function() { | |
var Song = new Array(); | |
$.getJSON("/widget/json-single/uid/0/sid/"+song_id,function(data) { | |
Song = { | |
location:data.location | |
}; | |
if(Song.location) { | |
$(togglePlay).attr('class','play'); | |
$(audio).attr("src",sospa(Song.location)); | |
audio.load(); | |
addEvent(togglePlay,'touchstart',function() { | |
togglePlayClick(); | |
}); | |
addEvent(audio, 'play', function () { | |
audio.play(); | |
$(togglePlay).attr('class','pause'); | |
togglePlay.innerHTML = '暂停'; | |
}); | |
addEvent(audio,'pause',function() { | |
audio.pause(); | |
$(togglePlay).attr('class','play'); | |
togglePlay.innerHTML = '播放'; | |
}); | |
// addEvent(audio,'canplay',function() {$(togglePlay).attr('class','play');}); | |
addEvent(audio,'timeupdate',function() { | |
var p = this.currentTime / this.duration; | |
duration.style.width = p*100+'%'; | |
}); | |
addEvent(audio,'ended',function(){ | |
audio.pause(); | |
audio.currentTime=0; | |
$(togglePlay).attr('class','play'); | |
}); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment