1
- var waveformData = require ( './server/library/waveformData' ) ;
1
+ import { getLocalWaveData , getRemoteWaveData } from './server/library/waveformData.js'
2
2
3
- var queryObject = { } ;
3
+ const queryObject = { }
4
4
5
5
process . argv . forEach ( function ( value , index , array ) {
6
-
7
- var commandParametersLength = array . length - 2 ;
8
-
6
+
7
+ const commandParametersLength = array . length - 2
8
+
9
9
if ( commandParametersLength !== 7 ) {
10
-
11
- var error = 'invalid parameters length, please call the cli with the following parameters: node cli SERVER_PATH TRACK_NAME TRACK_EXTENSION AMOUT_OF_PEAKS LOCAL_OR_REMOTE_SERVICENAME PEAKSLIST_OUTPUT_FORMAT TRACK_FORMAT_DETECTION\n' ;
12
-
13
- process . stderr . write ( error + "\n" ) ;
14
-
15
- process . exit ( 1 ) ;
16
-
17
- }
18
-
10
+
11
+ const error = 'invalid parameters length, please call the cli with the following parameters: node cli SERVER_PATH TRACK_NAME TRACK_EXTENSION AMOUT_OF_PEAKS LOCAL_OR_REMOTE_SERVICENAME PEAKSLIST_OUTPUT_FORMAT TRACK_FORMAT_DETECTION\n'
12
+
13
+ process . stderr . write ( error + "\n" )
14
+
15
+ process . exit ( 1 )
16
+
17
+ }
18
+
19
19
if ( index === 2 ) {
20
-
21
- queryObject . serverDirectory = value ;
22
-
20
+ queryObject . serverDirectory = value
23
21
}
24
-
22
+
25
23
if ( index === 3 ) {
26
-
27
- queryObject . trackId = value ;
28
-
24
+ queryObject . trackId = value
29
25
}
30
-
26
+
31
27
if ( index === 4 ) {
32
-
33
- queryObject . trackFormat = value . toLowerCase ( ) ;
34
-
28
+ queryObject . trackFormat = value . toLowerCase ( )
35
29
}
36
-
30
+
37
31
if ( index === 5 ) {
38
-
39
- queryObject . peaksAmount = parseInt ( value ) ;
40
-
32
+ queryObject . peaksAmount = parseInt ( value )
41
33
}
42
-
34
+
43
35
if ( index === 6 ) {
44
-
45
- queryObject . service = value . toLowerCase ( ) ;
46
-
36
+ queryObject . service = value . toLowerCase ( )
47
37
}
48
-
38
+
49
39
if ( index === 7 ) {
50
-
51
- queryObject . outputFormat = value . toLowerCase ( ) ;
52
-
40
+ queryObject . outputFormat = value . toLowerCase ( )
53
41
}
54
-
42
+
55
43
if ( index === 8 ) {
56
-
44
+
57
45
if ( typeof value === 'boolean' ) {
58
-
59
- queryObject . detectFormat = value ;
60
-
46
+ queryObject . detectFormat = value
61
47
} else {
62
-
63
- var detectFormat = value . toLowerCase ( ) ;
48
+
49
+ const detectFormat = value . toLowerCase ( )
64
50
65
51
if ( detectFormat === 'true' ) {
66
-
67
- queryObject . detectFormat = true ;
68
-
69
- } else if ( detectFormat . substr ( 0 , 2 ) === 'sr' ) {
70
-
71
- var splittedDetectFormat = detectFormat . split ( '=' ) ;
72
-
73
- queryObject . detectFormat = parseInt ( splittedDetectFormat [ 1 ] ) ;
74
-
52
+ queryObject . detectFormat = true
53
+ } else if ( detectFormat . substr ( 0 , 2 ) === 'sr' ) {
54
+ const splittedDetectFormat = detectFormat . split ( '=' )
55
+ queryObject . detectFormat = parseInt ( splittedDetectFormat [ 1 ] )
75
56
} else {
76
-
77
- queryObject . detectFormat = false ;
78
-
57
+ queryObject . detectFormat = false
79
58
}
80
-
59
+
81
60
}
82
-
83
61
}
84
-
85
- } ) ;
62
+ } )
86
63
87
- var outputResponse = function outputResponseFunction ( error , peaks ) {
64
+ const outputResponse = function outputResponseFunction ( error , peaks ) {
88
65
89
66
if ( error ) {
90
-
91
- process . stderr . write ( error + "\n" ) ;
92
-
93
- process . exit ( 1 ) ;
94
-
67
+ process . stderr . write ( error + "\n" )
68
+ process . exit ( 1 )
95
69
} else {
96
70
97
- var output = '' ;
71
+ let output = ''
98
72
99
73
// outputFormat can be json or text
100
74
if ( queryObject . outputFormat === 'json' ) {
101
75
102
- var outputData = {
76
+ const outputData = {
103
77
"peaks" : peaks
104
- } ;
105
-
106
- output = JSON . stringify ( outputData ) ;
107
-
78
+ }
79
+
80
+ output = JSON . stringify ( outputData )
81
+
108
82
} else {
109
-
110
- var peaksString = '' ;
111
- var i ;
112
- var peaksLength = peaks . length ;
83
+
84
+ const peaksString = ''
85
+ let i
86
+ const peaksLength = peaks . length
113
87
114
88
for ( i = 0 ; i < peaksLength ; i ++ ) {
89
+ peaksString += peaks [ i ] + ','
90
+ }
115
91
116
- peaksString += peaks [ i ] + ',' ;
92
+ output = peaksString . substring ( 0 , peaksString . length - 1 )
117
93
118
- }
119
-
120
- output = peaksString . substring ( 0 , peaksString . length - 1 ) ;
121
-
122
94
}
123
-
124
- process . stdout . write ( output + "\n" ) ;
125
95
126
- process . exit ( 0 ) ;
96
+ process . stdout . write ( output + "\n" )
97
+
98
+ process . exit ( 0 )
127
99
128
100
}
129
-
130
- } ;
101
+ }
131
102
132
103
if ( queryObject . service === 'local' ) {
133
-
134
- // node cli ./downloads 1100511 ogg 200 local json false
135
- // node cli ./downloads 1100511 mp3 200 local json false
136
- waveformData . getLocalWaveData ( queryObject , outputResponse ) ;
137
-
104
+ getLocalWaveData ( queryObject , outputResponse )
138
105
} else {
139
-
140
- // node cli ./downloads 1100511 ogg 200 jamendo json false
141
- // node cli ./downloads 1100511 mp3 200 jamendo json false
142
- waveformData . getRemoteWaveData ( queryObject , outputResponse ) ;
143
-
106
+ getRemoteWaveData ( queryObject , outputResponse )
144
107
}
0 commit comments