diff --git a/js_modules/dl.js b/js_modules/dl.js
index b1a6a9d..2ffc62c 100644
--- a/js_modules/dl.js
+++ b/js_modules/dl.js
@@ -11,16 +11,71 @@ const wrap = document.getElementById('wrap');
const container = document.getElementById('downloadContainer');
const loading = document.getElementById('progress-bar');
-const createDownloadCard = (title, url, thumb) => {
- // const tempRes = res;
- // let quality = tempRes.match(/\((.*)\)/)?.pop();
- // if (!quality) quality = 'View';
+const addEntry = (u, res) => {
+ return `
+
+ `;
+};
+
+const addProResolutionEntries = (url, res) => {
+ const set = new Set();
+ res[0].forEach((e) => {
+ if (e < 720) set.add('SD');
+ else if (e < 1080) set.add('HD');
+ else if (e < 1440) set.add('FHD');
+ else if (e < 2160) set.add('QHD');
+ else if (e < 4320) set.add('UHD');
+ else if (e >= 4320) set.add('UHD+');
+ });
+
+ let elements = `
+
+ `;
+
+ set.forEach((e) => {
+ elements = addEntry(url, e) + elements;
+ });
+
+ return elements;
+};
+
+const addFreeResolutionEntries = (streams) => {
+ let elements = '';
+ Object.keys(streams).forEach((k) => {
+ let title;
+ if (!streams[k].stream.length) return;
+ if (k === 'bestVideoOnly') {
+ title = `${streams[k].info}P MUTED`;
+ } else if (streams[k].info === 'NA') {
+ title = 'AUDIO';
+ } else {
+ title = `${streams[k].info}P`;
+ }
+ if (title) {
+ elements = elements + addEntry(streams[k].stream, title);
+ }
+ });
+ return elements;
+};
+
+
+const createDownloadCard = (title, streams, thumb, resolutions) => {
+ const free = addFreeResolutionEntries(streams);
+ const pro = addProResolutionEntries('#', resolutions);
container.insertAdjacentHTML('beforeend', `
@@ -31,47 +86,14 @@ const createDownloadCard = (title, url, thumb) => {
FREE
-
@@ -143,9 +165,16 @@ export const parseDl = (event, url = null) => {
result.json().then((res) => {
console.log(res);
res.forEach((i) => {
- createDownloadCard(i.title, i.stream, i.thumbnail);
- console.log(i.source, i.resolutions);
loading.classList.add('hidden');
+ if (!i.resolutions.length) {
+ genericAlert(
+ `Something went wrong`,
+ i.err);
+ closeContainer();
+ return;
+ }
+ createDownloadCard(i.title, i.streams, i.thumbnail, i.resolutions);
+ console.log(i.source, i.err);
});
});
}).catch((e) => {