forked from nukeop/nuclear
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.js
32 lines (27 loc) · 779 Bytes
/
utils.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
import _ from 'lodash';
export function formatDuration(duration) {
let sec_num = parseInt(duration, 10);
let hours = Math.floor(sec_num / 3600);
let minutes = Math.floor((sec_num - (hours * 3600)) / 60);
let seconds = sec_num - (hours * 3600) - (minutes * 60);
if (hours < 10) {
hours = '0'+hours;
}
if (minutes < 10) {
minutes = '0'+minutes;
}
if (seconds < 10) {
seconds = '0'+seconds;
}
if (hours === '00') {
return minutes+':'+seconds;
} else {
return hours+':'+minutes+':'+seconds;
}
}
export function getSelectedStream(streams, defaultMusicSource) {
let selectedStream = _.find(streams, {source: defaultMusicSource});
return selectedStream === undefined
? streams ? streams[0] : null
: selectedStream;
}