Skip to content

Commit d4adce9

Browse files
committed
clyric
1 parent 4e57db5 commit d4adce9

4 files changed

Lines changed: 4690 additions & 33 deletions

File tree

package.json

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
{
2-
"name": "cPlayer",
2+
"name": "cplayer",
33
"version": "2.4.7",
44
"description": "A beautiful and clean WEB Music Player by HTML5.",
55
"scripts": {
66
"dist": "gulp compress",
77
"demo": "gulp createDemo",
8-
"serve":"gulp serve"
8+
"serve": "gulp serve",
9+
"build": "webpack"
910
},
1011
"keywords": [
1112
"cPlayer",
@@ -32,9 +33,7 @@
3233
],
3334
"bugs": "zsq01@live.com",
3435
"license": "MIT",
35-
"repository": [
36-
"https://github.com/Copay/cPlayer"
37-
],
36+
"repository": "https://github.com/Copay/cPlayer",
3837
"devDependencies": {
3938
"babel": "*",
4039
"babel-cli": "*",
@@ -49,6 +48,9 @@
4948
"gulp-sourcemaps": "*",
5049
"gulp-uglify": "*",
5150
"node-sass": "latest",
52-
"uglify": "*"
51+
"tslint": "^5.5.0",
52+
"typescript": "^2.4.2",
53+
"uglify": "*",
54+
"webpack": "^3.3.0"
5355
}
5456
}

src/js/cplayer.js

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
55
I am the super Corps!
66
*/
7-
7+
import cLyric from "modules/cLyric.function";
88
const cPlayer = class cPlayer {
99
constructor(options) {
1010
this.transLock = false;
@@ -634,30 +634,5 @@ const cContext = class cContext{
634634
}
635635
}
636636

637-
function cLyric(lrc){
638-
let offset = 0,
639-
lyricArray = [];
640-
lrc.replace(/\n+/gi,"\n").split("\n").forEach(function(content){
641-
//content is like:
642-
// [00:12.34]JUUUUUUUUUUUUUUMP!!!!!!
643-
//get OFFSET
644-
if(content.indexOf("offset")!==-1) offset = parseInt((/offset\:(\d+)/gi).exec(content)[1]);
645-
//get Lyric and translate it.
646-
//ar[] -> [1.24,2.21,36.15,"HEY!"]
647-
if(/\[\d+:[\d\.]+\]/gi.test(content)){
648-
let ar = [];
649-
[].forEach.call(content.match(/\[\d+\:[\.\d]+\]/gi),function(e){
650-
let number = /\[(\d+)\:([\.\d]+)\]/gi.exec(e);
651-
ar.push(parseInt(number[1])*60+parseFloat(number[2]-offset*0.001));
652-
});
653-
ar.push(/(?:\[\d+\:[\.\d]+\])*(.*)/gi.exec(content)[1]);
654-
do{
655-
lyricArray.push({time:ar.shift(),content:ar[ar.length-1]});
656-
}while(ar.length>=2)
657-
}
658-
});
659-
return lyricArray.sort((a, b)=> {
660-
return a.time - b.time;
661-
});
662-
} ;
637+
663638
if(window)window.cPlayer = cPlayer;

src/js/modules/cLyric.function.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
2+
/**
3+
* To transform the lrc contents into a array
4+
* @module module/cLyric.function
5+
* @param {string} lrc The lyric string
6+
* @return {array} Sorted lyric array
7+
*/
8+
export function cLyric(lrc){
9+
let offset = 0,
10+
lyricArray = [];
11+
lrc.replace(/\n+/gi,"\n").split("\n").forEach(function(content){
12+
//content is like:
13+
// [00:12.34]JUUUUUUUUUUUUUUMP!!!!!!
14+
//get OFFSET
15+
if(content.indexOf("offset")!==-1) offset = parseInt((/offset\:(\d+)/gi).exec(content)[1]);
16+
//get Lyric and translate it.
17+
//ar[] -> [1.24,2.21,36.15,"HEY!"]
18+
if(/\[\d+:[\d\.]+\]/gi.test(content)){
19+
let ar = [];
20+
[].forEach.call(content.match(/\[\d+\:[\.\d]+\]/gi),function(e){
21+
let number = /\[(\d+)\:([\.\d]+)\]/gi.exec(e);
22+
ar.push(parseInt(number[1])*60+parseFloat(number[2]-offset*0.001));
23+
});
24+
ar.push(/(?:\[\d+\:[\.\d]+\])*(.*)/gi.exec(content)[1]);
25+
do{
26+
lyricArray.push({time:ar.shift(),content:ar[ar.length-1]});
27+
}while(ar.length>=2)
28+
}
29+
});
30+
return lyricArray.sort((a, b)=> {
31+
return a.time - b.time;
32+
});
33+
};

0 commit comments

Comments
 (0)