tunecamp 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env.local +2 -0
- package/.vercel/README.txt +11 -0
- package/.vercel/project.json +1 -0
- package/LICENSE +22 -0
- package/README.md +554 -0
- package/dist/cli.d.ts +6 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +172 -0
- package/dist/cli.js.map +1 -0
- package/dist/generator/embedGenerator.d.ts +38 -0
- package/dist/generator/embedGenerator.d.ts.map +1 -0
- package/dist/generator/embedGenerator.js +92 -0
- package/dist/generator/embedGenerator.js.map +1 -0
- package/dist/generator/feedGenerator.d.ts +50 -0
- package/dist/generator/feedGenerator.d.ts.map +1 -0
- package/dist/generator/feedGenerator.js +167 -0
- package/dist/generator/feedGenerator.js.map +1 -0
- package/dist/generator/podcastFeedGenerator.d.ts +54 -0
- package/dist/generator/podcastFeedGenerator.d.ts.map +1 -0
- package/dist/generator/podcastFeedGenerator.js +173 -0
- package/dist/generator/podcastFeedGenerator.js.map +1 -0
- package/dist/generator/proceduralCoverGenerator.d.ts +51 -0
- package/dist/generator/proceduralCoverGenerator.d.ts.map +1 -0
- package/dist/generator/proceduralCoverGenerator.js +228 -0
- package/dist/generator/proceduralCoverGenerator.js.map +1 -0
- package/dist/generator/siteGenerator.d.ts +55 -0
- package/dist/generator/siteGenerator.d.ts.map +1 -0
- package/dist/generator/siteGenerator.js +539 -0
- package/dist/generator/siteGenerator.js.map +1 -0
- package/dist/generator/templateEngine.d.ts +13 -0
- package/dist/generator/templateEngine.d.ts.map +1 -0
- package/dist/generator/templateEngine.js +146 -0
- package/dist/generator/templateEngine.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +32 -0
- package/dist/index.js.map +1 -0
- package/dist/parser/catalogParser.d.ts +13 -0
- package/dist/parser/catalogParser.d.ts.map +1 -0
- package/dist/parser/catalogParser.js +120 -0
- package/dist/parser/catalogParser.js.map +1 -0
- package/dist/tools/generate-codes.d.ts +14 -0
- package/dist/tools/generate-codes.d.ts.map +1 -0
- package/dist/tools/generate-codes.js +274 -0
- package/dist/tools/generate-codes.js.map +1 -0
- package/dist/tools/generate-sea-pair.d.ts +14 -0
- package/dist/tools/generate-sea-pair.d.ts.map +1 -0
- package/dist/tools/generate-sea-pair.js +111 -0
- package/dist/tools/generate-sea-pair.js.map +1 -0
- package/dist/types/index.d.ts +117 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +5 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/audioUtils.d.ts +9 -0
- package/dist/utils/audioUtils.d.ts.map +1 -0
- package/dist/utils/audioUtils.js +67 -0
- package/dist/utils/audioUtils.js.map +1 -0
- package/dist/utils/configUtils.d.ts +11 -0
- package/dist/utils/configUtils.d.ts.map +1 -0
- package/dist/utils/configUtils.js +50 -0
- package/dist/utils/configUtils.js.map +1 -0
- package/dist/utils/fileUtils.d.ts +14 -0
- package/dist/utils/fileUtils.d.ts.map +1 -0
- package/dist/utils/fileUtils.js +73 -0
- package/dist/utils/fileUtils.js.map +1 -0
- package/examples/artist-free/README.md +36 -0
- package/examples/artist-paycurtain/README.md +49 -0
- package/examples/label/README.md +33 -0
- package/gundb-keypair.json +8 -0
- package/logo.svg +30 -0
- package/package-lock.json +1176 -0
- package/package.json +42 -0
- package/public/assets/community-registry.js +291 -0
- package/public/assets/download-stats.js +263 -0
- package/public/assets/player.js +219 -0
- package/public/assets/style.css +1170 -0
- package/public/assets/theme-widget.js +353 -0
- package/public/assets/unlock-codes.js +225 -0
- package/public/atom.xml +22 -0
- package/public/catalog.m3u +3 -0
- package/public/feed.xml +22 -0
- package/public/image.png +0 -0
- package/public/index.html +249 -0
- package/public/logo.svg +30 -0
- package/public/releases/chirichetto/Homologo - Chirichetto.wav +0 -0
- package/public/releases/chirichetto/cover.png +0 -0
- package/public/releases/chirichetto/embed-code.txt +16 -0
- package/public/releases/chirichetto/embed-compact.txt +8 -0
- package/public/releases/chirichetto/embed.html +39 -0
- package/public/releases/chirichetto/index.html +389 -0
- package/public/releases/chirichetto/playlist.m3u +3 -0
- package/templates/dark/assets/community-registry.js +291 -0
- package/templates/dark/assets/download-stats.js +263 -0
- package/templates/dark/assets/player.js +219 -0
- package/templates/dark/assets/style.css +740 -0
- package/templates/dark/index.hbs +73 -0
- package/templates/dark/layout.hbs +84 -0
- package/templates/dark/release.hbs +212 -0
- package/templates/default/assets/community-registry.js +291 -0
- package/templates/default/assets/download-stats.js +263 -0
- package/templates/default/assets/player.js +219 -0
- package/templates/default/assets/style.css +1170 -0
- package/templates/default/assets/theme-widget.js +353 -0
- package/templates/default/assets/unlock-codes.js +225 -0
- package/templates/default/index.hbs +188 -0
- package/templates/default/layout.hbs +117 -0
- package/templates/default/release.hbs +553 -0
- package/templates/minimal/assets/community-registry.js +291 -0
- package/templates/minimal/assets/download-stats.js +263 -0
- package/templates/minimal/assets/player.js +219 -0
- package/templates/minimal/assets/style.css +796 -0
- package/templates/minimal/index.hbs +73 -0
- package/templates/minimal/layout.hbs +84 -0
- package/templates/minimal/release.hbs +212 -0
- package/templates/retro/assets/community-registry.js +291 -0
- package/templates/retro/assets/download-stats.js +263 -0
- package/templates/retro/assets/player.js +219 -0
- package/templates/retro/assets/style.css +872 -0
- package/templates/retro/index.hbs +73 -0
- package/templates/retro/layout.hbs +84 -0
- package/templates/retro/release.hbs +212 -0
- package/templates/translucent/assets/community-registry.js +291 -0
- package/templates/translucent/assets/download-stats.js +263 -0
- package/templates/translucent/assets/player.js +219 -0
- package/templates/translucent/assets/style.css +1352 -0
- package/templates/translucent/index.hbs +73 -0
- package/templates/translucent/layout.hbs +84 -0
- package/templates/translucent/release.hbs +212 -0
- package/website/community.html +492 -0
- package/website/index.html +195 -0
- package/website/styles.css +396 -0
- package/website/tunecamp.svg +30 -0
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tunecamp Download Stats - GunDB Client
|
|
3
|
+
* Decentralized download counter using GunDB public peers
|
|
4
|
+
*
|
|
5
|
+
* Uses a public GunDB space to track and display download counts.
|
|
6
|
+
* No authentication required - anyone can read/increment counts.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
(function() {
|
|
10
|
+
'use strict';
|
|
11
|
+
|
|
12
|
+
// Default public GunDB peers
|
|
13
|
+
const DEFAULT_PEERS = [
|
|
14
|
+
'https://gun.defucc.me/gun',
|
|
15
|
+
'https://gun.o8.is/gun',
|
|
16
|
+
'https://shogun-relay.scobrudot.dev/gun',
|
|
17
|
+
'https://relay.peer.ooo/gun',
|
|
18
|
+
];
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* TunecampDownloadStats class
|
|
22
|
+
* Tracks download counts via GunDB
|
|
23
|
+
*/
|
|
24
|
+
class TunecampDownloadStats {
|
|
25
|
+
/**
|
|
26
|
+
* Initialize the download stats system
|
|
27
|
+
* @param {Object} options - Configuration options
|
|
28
|
+
* @param {Array} options.peers - GunDB peer URLs (default: public peers)
|
|
29
|
+
* @param {string} options.namespace - GunDB namespace (default: 'tunecamp-stats')
|
|
30
|
+
*/
|
|
31
|
+
constructor(options = {}) {
|
|
32
|
+
this.peers = options.peers || DEFAULT_PEERS;
|
|
33
|
+
this.root = options.root || 'shogun';
|
|
34
|
+
this.namespace = options.namespace || 'tunecamp-stats';
|
|
35
|
+
this.gun = null;
|
|
36
|
+
this.initialized = false;
|
|
37
|
+
|
|
38
|
+
// Initialize GunDB when script loads
|
|
39
|
+
this.init();
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Initialize GunDB connection
|
|
44
|
+
*/
|
|
45
|
+
async init() {
|
|
46
|
+
// Check if Gun is available
|
|
47
|
+
if (typeof Gun === 'undefined') {
|
|
48
|
+
console.warn('GunDB not loaded. Download stats disabled.');
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Initialize Gun with peers
|
|
53
|
+
this.gun = Gun({
|
|
54
|
+
peers: this.peers,
|
|
55
|
+
localStorage: true,
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
this.initialized = true;
|
|
59
|
+
console.log('📊 Tunecamp Download Stats initialized');
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Wait for Gun to be ready
|
|
64
|
+
*/
|
|
65
|
+
async waitForInit() {
|
|
66
|
+
if (this.initialized) return;
|
|
67
|
+
|
|
68
|
+
return new Promise((resolve, reject) => {
|
|
69
|
+
let attempts = 0;
|
|
70
|
+
const maxAttempts = 50; // 5 seconds max
|
|
71
|
+
|
|
72
|
+
const check = () => {
|
|
73
|
+
if (this.initialized) {
|
|
74
|
+
resolve();
|
|
75
|
+
} else if (attempts >= maxAttempts) {
|
|
76
|
+
reject(new Error('GunDB initialization timeout'));
|
|
77
|
+
} else {
|
|
78
|
+
attempts++;
|
|
79
|
+
setTimeout(check, 100);
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
check();
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Get download count for a release
|
|
88
|
+
* @param {string} releaseSlug - The release identifier
|
|
89
|
+
* @returns {Promise<number>} Download count
|
|
90
|
+
*/
|
|
91
|
+
async getDownloadCount(releaseSlug) {
|
|
92
|
+
try {
|
|
93
|
+
await this.waitForInit();
|
|
94
|
+
} catch (e) {
|
|
95
|
+
return 0;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if (!this.gun) return 0;
|
|
99
|
+
|
|
100
|
+
return new Promise((resolve) => {
|
|
101
|
+
this.gun
|
|
102
|
+
.get(this.root).get(this.namespace)
|
|
103
|
+
.get('releases')
|
|
104
|
+
.get(releaseSlug)
|
|
105
|
+
.get('downloads')
|
|
106
|
+
.once((data) => {
|
|
107
|
+
resolve(data ? parseInt(data, 10) || 0 : 0);
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
// Timeout fallback
|
|
111
|
+
setTimeout(() => resolve(0), 3000);
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Get download count for a specific track
|
|
117
|
+
* @param {string} releaseSlug - The release identifier
|
|
118
|
+
* @param {string} trackId - The track identifier (filename or index)
|
|
119
|
+
* @returns {Promise<number>} Download count
|
|
120
|
+
*/
|
|
121
|
+
async getTrackDownloadCount(releaseSlug, trackId) {
|
|
122
|
+
try {
|
|
123
|
+
await this.waitForInit();
|
|
124
|
+
} catch (e) {
|
|
125
|
+
return 0;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if (!this.gun) return 0;
|
|
129
|
+
|
|
130
|
+
return new Promise((resolve) => {
|
|
131
|
+
this.gun
|
|
132
|
+
.get(this.root).get(this.namespace)
|
|
133
|
+
.get('releases')
|
|
134
|
+
.get(releaseSlug)
|
|
135
|
+
.get('tracks')
|
|
136
|
+
.get(trackId)
|
|
137
|
+
.get('downloads')
|
|
138
|
+
.once((data) => {
|
|
139
|
+
resolve(data ? parseInt(data, 10) || 0 : 0);
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
// Timeout fallback
|
|
143
|
+
setTimeout(() => resolve(0), 3000);
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Increment download count for a release
|
|
149
|
+
* @param {string} releaseSlug - The release identifier
|
|
150
|
+
* @returns {Promise<number>} New download count
|
|
151
|
+
*/
|
|
152
|
+
async incrementDownloadCount(releaseSlug) {
|
|
153
|
+
try {
|
|
154
|
+
await this.waitForInit();
|
|
155
|
+
} catch (e) {
|
|
156
|
+
return 0;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
if (!this.gun) return 0;
|
|
160
|
+
|
|
161
|
+
const currentCount = await this.getDownloadCount(releaseSlug);
|
|
162
|
+
const newCount = currentCount + 1;
|
|
163
|
+
|
|
164
|
+
return new Promise((resolve) => {
|
|
165
|
+
this.gun
|
|
166
|
+
.get(this.root).get(this.namespace)
|
|
167
|
+
.get('releases')
|
|
168
|
+
.get(releaseSlug)
|
|
169
|
+
.get('downloads')
|
|
170
|
+
.put(newCount, (ack) => {
|
|
171
|
+
if (ack.err) {
|
|
172
|
+
console.error('Error incrementing download count:', ack.err);
|
|
173
|
+
resolve(currentCount);
|
|
174
|
+
} else {
|
|
175
|
+
resolve(newCount);
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
// Timeout fallback
|
|
180
|
+
setTimeout(() => resolve(newCount), 2000);
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Increment download count for a specific track
|
|
186
|
+
* @param {string} releaseSlug - The release identifier
|
|
187
|
+
* @param {string} trackId - The track identifier
|
|
188
|
+
* @returns {Promise<number>} New download count
|
|
189
|
+
*/
|
|
190
|
+
async incrementTrackDownloadCount(releaseSlug, trackId) {
|
|
191
|
+
try {
|
|
192
|
+
await this.waitForInit();
|
|
193
|
+
} catch (e) {
|
|
194
|
+
return 0;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
if (!this.gun) return 0;
|
|
198
|
+
|
|
199
|
+
const currentCount = await this.getTrackDownloadCount(releaseSlug, trackId);
|
|
200
|
+
const newCount = currentCount + 1;
|
|
201
|
+
|
|
202
|
+
return new Promise((resolve) => {
|
|
203
|
+
this.gun
|
|
204
|
+
.get(this.root).get(this.namespace)
|
|
205
|
+
.get('releases')
|
|
206
|
+
.get(releaseSlug)
|
|
207
|
+
.get('tracks')
|
|
208
|
+
.get(trackId)
|
|
209
|
+
.get('downloads')
|
|
210
|
+
.put(newCount, (ack) => {
|
|
211
|
+
if (ack.err) {
|
|
212
|
+
console.error('Error incrementing track download count:', ack.err);
|
|
213
|
+
resolve(currentCount);
|
|
214
|
+
} else {
|
|
215
|
+
resolve(newCount);
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
// Timeout fallback
|
|
220
|
+
setTimeout(() => resolve(newCount), 2000);
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Subscribe to download count changes (real-time updates)
|
|
226
|
+
* @param {string} releaseSlug - The release identifier
|
|
227
|
+
* @param {function} callback - Called with new count on each update
|
|
228
|
+
*/
|
|
229
|
+
subscribeToDownloadCount(releaseSlug, callback) {
|
|
230
|
+
if (!this.gun) {
|
|
231
|
+
callback(0);
|
|
232
|
+
return () => {};
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
const ref = this.gun
|
|
236
|
+
.get(this.root).get(this.namespace)
|
|
237
|
+
.get('releases')
|
|
238
|
+
.get(releaseSlug)
|
|
239
|
+
.get('downloads');
|
|
240
|
+
|
|
241
|
+
ref.on((data) => {
|
|
242
|
+
callback(data ? parseInt(data, 10) || 0 : 0);
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
// Return unsubscribe function
|
|
246
|
+
return () => ref.off();
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* Format download count for display
|
|
251
|
+
* @param {number} count - Download count
|
|
252
|
+
* @returns {string} Formatted string (e.g., "1.2K", "3.5M")
|
|
253
|
+
*/
|
|
254
|
+
formatCount(count) {
|
|
255
|
+
if (count < 1000) return count.toString();
|
|
256
|
+
if (count < 1000000) return (count / 1000).toFixed(1).replace(/\.0$/, '') + 'K';
|
|
257
|
+
return (count / 1000000).toFixed(1).replace(/\.0$/, '') + 'M';
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
// Expose globally
|
|
262
|
+
window.TunecampDownloadStats = TunecampDownloadStats;
|
|
263
|
+
})();
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
// Tunecamp Audio Player
|
|
2
|
+
|
|
3
|
+
class AudioPlayer {
|
|
4
|
+
constructor() {
|
|
5
|
+
this.audio = new Audio();
|
|
6
|
+
this.currentTrack = 0;
|
|
7
|
+
this.isPlaying = false;
|
|
8
|
+
this.tracks = window.tracks || [];
|
|
9
|
+
|
|
10
|
+
this.initElements();
|
|
11
|
+
this.attachListeners();
|
|
12
|
+
this.loadTrack(0);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
initElements() {
|
|
16
|
+
this.playBtn = document.getElementById('playBtn');
|
|
17
|
+
this.prevBtn = document.getElementById('prevBtn');
|
|
18
|
+
this.nextBtn = document.getElementById('nextBtn');
|
|
19
|
+
this.progressBar = document.getElementById('progressBar');
|
|
20
|
+
this.volumeBar = document.getElementById('volumeBar');
|
|
21
|
+
this.currentTimeEl = document.getElementById('currentTime');
|
|
22
|
+
this.durationEl = document.getElementById('duration');
|
|
23
|
+
this.playerTitle = document.getElementById('playerTitle');
|
|
24
|
+
this.playerArtist = document.getElementById('playerArtist');
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
attachListeners() {
|
|
28
|
+
// Play/Pause
|
|
29
|
+
if (this.playBtn) {
|
|
30
|
+
this.playBtn.addEventListener('click', () => this.togglePlay());
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Previous track
|
|
34
|
+
if (this.prevBtn) {
|
|
35
|
+
this.prevBtn.addEventListener('click', () => this.previousTrack());
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Next track
|
|
39
|
+
if (this.nextBtn) {
|
|
40
|
+
this.nextBtn.addEventListener('click', () => this.nextTrack());
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Progress bar
|
|
44
|
+
if (this.progressBar) {
|
|
45
|
+
this.progressBar.addEventListener('input', (e) => {
|
|
46
|
+
const time = (this.audio.duration / 100) * e.target.value;
|
|
47
|
+
this.audio.currentTime = time;
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Volume
|
|
52
|
+
if (this.volumeBar) {
|
|
53
|
+
this.volumeBar.addEventListener('input', (e) => {
|
|
54
|
+
this.audio.volume = e.target.value / 100;
|
|
55
|
+
});
|
|
56
|
+
this.audio.volume = this.volumeBar.value / 100;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Audio events
|
|
60
|
+
this.audio.addEventListener('timeupdate', () => this.updateProgress());
|
|
61
|
+
this.audio.addEventListener('loadedmetadata', () => this.updateDuration());
|
|
62
|
+
this.audio.addEventListener('ended', () => this.nextTrack());
|
|
63
|
+
|
|
64
|
+
// Track click listeners
|
|
65
|
+
document.querySelectorAll('.track-item').forEach((item, index) => {
|
|
66
|
+
item.addEventListener('click', (e) => {
|
|
67
|
+
if (!e.target.closest('.track-download-btn')) {
|
|
68
|
+
this.playTrack(index);
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
loadTrack(index) {
|
|
75
|
+
if (!this.tracks[index]) return;
|
|
76
|
+
|
|
77
|
+
this.currentTrack = index;
|
|
78
|
+
const track = this.tracks[index];
|
|
79
|
+
|
|
80
|
+
this.audio.src = track.url;
|
|
81
|
+
|
|
82
|
+
if (this.playerTitle) {
|
|
83
|
+
this.playerTitle.textContent = track.title;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (this.playerArtist && track.artist) {
|
|
87
|
+
this.playerArtist.textContent = track.artist;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Update active track in list
|
|
91
|
+
document.querySelectorAll('.track-item').forEach((item, i) => {
|
|
92
|
+
if (i === index) {
|
|
93
|
+
item.classList.add('playing');
|
|
94
|
+
} else {
|
|
95
|
+
item.classList.remove('playing');
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
togglePlay() {
|
|
101
|
+
if (this.isPlaying) {
|
|
102
|
+
this.pause();
|
|
103
|
+
} else {
|
|
104
|
+
this.play();
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
play() {
|
|
109
|
+
this.audio.play();
|
|
110
|
+
this.isPlaying = true;
|
|
111
|
+
|
|
112
|
+
if (this.playBtn) {
|
|
113
|
+
this.playBtn.innerHTML = '<i class="fas fa-pause"></i>';
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
pause() {
|
|
118
|
+
this.audio.pause();
|
|
119
|
+
this.isPlaying = false;
|
|
120
|
+
|
|
121
|
+
if (this.playBtn) {
|
|
122
|
+
this.playBtn.innerHTML = '<i class="fas fa-play"></i>';
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
playTrack(index) {
|
|
127
|
+
this.loadTrack(index);
|
|
128
|
+
this.play();
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
previousTrack() {
|
|
132
|
+
let prev = this.currentTrack - 1;
|
|
133
|
+
if (prev < 0) {
|
|
134
|
+
prev = this.tracks.length - 1;
|
|
135
|
+
}
|
|
136
|
+
this.playTrack(prev);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
nextTrack() {
|
|
140
|
+
let next = this.currentTrack + 1;
|
|
141
|
+
if (next >= this.tracks.length) {
|
|
142
|
+
next = 0;
|
|
143
|
+
}
|
|
144
|
+
this.playTrack(next);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
updateProgress() {
|
|
148
|
+
if (!this.audio.duration) return;
|
|
149
|
+
|
|
150
|
+
const percent = (this.audio.currentTime / this.audio.duration) * 100;
|
|
151
|
+
|
|
152
|
+
if (this.progressBar) {
|
|
153
|
+
this.progressBar.value = percent;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
if (this.currentTimeEl) {
|
|
157
|
+
this.currentTimeEl.textContent = this.formatTime(this.audio.currentTime);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
updateDuration() {
|
|
162
|
+
if (this.durationEl) {
|
|
163
|
+
this.durationEl.textContent = this.formatTime(this.audio.duration);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
formatTime(seconds) {
|
|
168
|
+
if (!seconds || isNaN(seconds)) return '0:00';
|
|
169
|
+
|
|
170
|
+
const mins = Math.floor(seconds / 60);
|
|
171
|
+
const secs = Math.floor(seconds % 60);
|
|
172
|
+
return `${mins}:${secs.toString().padStart(2, '0')}`;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// Initialize player when DOM is ready
|
|
177
|
+
if (document.readyState === 'loading') {
|
|
178
|
+
document.addEventListener('DOMContentLoaded', () => {
|
|
179
|
+
if (window.tracks && window.tracks.length > 0) {
|
|
180
|
+
window.player = new AudioPlayer();
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
} else {
|
|
184
|
+
if (window.tracks && window.tracks.length > 0) {
|
|
185
|
+
window.player = new AudioPlayer();
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// Global function for track buttons
|
|
190
|
+
function playTrack(index) {
|
|
191
|
+
if (window.player) {
|
|
192
|
+
window.player.playTrack(index);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// Download all function
|
|
197
|
+
function downloadAll() {
|
|
198
|
+
// Call tracking hook if registered (for download stats)
|
|
199
|
+
if (typeof window.onDownloadAll === 'function') {
|
|
200
|
+
try {
|
|
201
|
+
window.onDownloadAll();
|
|
202
|
+
} catch (e) {
|
|
203
|
+
console.warn('Download tracking error:', e);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// Perform the actual downloads
|
|
208
|
+
if (window.tracks) {
|
|
209
|
+
window.tracks.forEach(track => {
|
|
210
|
+
const a = document.createElement('a');
|
|
211
|
+
a.href = track.url;
|
|
212
|
+
a.download = track.title;
|
|
213
|
+
document.body.appendChild(a);
|
|
214
|
+
a.click();
|
|
215
|
+
document.body.removeChild(a);
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|