load ytmusic stuffs from cache and add dev logging #7
22
index.js
22
index.js
@@ -89,7 +89,7 @@ async function updateSongs() {
|
|||||||
// For each song that youtube moosic has yelled back at us, give them individually to populateThumbnails()
|
// For each song that youtube moosic has yelled back at us, give them individually to populateThumbnails()
|
||||||
await Promise.all(playlistSongs.map(async song => await populateThumbnails(song)));
|
await Promise.all(playlistSongs.map(async song => await populateThumbnails(song)));
|
||||||
// Write all of this to cache
|
// Write all of this to cache
|
||||||
fs.writeFileSync(path.join(baseDir + 'ytmusic_cache'), JSON.stringify({playlistSongs, thumbnails}));
|
fs.writeFileSync(path.join(baseDir + '/ytmusic_cache'), JSON.stringify({playlistSongs, thumbnails}));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// like legit this shouldnt even be possible
|
// like legit this shouldnt even be possible
|
||||||
@@ -298,15 +298,25 @@ async function customConsole() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wrap in a async function to wait for youtube music response before starting http server
|
|
||||||
// (to prevent a race condition where people can view the moosic page be4 it is ready)
|
|
||||||
async function main() {
|
async function main() {
|
||||||
|
|
||||||
// Init the moosics stuff (black magic)
|
// Load from cache
|
||||||
|
await (async () => {
|
||||||
|
let cachefile;
|
||||||
|
cachefile = fs.readFileSync(path.join(baseDir, '/ytmusic_cache'));
|
||||||
|
let parsed_cachefile = JSON.parse(cachefile);
|
||||||
|
playlistSongs = parsed_cachefile.playlistSongs;
|
||||||
|
thumbnails = parsed_cachefile.thumbnails;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Wrap in async but don't await as to not delay server boot, we can load from cache faster then we can load from yt music
|
||||||
|
(async () => {
|
||||||
|
// Init the moosics stuff
|
||||||
await ytmusic.initialize();
|
await ytmusic.initialize();
|
||||||
|
|
||||||
// Populate playlistSongs and thumbnails
|
// Populate playlistSongs and thumbnails
|
||||||
await updateSongs();
|
await updateSongs();
|
||||||
|
});
|
||||||
|
|
||||||
// Populate the blog index
|
// Populate the blog index
|
||||||
await generateBlogIndex();
|
await generateBlogIndex();
|
||||||
@@ -319,11 +329,11 @@ async function main() {
|
|||||||
|
|
||||||
// Start hourly loop to update playlist
|
// Start hourly loop to update playlist
|
||||||
loopHourly(async () => await updateSongs());
|
loopHourly(async () => await updateSongs());
|
||||||
});
|
|
||||||
})();
|
|
||||||
|
|
||||||
// Start console
|
// Start console
|
||||||
customConsole();
|
customConsole();
|
||||||
|
});
|
||||||
|
})();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle a few signals
|
// Handle a few signals
|
||||||
|
|||||||
Reference in New Issue
Block a user