Skip to content

Commit

Permalink
fix: gotten rid of extra try-catch, changed fetchSafely to do what wa…
Browse files Browse the repository at this point in the history
…s trying to be achieved
  • Loading branch information
GreenDiscord committed May 22, 2024
1 parent 8bd1277 commit ec779c7
Showing 1 changed file with 7 additions and 17 deletions.
24 changes: 7 additions & 17 deletions src/rpc/format.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const config = cl.getOrInit('config.js');
const axios = require('axios');
const yt = require("ytsr");
const path = require("path");
const { debug } = require('console');

let staticOverridesFetcher = new (require('./staticOverridesFetcher.js'))(cl.getOrInit('staticoverrides.js'));
let musichoardersFetcher = new (require('./musichoardersFetcher.js'))(config.rpc.persistentMusicHoardersCache);
Expand All @@ -29,7 +30,6 @@ const fetchers = {
"apple": async (metadata) => { // Doesn't rely on MusicHoarders, keep it that way, just in case
if ((metadata.ALBUMARTIST || metadata.artist) && metadata.title)
{
try{
const result = await axios.get("https://itunes.apple.com/search", {
params: {
media: "music",
Expand All @@ -47,14 +47,10 @@ const fetchers = {
};
}
}
catch(err)
{ return console.log("Attempting to switch provider, Error Occured.");};
}
},
"bandcamp": async (metadata) => {
if ((metadata.ALBUMARTIST || metadata.artist) && (metadata.album || metadata.title))
{
try {
const result = await axios.post("https://bandcamp.com/api/bcsearch_public_api/1/autocomplete_elastic", {
fan_id: null,
full_page: false,
Expand All @@ -75,14 +71,10 @@ const fetchers = {
}
}
}
catch(err)
{ return console.log("Attempting to switch provider, Error Occured.");};
}
},
"coverartarchive": async (metadata) => {
if ((metadata.MUSICBRAINZ_ALBUMID) && metadata.title)
{
try {
const result = await axios.get("https://coverartarchive.org/release/" + metadata.MUSICBRAINZ_ALBUMID, {
headers: {"Accept-Encoding": "gzip,deflate,compress" }
})
Expand All @@ -96,9 +88,6 @@ const fetchers = {
};
}
}
catch(err)
{ return console.log("Attempting to switch provider, Error Occured.");};
}
},
"deezer": async (metadata) => {
//return musichoardersFetcher.fetch("deezer", metadata);
Expand Down Expand Up @@ -138,7 +127,6 @@ const fetchers = {
//return musichoardersFetcher.fetch("tidal", metadata);
},
"youtube": async (metadata) => {
try {
const result = await yt(`${metadata.ALBUMARTIST || metadata.artist || ""} ${metadata.title || metadata.filename}`.trim(), { limit: 1 });
if (result.items.length > 0)
{
Expand All @@ -150,9 +138,6 @@ const fetchers = {
};
}
}
catch(err)
{ return console.log("Attempting to switch provider, Error Occured.");};
}
}

/**
Expand All @@ -170,7 +155,12 @@ async function fetchSafely(fetcherName, metadata)
}
catch (err)
{
console.log(err);
if(debug == 'true'){
console.log(err);
} else {
console.log("Attempting to switch provider, Error Occured.");
}

}
finally
{
Expand Down

0 comments on commit ec779c7

Please sign in to comment.