-
Notifications
You must be signed in to change notification settings - Fork 51
/
start.ts
122 lines (91 loc) · 3.1 KB
/
start.ts
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
import { type SortableEvent } from 'sortablejs';
import player from '../lib/player';
import { getSaved, params, store } from '../lib/store';
import { idFromURL, notify } from '../lib/utils';
import { bitrateSelector, searchFilters, superInput, audio, loadingScreen, ytifyIcon, queuelist } from '../lib/dom';
import fetchList from '../modules/fetchList';
import { fetchCollection } from "../lib/libraryUtils";
export default async function() {
const custom_instance = getSaved('custom_instance_2');
const a = store.api;
if (custom_instance) {
const [pi, iv] = custom_instance.split(',');
a.piped.push(pi);
a.invidious.push(iv);
} else {
const apiUrl = 'https://raw.githubusercontent.com/n-ce/Uma/main/dynamic_instances.json';
await fetch(apiUrl)
.then(res => res.json())
.then(data => {
a.piped = data.piped;
a.invidious = data.invidious;
});
}
// hls
if (getSaved('HLS')) {
// handling bitrates with HLS will increase complexity, better to detach from DOM
bitrateSelector.remove();
if (!store.player.legacy)
import('hls.js')
.then(mod => {
store.player.HLS = new mod.default();
const h = store.player.HLS;
h.attachMedia(audio);
h.on(mod.default.Events.MANIFEST_PARSED, () => {
h.currentLevel = store.player.hq ?
h.levels.findIndex(l => l.audioCodec === 'mp4a.40.2') : 0;
audio.play();
});
h.on(mod.default.Events.ERROR, (_, d) => {
if (d.details === 'manifestLoadError') {
notify(d.details);
player(id);
}
})
})
}
else bitrateSelector.addEventListener('change', () => {
if (store.player.playbackState === 'playing')
audio.pause();
const timeOfSwitch = audio.currentTime;
audio.src = bitrateSelector.value;
audio.currentTime = timeOfSwitch;
audio.play();
});
// queue sorting
await import('sortablejs')
.then(mod =>
new mod.default(queuelist, {
handle: '.ri-draggable',
onUpdate(e: SortableEvent) {
if (e.oldIndex == null || e.newIndex == null) return;
const queueArray = store.queue;
queueArray.splice(e.newIndex, 0, queueArray.splice(e.oldIndex, 1)[0]);
}
})
);
// params handling
const id = params.get('s') || idFromURL(params.get('url') || params.get('text'));
if (id) {
loadingScreen.showModal();
await player(id);
loadingScreen.close();
}
else document.getElementById('ytifyIconContainer')?.prepend(ytifyIcon);
if (params.has('q')) {
superInput.value = params.get('q') || '';
if (params.has('f'))
searchFilters.value = params.get('f') || '';
superInput.dispatchEvent(new KeyboardEvent('keydown', { 'key': 'Enter' }));
}
if (params.has('collection') || params.has('si'))
fetchCollection(params.get('collection'), params.get('si'));
// list loading
if (params.has('channel') || params.has('playlists'))
fetchList('/' +
location.search
.substring(1)
.split('=')
.join('/')
);
}