basic song access, previews, difficulties
This commit is contained in:
@@ -10,6 +10,6 @@ AFRAME.registerComponent('menu-selected-challenge-image', {
|
||||
if (!this.data.selectedChallengeId) { return; }
|
||||
el.setAttribute(
|
||||
'material', 'src',
|
||||
utils.getS3FileUrl(this.data.selectedChallengeId, 'image.jpg'));
|
||||
this.data.selectedChallengeId);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -51,7 +51,7 @@ AFRAME.registerComponent('search-thumbnail-atlas', {
|
||||
for (let i = 0; i < results.length; i++) {
|
||||
let img = this.images[i] = this.images[i] || document.createElement('img');
|
||||
img.crossOrigin = 'anonymous';
|
||||
img.src = utils.getS3FileUrl(results[i].id, 'image.jpg');
|
||||
img.src = results[i].imageUrl;
|
||||
if (img.complete) {
|
||||
this.draw(img, i);
|
||||
} else {
|
||||
|
||||
@@ -1,5 +1,12 @@
|
||||
var algoliasearch = require('algoliasearch/lite');
|
||||
var bindEvent = require('aframe-event-decorators').bindEvent;
|
||||
var _ = require('lodash');
|
||||
const BeatSaverAPI = require('beatsaver-api');
|
||||
const api = new BeatSaverAPI({
|
||||
AppName: 'Application Name',
|
||||
Version: '1.0.0'
|
||||
});
|
||||
const zip = require("@zip.js/zip.js/dist/zip");
|
||||
|
||||
var client = algoliasearch('QULTOY3ZWU', 'be07164192471df7e97e6fa70c1d041d');
|
||||
var algolia = client.initIndex('supersaber');
|
||||
@@ -30,6 +37,7 @@ AFRAME.registerComponent('search', {
|
||||
|
||||
search: function (query) {
|
||||
// Use cached for popular hits.
|
||||
console.log(query);
|
||||
if (!query && this.popularHits) {
|
||||
this.eventDetail.results = this.popularHits;
|
||||
this.eventDetail.query = '';
|
||||
@@ -39,18 +47,52 @@ AFRAME.registerComponent('search', {
|
||||
|
||||
this.eventDetail.query = query;
|
||||
this.queryObject.query = query;
|
||||
algolia.search(this.queryObject, (err, content) => {
|
||||
// Cache popular hits.
|
||||
if (err) {
|
||||
this.el.sceneEl.emit('searcherror', null, false);
|
||||
console.error(err);
|
||||
return;
|
||||
}
|
||||
api.searchMaps({q:query}).then((results)=>{
|
||||
console.log(results);
|
||||
Promise.all(_.map(results.docs, async (result) => {
|
||||
let zipBlob = await fetch(result.versions[0].downloadURL).then(r => r.blob());
|
||||
const zipFileReader = new zip.BlobReader(zipBlob);
|
||||
const zipReader = new zip.ZipReader(zipFileReader);
|
||||
const files = await zipReader.getEntries();
|
||||
const info = _.find(files, {filename: "Info.dat"});
|
||||
//const infoStream = new TransformStream();
|
||||
//const infoPromise = new Response(infoStream.readable).text();
|
||||
const infoBlob = await info.getData(new zip.BlobWriter());
|
||||
const infoJson = JSON.parse(await infoBlob.text());
|
||||
console.log(infoJson);
|
||||
const songFile = _.find(files, {filename: infoJson._songFilename});
|
||||
const songBlob = await songFile.getData(new zip.BlobWriter());
|
||||
const songUrl = URL.createObjectURL(songBlob);
|
||||
console.log(songUrl);
|
||||
|
||||
if (!query) { this.popularHits = content.hits; }
|
||||
this.eventDetail.results = content.hits;
|
||||
this.el.sceneEl.emit('searchresults', this.eventDetail);
|
||||
});
|
||||
return {
|
||||
songName: result.metadata.songName,
|
||||
songSubName: result.metadata.songAuthorName,
|
||||
imageUrl: result.versions[0].coverURL,
|
||||
songUrl: songUrl,
|
||||
id: result.id,
|
||||
data: result,
|
||||
difficulties: _.map(infoJson._difficultyBeatmapSets[0]._difficultyBeatmaps, '_difficulty'),
|
||||
numBeats: result.metadata.duration,
|
||||
}
|
||||
})).then((tmpResults) => {
|
||||
this.eventDetail.results = tmpResults;
|
||||
console.log(tmpResults);
|
||||
this.el.sceneEl.emit('searchresults', this.eventDetail);
|
||||
});
|
||||
})
|
||||
// algolia.search(this.queryObject, (err, content) => {
|
||||
// // Cache popular hits.
|
||||
// if (err) {
|
||||
// this.el.sceneEl.emit('searcherror', null, false);
|
||||
// console.error(err);
|
||||
// return;
|
||||
// }
|
||||
|
||||
// if (!query) { this.popularHits = content.hits; }
|
||||
// this.eventDetail.results = content.hits;
|
||||
// this.el.sceneEl.emit('searchresults', this.eventDetail);
|
||||
// });
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -11,7 +11,8 @@ AFRAME.registerComponent('song-preview-system', {
|
||||
debug: {default: false},
|
||||
isSearching: {default: false},
|
||||
isSongLoading: {default: false}, // Continue to play preview song during loading.
|
||||
selectedChallengeId: {type: 'string'}
|
||||
selectedChallengeId: {type: 'string'},
|
||||
songUrl: {type: 'string'}
|
||||
},
|
||||
|
||||
init: function () {
|
||||
@@ -91,7 +92,7 @@ AFRAME.registerComponent('song-preview-system', {
|
||||
|
||||
// Preload.
|
||||
this.audioStore[data.selectedChallengeId].src =
|
||||
utils.getS3FileUrl(data.selectedChallengeId, 'song.ogg');
|
||||
data.songUrl;
|
||||
|
||||
// Remove from preload queue.
|
||||
for (let i = 0; i < preloadQueue.length; i++) {
|
||||
@@ -106,7 +107,7 @@ AFRAME.registerComponent('song-preview-system', {
|
||||
* Create an audio element and queue to preload. If the queue is empty, preload it
|
||||
* immediately.
|
||||
*/
|
||||
queuePreloadSong: function (challengeId, previewStartTime) {
|
||||
queuePreloadSong: function (challengeId, previewStartTime, songUrl) {
|
||||
if (this.audioStore[challengeId]) { return; }
|
||||
|
||||
const audio = document.createElement('audio');
|
||||
@@ -114,7 +115,7 @@ AFRAME.registerComponent('song-preview-system', {
|
||||
audio.dataset.previewStartTime = previewStartTime;
|
||||
this.audioStore[challengeId] = audio;
|
||||
|
||||
let src = utils.getS3FileUrl(challengeId, 'song.ogg');
|
||||
let src = songUrl;
|
||||
if (this.currentLoadingId) {
|
||||
// Audio currently loading, add to queue.
|
||||
this.preloadQueue.push({
|
||||
@@ -183,7 +184,7 @@ AFRAME.registerComponent('song-preview-system', {
|
||||
|
||||
// Prefetch buffer for playing.
|
||||
if (audioanalyser.xhr) { audioanalyser.xhr.abort(); }
|
||||
audioanalyser.fetchAudioBuffer(utils.getS3FileUrl(challengeId, 'song.ogg'));
|
||||
audioanalyser.fetchAudioBuffer(data.songUrl);
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -221,7 +222,7 @@ AFRAME.registerComponent('song-preview', {
|
||||
}
|
||||
|
||||
this.el.sceneEl.components['song-preview-system'].queuePreloadSong(
|
||||
this.data.challengeId, this.data.previewStartTime
|
||||
this.data.challengeId, this.data.previewStartTime, this.data.songUrl
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user