@@ -254,6 +254,8 @@ extension.on("subscribe_zones", (core, response, body) => {
254254 } ) ;
255255} ) ;
256256
257+ //figure out if we're played or paused to update the small image
258+
257259function determinePlaybackStatus ( ) {
258260 var playStatus = trackInfo [ "playback_status" ] ;
259261 switch ( trackInfo [ "playback_status" ] ) {
@@ -273,6 +275,8 @@ client.on("error", async (err) => {
273275 outputLog ( logTypes . err , "Error from Discord RPC interface:\n" + err ) ;
274276} ) ;
275277
278+ //initial RPC call
279+
276280client . on ( "ready" , async ( ) => {
277281 await client . user ?. setActivity ( {
278282 state : trackInfo [ "artist" ] + " — " + trackInfo [ "album" ] ,
@@ -287,6 +291,8 @@ client.on("ready", async () => {
287291 } ) ;
288292} ) ;
289293
294+ //function to make repeated RPC calls
295+
290296async function updateRPC ( artlink ) {
291297 await client . user ?. setActivity ( {
292298 state : trackInfo [ "artist" ] + " — " + trackInfo [ "album" ] ,
@@ -301,6 +307,8 @@ async function updateRPC(artlink) {
301307 } ) ;
302308}
303309
310+ //let's figure out what the user preferred for album art, and go from there.
311+
304312async function startAlbumArtOperation ( albumartString , albumInput , artistString , reason ) {
305313 const found = await findInCache ( cachedArt , albumInput ) ;
306314 if ( configParams . artUploadMethod !== "musicbrainz" && configParams . artUploadMethod !== "none" ) {
@@ -338,6 +346,8 @@ async function startAlbumArtOperation(albumartString, albumInput, artistString,
338346 }
339347} ;
340348
349+ //convoluted MusicBrainz to Cover Art Archive search function
350+
341351async function fetchFromMusicBrainz ( artistString , albumInput , callback ) {
342352 outputLog ( logTypes . info , "Returning match from MusicBrainz to RPC." )
343353 const encodedArtist = encodeURIComponent ( artistString ) ;
@@ -361,13 +371,15 @@ async function fetchFromMusicBrainz(artistString, albumInput, callback) {
361371 } )
362372}
363373
374+ //let's give Imgur some form-data and an API key, as a little treat.
375+
364376async function imgurUploadArt ( imgBuf , albumInput , callback ) {
365377 outputLog ( logTypes . info , "Uploading album art to Imgur." )
366378 var config = {
367379 headers : { 'Authorization' : `Client-ID ${ configParams . imgurImage . imgurClientId } ` }
368380 }
369381 const form = new FormData ( ) ;
370- const fileName = await makeFileID ( )
382+ const fileName = await makeFileID ( 12 )
371383 form . append ( configParams . imgurImage . imgurUploadKey , imgBuf , { filename : `${ fileName } .jpg` } ) ;
372384 form . append ( 'type' , configParams . imgurImage . imgurFileType )
373385 axios . post ( configParams . imgurImage . imgurUrl , form , config ) . then ( ( { data} ) => {
@@ -380,10 +392,12 @@ async function imgurUploadArt(imgBuf, albumInput, callback) {
380392 } )
381393}
382394
395+ //if you're selfhosting, good for you. I like that.
396+
383397async function selfUploadArt ( imgBuf , albumInput , callback ) {
384398 outputLog ( logTypes . info , "Uploading album art to self-hosted service." )
385399 const form = new FormData ( ) ;
386- const fileName = await makeFileID ( )
400+ const fileName = await makeFileID ( 12 )
387401 form . append ( 'file' , Buffer . from ( imgBuf ) , { filename : `${ fileName } .jpg` } ) ;
388402 form . append ( 'type' , configParams . selfServiceImage . formImageType )
389403 if ( configParams . selfServiceImage . endpointAuthTokenType !== "" ) {
@@ -411,6 +425,8 @@ async function selfUploadArt(imgBuf, albumInput, callback) {
411425 }
412426}
413427
428+ //just to save some bandwidth, let's cache those links in a little json file to call later.
429+
414430function cacheArtUrl ( artLink , albumInput , source ) {
415431 cachedArt . push ( { "album" : albumInput , "link" : artLink } )
416432 fs . writeFile ( "cached_art.json" , JSON . stringify ( cachedArt ) , ( err ) => {
@@ -421,6 +437,7 @@ function cacheArtUrl(artLink, albumInput, source) {
421437 } ) ;
422438}
423439
440+ //let's look for an album in cache before we go any further
424441
425442async function findInCache ( cache , albumInput ) {
426443 const cacheSearch = cache . find ( ( { album } ) => album === albumInput ) ;
@@ -431,6 +448,8 @@ async function findInCache(cache, albumInput) {
431448 }
432449}
433450
451+ //random alphanumeric file name generator cause why not?
452+
434453async function makeFileID ( length ) {
435454 let result = '' ;
436455 const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789' ;
0 commit comments