forked from justan/gmscrobber
-
Notifications
You must be signed in to change notification settings - Fork 0
/
simple_scrobbler_user.js
653 lines (611 loc) · 23 KB
/
simple_scrobbler_user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
var log = function(){},GM_log,////unsafeWindow.console.log,//
getVal = GM_getValue,
setVal = GM_setValue,
delVal = GM_deleteValue,
xhr = GM_xmlhttpRequest,
rmc = GM_registerMenuCommand,
_md5 = hex_md5;
//simple scrobbler for userscript
var Scrobbler = function(){
var apikey = "4472aff22b680a870bfd583f99644a03",
secret = "cbc5528721f63b839720633d7c1258d2",
apiurl = "http://ws.audioscrobbler.com/2.0/",
scrate = .9,
tokenreg = /[?&]token=(\w{32})/,
_timer, _shift;
/**
* Scrobbler
* @constructor
* @param {Object} info 该页面 scrobbler 信息
* @param {Number} info.type 1: 手动调用scrobble记录歌曲;
0(缺省): 在调用 nowplaying 后根据播放时间自动调用 scrobble 记录歌曲
* @param {String} info.name 该 scrobbler 名字, 会显示在 greasemonkey 菜单中
* @param {Function} info.ready 回调. scrobbler sessionid 取得后会调用此函数.
* @param {Number} [info.scrate] 自动记录的百分比, info.type == 1 时无效
*/
var fn = function(info){
this.type = info.type;
this.name = info.name || "";
this.ready = info.ready || function(){};
this.scrate = info.scrate || scrate;
this.init();
};
fn.prototype = {
init: function(){
var sk = getVal("session"),
token = document.location.search.match(tokenreg),
that = this;
token = token && token[1];
log(sk + "\n" + token + "\n" + document.location.href);
if(sk){
rmc("停止记录" + that.name, that.delSession);
that.username = sk.split("/")[0];
that.sk = sk.split("/")[1];
setTimeout(function(){that.ready()}, 0);
}else if(token){
that.sk = "wait";
that.ajax({method:"auth.getSession", _sig:"", token: token},
function(d){
log(JSON.stringify(d))
if(d.session && d.session.key){
that.sk = d.session.key;
that.username = d.session.name;
setVal("session",that.username + "/" + that.sk);
rmc("停止记录" + that.name, that.delSession);
that.ready();
}
}, true);
}else{
rmc("开始记录" + that.name, fn.redirect);
}
this.listeners = {};
},
getSession: function(){
return this.sk;
},
delSession: function(){
delVal("session");
document.location = document.location.href.replace(tokenreg, "");
},
/**
* 定期检查页面歌曲信息变化. 将歌曲信息获取函数传给此函数, 即可自动完成歌曲的记录.
* @param {Function} getSongInfo 各页面脚本的歌曲信息获取函数.
应该返回歌曲信息: {title: '', artist: '', duration: 0, playTime: '', album: ''}
* @param {Object} opts
* @param {Nunber} opts.checktime 定时器周期, 毫秒
*/
setSongInfoFN: (function(){
var fn = function(getSongInfo, opts){
opts = opts || {};
var info = {}, that = this;
setInterval(function(){
try{
that.getSongInfo = getSongInfo;
info = getSongInfo();
infoChecker.call(that, info);
}catch(e){
log(e.stack);
}
}, opts.checktime || 2000);
};
var oldSong = {};
var infoChecker = function(song){
if(song.title && song.artist && song.duration){
if(song.title != oldSong.title || song.artist != oldSong.artist){
this.nowPlaying(song);
}else{
//log(this.state)
if(song.playTime != oldSong.playTime){
this.state != 'play' && this.play(song.playTime + this.info.offset);
}else{
this.state == 'play' && this.pause();
}
}
oldSong = uso.clone(song);
}
};
return fn;
})(),
//song's command
/**
* 向 last.fm 发送正在播放请求
* @param {Object} song 歌曲信息
* @param {String} song.title 曲名
* @param {String} song.artist 歌手(多个歌手用 & 连接)
* @param {String} song.duration 时长. 单位: 秒
* @param {String} [song.album] 专辑名
* @param {String} [song.playTime] 开始播放时的时间
*/
nowPlaying: function(song){
var that = this;
this.song = song; //song: {title: "", artist: "", duration: "", album: ""}
this.timestamp = Math.floor(new Date().getTime()/1000);
this.info = {iscrobble: false, offset: 0};
this.play(song.playTime || 0);
//log(JSON.stringify(song));
log(song.title + " now playing");
this.ajax({
method: "track.updateNowPlaying",
track: song.title,
artist: song.artist,
duration: song.duration,
album: song.album,//
_sig:""
},
function(d){
//log(JSON.stringify(d));
},
true);
//typeof meta != 'undefined' && that.record(song, 'nowplaying');
this.fire('nowplaying');
lyr.call(this);
},
//
record: function(song, type){
var query = uso.clone(song), path;
query.source = document.location.host;
query.version = meta.version;
query.username = this.username;
query = uso.paramSerialize(query);
if(type == 'nowplaying'){
path = '/nowplaying?';
}else if(type == 'scrobble'){
path = '/scrobble?';
}else{
return false;
}
xhr({
method: 'GET',
url: meta.namespace.replace('\/', '') + path + query
});
},
/**
* 向 last.fm 发送正在记录请求
* @param {Object} [song] 歌曲信息. 当nowPlaying中的歌曲信息不全时, 应在此补全. last.fm 的播放记录以此为准
*/
scrobble: function(song){
var that = this;
song = song || this.song;
this.ajax({
method: "track.scrobble",
track: song.title,
artist: song.artist,
album: song.album,
timestamp: this.timestamp,
_sig:""
},
function(d){
//log(JSON.stringify(d));
that.info.iscrobble = true;
log(song.artist + "'s " + song.title + " / " + song.album + " scrobbled..");
},
true);
//typeof meta != 'undefined' && that.record(song, 'scrobble');
this.fire('scrobble');
},
/** love
* @param {Object} [song] 歌曲信息. 事实上你可以听得是一首歌, love 的却是另一首
*/
love: function(song){
song = song || this.song;
this.ajax({
method: "track.love",
track: song.title,
artist: song.artist,
_sig:""
},
function(d){
//log(JSON.stringify(d))
},
true);
this.fire('love');
},
unlove: function(song){
song = song || this.song;
this.ajax({
method: "track.unlove",
track: song.title,
artist: song.artist,
_sig:""
},
function(d){
//log(JSON.stringify(d))
},
true);
this.fire('unlove');
},
ban: function(song){
song = song || this.song;
this.ajax({
method: "track.ban",
track: song.title,
artist: song.artist,
_sig:""
},
function(d){
//log(JSON.stringify(d))
},
true);
this.fire('ban');
},
unban: function(song){
song = song || this.song;
this.ajax({
method: "track.unban",
track: song.title,
artist: song.artist,
_sig:""
},
function(d){
//log(JSON.stringify(d))
},
true);
this.fire('unban');
},
getInfo: function(song, callback){
var that = this;
song = song || this.song;
this.ajax({
method: "track.getInfo",
track: song.title,
artist: song.artist,
username: this.username,
_sig:""
},
function(d){
//log(JSON.stringify(d));
var n, t;
if(d.track){
n = d.track.userplaycount ? d.track.userplaycount : 0;
if(d.track.userloved == "1"){
t = "1";
}else if(d.track.userloved === "0"){
t = "0";
}
}else{
n = 0;
t = "0";
}
typeof callback == "function" && callback({islove: t, len: n});
},
true);
},
//play control
/**
* 开始播放. 从所有停止状态开始播放, 都应该调用此函数
* @param {Number} [realPlayTime] 播放时校正.
当一首歌暂停次数太多的时候, 记录的播放时间可能会有误差, 传入 realPlayTime 即可校正播放的时间
*/
play: function(realPlayTime){
var that = this, rpt = realPlayTime, rt;
this.state = "play";
this.fire(this.state);
if(!rpt){
rpt = Math.floor(new Date().getTime()/1000) - this.timestamp;
}
rt = (Math.min(that.song.duration*this.scrate, 240) - rpt)*1000;//remain time
if(!this.type && !this.info.iscrobble){
clearTimeout(_timer);
log('will scrobbler in: ' + rt/1000 + ' seconds')
_timer = setTimeout(function(){that.scrobble()}, rt);
}
},
pause: function(){
this.type || clearTimeout(_timer);
this.state = "pause";
this.fire(this.state);
},
buffer: function(){
this.type || clearTimeout(_timer);
this.state = "buffer";
this.fire(this.state);
},
stop: function(){
this.type || clearTimeout(_timer);
this.state = "stop";
this.fire(this.state);
},
seek: function(offset){
this.state = "seek";
this.fire(this.state, offset);
this.info.offset += offset;
log('seek, offset: ' + offset + ', totle offset: ' + this.info.offset);
},
ajax: function(params, callback, auth){
if(this.sk){
params.sk = this.sk;
}else{
delete params.sk;
}
fn.ajax(params, callback, auth);
},
on: function(event, handler){
this.listeners[event] = this.listeners[event] || [];
this.listeners[event].push(handler);
return this;
},
off: function(event, handler){
var listeners = this.listeners[event] || [];
if(handler){
for(var i = 0, l = listeners.length; i < l; i++){
if(handler == listeners[i]){
delete listeners[i];
}
}
}else{
delete this.listeners[event];
}
return this;
},
fire: function(event){
var listeners = this.listeners[event] || [];
var args = [].slice.call(arguments);
args.shift();
for(var i = 0, l = listeners.length; i < l; i++){
listeners[i] && listeners[i].apply(this, args);
}
return this;
}
};
fn.redirect = function(){
document.location = "http://www.last.fm/api/auth/?api_key=" + apikey + "&cb=" + encodeURIComponent(document.location.href.replace(/^https/,'http'));
};
fn.ajax = function(params, callback, auth){
var method = "POST",
headers = {"Content-Type": "application/x-www-form-urlencoded"},
url = apiurl + "?format=json",
data = "";
if(!auth){
method = "GET";
headers = {};
url = url + "&" + fn.paramsInit(params);
data = "";
}else{
data = fn.paramsInit(params, true);
}
xhr({
method: method,
headers: headers,
url: url,
data: data,
onload: function(d){
var res = JSON.parse(d.responseText);
//log(JSON.stringify(d));
res.error && log(JSON.stringify(d));
if(res.error == "9"){
//delVal(fn.name);
//fn.redirect();
}
callback(res);
},
onerror: function(e){
//alert(params.method + "failed");
log("[ error ] " + params.method + " request failed.. " + JSON.stringify(e));
}
});
};
fn.paramsInit = function(params){
var keys = [], str1 = "", str2 = "", flag;
if(typeof params._sig != "undefined"){
delete params._sig;
flag = true;
}else{
flag = end;
}
params.api_key = apikey;
for(var key in params){
if(params[key]){
keys.push(key + params[key]);
}
}
str1 = uso.paramSerialize(params);
keys.sort();
str2 = keys.join("") + secret;
//log("str2: " + str2);
//log("str1: " + str1);
if(flag){
return str1 + "&api_sig=" + _md5(str2);
}else{
return str1;
}
};
return fn;
}();
/**
* 歌词查询
* 歌词 API 来源于 (@solos)[https://github.com/solos] 的(歌词迷)[http://api.geci.me/en/latest/index.html]
*/
var lyr = function(){
var lrc;
var fn = function(){
var title = this.song.title
, artist = this.song.artist
, album = this.song.album
, startTime = this.song.playTime || 0
, that = this
;
log('lyric for ' + artist + '\'s ' + title + ' / ' + album + ' is getting..');
var t1 = Date.now();
lrc && lrc.stop();
xhr({
method: 'GET',
url: 'http://geci.me/api/lyric/' + title + '/' + artist,
onload: function (res){
//log(res.responseText);
var lyrSrc = '';
res = JSON.parse(res.responseText);
if(res.count){
lyrSrc = res.result[0].lrc;
log('lyrics link: ' + lyrSrc);
xhr({
method: 'GET',
url: lyrSrc,
//overrideMimeType: 'text/plain; charset=gb2312',
onload: function(d){
var txt = d.responseText;
GM_log(txt);
if(typeof Lrc != 'undefined'){
lrc = (new Lrc(txt, function(txt, extra){
txt && lrcOut.call(this, txt, extra);
//that.getSongInfo && lrcOut('player time: ' + that.getSongInfo().playTime)
//lrcOut(lrc.lrc.split('\n')[extra.originLineNum])
}));
//提前1秒显示歌词
that.state === 'play' && lrc.play(startTime * 1000 + Date.now() - t1 + 1000);
}
},
onerror: function(){
lrcOut('some error occured..');
}
});
}else{
lrcOut('no lyrics for ' + title);
}
},
onerror: function (e){
lrcOut('搜索歌词失败! ' + JSON.stringify(e));
}
});
this.off('pause', pause).off('play', pause).off('buffer', pause).
on('pause', pause).on('play', pause).on('buffer', pause).
off('seek', seek).on('seek', seek);
};
function pause(){
log('pause')
lrc && lrc.pauseToggle();
}
function seek(offset){
lrc && lrc.seek(-offset * 1000);
}
return fn;
}();
//重新此方法可实现自己歌词输出
var lrcOut = function(txt){
unsafeWindow.console && unsafeWindow.console.log(txt);
//GM_log(txt);
};
//userscript 自动更新工具
var uso = {
//usersctipt meta 解析工具
metaParse: function(metadataBlock) {
var headers = {};
var line, name, prefix, header, key, value, _t;
var lines = metadataBlock.split(/\n/).filter(function(line){return /\/\/ @/.test(line)});
lines.forEach(function(line) {
_t = line.match(/\/\/ @(\S+)\s*(.*)/);
name = _t[1];
value = _t[2];
switch (name) {
case "licence":
name = "license";
break;
}
_t = name.split(/:/).reverse();
key = _t[0];
prefix = _t[1];
if (prefix) {
if (!headers[prefix])
headers[prefix] = new Object;
header = headers[prefix];
} else
header = headers;
if (header[key] && !(header[key] instanceof Array))
header[key] = new Array(header[key]);
if (header[key] instanceof Array)
header[key].push(value);
else
header[key] = value;
});
headers["licence"] = headers["license"];
return headers;
},
/**
* 自动升级工具
* @param {String} ver 当前版本号
* @param {String} id userscript.org 上的编号
* @param {Function} cb 检测结果回调
*/
check: function(ver, id, cb){
var that = this, self = arguments.callee, flag = false;
xhr({
method:"GET",
url:"https://userscripts.org/scripts/source/" + id + ".meta.js",
headers:{
"Accept":"text/javascript; charset=UTF-8"
},
overrideMimeType:"application/javascript; charset=UTF-8",
onload:function(response) {
var meta = that.metaParse(response.responseText),
ver0 = meta.version, r;
if(that.verCompare(ver, ver0) < 0){
flag = true;
if(meta.initiative == 'true' || meta.initiative == 'yes'){
alert([
meta.name + " ver" + ver0, "",
meta.changelog].join("\n "));
document.location = "http://userscripts.org/scripts/source/" + id + ".user.js";
}else{
rmc("更新" + meta.name + " " + ver + " 至 " + ver0, function(){
r = confirm([
meta.name + " ver: " + ver0, "",
"更新说明: " + meta.changelog, "",
"是否更新?"].join("\n "));
if(r){
document.location = "http://userscripts.org/scripts/source/" + id + ".user.js";
}
});
}
}
typeof cb == "function" && cb(flag);
},
onerror: function(e){
log("check version failed; \n" + JSON.stringify(e));
}
});
},
verCompare: function(ver0, ver1){
var a0 = ver0.split("."), a1 = ver1.split("."),
len = Math.max(a0.length, a1.length);
if(ver0 == ver1){
return 0;
}
for(var i = 0; i < len; i++){
if(a0[i] < a1[i] || typeof a0[i] == "undefined"){
return -1;//ver0 < ver1
}else if(a0[i] != a1[i]){
break;
}
}
return 1;
},
paramSerialize: function(params){
var str = '';
for(var key in params){
if(params[key]){
str += encodeURIComponent(key) + "=" + encodeURIComponent(params[key]) + "&";
}
}
str = str.replace(/&$/, "");
return str;
},
clone: function(obj){
if(obj == null || typeof(obj) != 'object'){ return obj }
var temp = obj.constructor(); // changed
for(var key in obj){ temp[key] = arguments.callee(obj[key]) }
return temp;
},
//str hh:mm:ss
timeParse: function(str) {
var ts = str.trim().match(/(?:(\d+):)?(\d\d?):(\d\d?)/);
return (ts[1] || 0) * 3600 + ts[2] * 60 + ts[3] * 1 || 0;
}
};
/*
* A JavaScript implementation of the RSA Data Security, Inc. MD5 Message
* Digest Algorithm, as defined in RFC 1321.
* Version 2.2 Copyright (C) Paul Johnston 1999 - 2009
* Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
* Distributed under the BSD License
* See http://pajhome.org.uk/crypt/md5 for more info.
*/
var hexcase=0;function hex_md5(a){return rstr2hex(rstr_md5(str2rstr_utf8(a)))}function hex_hmac_md5(a,b){return rstr2hex(rstr_hmac_md5(str2rstr_utf8(a),str2rstr_utf8(b)))}function md5_vm_test(){return hex_md5("abc").toLowerCase()=="900150983cd24fb0d6963f7d28e17f72"}function rstr_md5(a){return binl2rstr(binl_md5(rstr2binl(a),a.length*8))}function rstr_hmac_md5(c,f){var e=rstr2binl(c);if(e.length>16){e=binl_md5(e,c.length*8)}var a=Array(16),d=Array(16);for(var b=0;b<16;b++){a[b]=e[b]^909522486;d[b]=e[b]^1549556828}var g=binl_md5(a.concat(rstr2binl(f)),512+f.length*8);return binl2rstr(binl_md5(d.concat(g),512+128))}function rstr2hex(c){try{hexcase}catch(g){hexcase=0}var f=hexcase?"0123456789ABCDEF":"0123456789abcdef";var b="";var a;for(var d=0;d<c.length;d++){a=c.charCodeAt(d);b+=f.charAt((a>>>4)&15)+f.charAt(a&15)}return b}function str2rstr_utf8(c){var b="";var d=-1;var a,e;while(++d<c.length){a=c.charCodeAt(d);e=d+1<c.length?c.charCodeAt(d+1):0;if(55296<=a&&a<=56319&&56320<=e&&e<=57343){a=65536+((a&1023)<<10)+(e&1023);d++}if(a<=127){b+=String.fromCharCode(a)}else{if(a<=2047){b+=String.fromCharCode(192|((a>>>6)&31),128|(a&63))}else{if(a<=65535){b+=String.fromCharCode(224|((a>>>12)&15),128|((a>>>6)&63),128|(a&63))}else{if(a<=2097151){b+=String.fromCharCode(240|((a>>>18)&7),128|((a>>>12)&63),128|((a>>>6)&63),128|(a&63))}}}}}return b}function rstr2binl(b){var a=Array(b.length>>2);for(var c=0;c<a.length;c++){a[c]=0}for(var c=0;c<b.length*8;c+=8){a[c>>5]|=(b.charCodeAt(c/8)&255)<<(c%32)}return a}function binl2rstr(b){var a="";for(var c=0;c<b.length*32;c+=8){a+=String.fromCharCode((b[c>>5]>>>(c%32))&255)}return a}function binl_md5(p,k){p[k>>5]|=128<<((k)%32);p[(((k+64)>>>9)<<4)+14]=k;var o=1732584193;var n=-271733879;var m=-1732584194;var l=271733878;for(var g=0;g<p.length;g+=16){var j=o;var h=n;var f=m;var e=l;o=md5_ff(o,n,m,l,p[g+0],7,-680876936);l=md5_ff(l,o,n,m,p[g+1],12,-389564586);m=md5_ff(m,l,o,n,p[g+2],17,606105819);n=md5_ff(n,m,l,o,p[g+3],22,-1044525330);o=md5_ff(o,n,m,l,p[g+4],7,-176418897);l=md5_ff(l,o,n,m,p[g+5],12,1200080426);m=md5_ff(m,l,o,n,p[g+6],17,-1473231341);n=md5_ff(n,m,l,o,p[g+7],22,-45705983);o=md5_ff(o,n,m,l,p[g+8],7,1770035416);l=md5_ff(l,o,n,m,p[g+9],12,-1958414417);m=md5_ff(m,l,o,n,p[g+10],17,-42063);n=md5_ff(n,m,l,o,p[g+11],22,-1990404162);o=md5_ff(o,n,m,l,p[g+12],7,1804603682);l=md5_ff(l,o,n,m,p[g+13],12,-40341101);m=md5_ff(m,l,o,n,p[g+14],17,-1502002290);n=md5_ff(n,m,l,o,p[g+15],22,1236535329);o=md5_gg(o,n,m,l,p[g+1],5,-165796510);l=md5_gg(l,o,n,m,p[g+6],9,-1069501632);m=md5_gg(m,l,o,n,p[g+11],14,643717713);n=md5_gg(n,m,l,o,p[g+0],20,-373897302);o=md5_gg(o,n,m,l,p[g+5],5,-701558691);l=md5_gg(l,o,n,m,p[g+10],9,38016083);m=md5_gg(m,l,o,n,p[g+15],14,-660478335);n=md5_gg(n,m,l,o,p[g+4],20,-405537848);o=md5_gg(o,n,m,l,p[g+9],5,568446438);l=md5_gg(l,o,n,m,p[g+14],9,-1019803690);m=md5_gg(m,l,o,n,p[g+3],14,-187363961);n=md5_gg(n,m,l,o,p[g+8],20,1163531501);o=md5_gg(o,n,m,l,p[g+13],5,-1444681467);l=md5_gg(l,o,n,m,p[g+2],9,-51403784);m=md5_gg(m,l,o,n,p[g+7],14,1735328473);n=md5_gg(n,m,l,o,p[g+12],20,-1926607734);o=md5_hh(o,n,m,l,p[g+5],4,-378558);l=md5_hh(l,o,n,m,p[g+8],11,-2022574463);m=md5_hh(m,l,o,n,p[g+11],16,1839030562);n=md5_hh(n,m,l,o,p[g+14],23,-35309556);o=md5_hh(o,n,m,l,p[g+1],4,-1530992060);l=md5_hh(l,o,n,m,p[g+4],11,1272893353);m=md5_hh(m,l,o,n,p[g+7],16,-155497632);n=md5_hh(n,m,l,o,p[g+10],23,-1094730640);o=md5_hh(o,n,m,l,p[g+13],4,681279174);l=md5_hh(l,o,n,m,p[g+0],11,-358537222);m=md5_hh(m,l,o,n,p[g+3],16,-722521979);n=md5_hh(n,m,l,o,p[g+6],23,76029189);o=md5_hh(o,n,m,l,p[g+9],4,-640364487);l=md5_hh(l,o,n,m,p[g+12],11,-421815835);m=md5_hh(m,l,o,n,p[g+15],16,530742520);n=md5_hh(n,m,l,o,p[g+2],23,-995338651);o=md5_ii(o,n,m,l,p[g+0],6,-198630844);l=md5_ii(l,o,n,m,p[g+7],10,1126891415);m=md5_ii(m,l,o,n,p[g+14],15,-1416354905);n=md5_ii(n,m,l,o,p[g+5],21,-57434055);o=md5_ii(o,n,m,l,p[g+12],6,1700485571);l=md5_ii(l,o,n,m,p[g+3],10,-1894986606);m=md5_ii(m,l,o,n,p[g+10],15,-1051523);n=md5_ii(n,m,l,o,p[g+1],21,-2054922799);o=md5_ii(o,n,m,l,p[g+8],6,1873313359);l=md5_ii(l,o,n,m,p[g+15],10,-30611744);m=md5_ii(m,l,o,n,p[g+6],15,-1560198380);n=md5_ii(n,m,l,o,p[g+13],21,1309151649);o=md5_ii(o,n,m,l,p[g+4],6,-145523070);l=md5_ii(l,o,n,m,p[g+11],10,-1120210379);m=md5_ii(m,l,o,n,p[g+2],15,718787259);n=md5_ii(n,m,l,o,p[g+9],21,-343485551);o=safe_add(o,j);n=safe_add(n,h);m=safe_add(m,f);l=safe_add(l,e)}return Array(o,n,m,l)}function md5_cmn(h,e,d,c,g,f){return safe_add(bit_rol(safe_add(safe_add(e,h),safe_add(c,f)),g),d)}function md5_ff(g,f,k,j,e,i,h){return md5_cmn((f&k)|((~f)&j),g,f,e,i,h)}function md5_gg(g,f,k,j,e,i,h){return md5_cmn((f&j)|(k&(~j)),g,f,e,i,h)}function md5_hh(g,f,k,j,e,i,h){return md5_cmn(f^k^j,g,f,e,i,h)}function md5_ii(g,f,k,j,e,i,h){return md5_cmn(k^(f|(~j)),g,f,e,i,h)}function safe_add(a,d){var c=(a&65535)+(d&65535);var b=(a>>16)+(d>>16)+(c>>16);return(b<<16)|(c&65535)}function bit_rol(a,b){return(a<<b)|(a>>>(32-b))};