fix some issues regarding the api :3

This commit is contained in:
Ashley 2022-09-23 18:54:05 +02:00
parent 008d2b30b4
commit ce16fffe9d

View file

@ -15,6 +15,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see https://www.gnu.org/licenses/. along with this program. If not, see https://www.gnu.org/licenses/.
*/ */
const fetch = require("node-fetch"); //2.5.x const fetch = require("node-fetch"); //2.5.x
const { toJson } = require("xml2json"); const { toJson } = require("xml2json");
@ -28,14 +29,27 @@ module.exports = async function (video_id) {
); );
const dislikes = dislike.dislikes || "none"; const dislikes = dislike.dislikes || "none";
const headers = {};
/* /*
* Parses and fetches an xml * Parses and fetches an xml
*/ */
async function parsexml(id) { async function parsexml(id) {
const player = await fetch(`${new_api_url}?v=${id}`); for (let i = 0; i < 3; i++) {
var h = await player.text(); try {
var j = toJson(h); const player = await fetch(`${new_api_url}?v=${id}`, headers);
return JSON.parse(j); var h = await player.text();
var j = toJson(h);
return JSON.parse(j);
} catch (err) {
if (err.status === 503) {
// retry after a bit
await new Promise((resolve) => setTimeout(resolve, 1000));
} else {
return "";
}
}
}
} }
/* /*