Skip to content

Commit

Permalink
tweak music detection and fix certain errors relating to it
Browse files Browse the repository at this point in the history
  • Loading branch information
sylviiu committed May 28, 2024
1 parent 004be50 commit 4608e7c
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 6 deletions.
2 changes: 1 addition & 1 deletion build.js
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ if(require.main == module) {

console.log(`Spawning npm with args "${procArgs.join(` `)}"`);

const proc = child_process.spawn(npm, procArgs, { stdio: "inherit" });
const proc = child_process.spawn(npm, procArgs, { stdio: "inherit", shell: true });

proc.on(`close`, async (code) => {
console.log(`Build closed with code ${code}`);
Expand Down
18 changes: 15 additions & 3 deletions html/afterload/conversionOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,9 @@ const conversionOptions = (node, info, colorScheme) => {

metaButtons.forEach(m => {
if(m.id == `opt-saveMusicData` && !auth.spotify) {
setupDisabledButtonWithReason(m, `Spotify not set up!`, `To save extra data such as the BPM / initial key of a song, ezytdl will need to cross reference it with Spotify. Please set up Spotify in the settings and try again!`)
m.setAttribute(`value`, `false`);
m.style.display = `none`;
//setupDisabledButtonWithReason(m, `Spotify not set up!`, `To save extra data such as the BPM / initial key of a song, ezytdl will need to cross reference it with Spotify. Please set up Spotify in the settings and try again!`)
} else {
const icon = m.querySelector(`#icon`);

Expand Down Expand Up @@ -638,7 +640,11 @@ const conversionOptions = (node, info, colorScheme) => {
easing: `easeOutExpo`,
})
}
}
};

if(m.id == `opt-saveMusicData` && !(info.genres || info.genre)) {
while(m.getAttribute(`value`) != `false`) m.onclick();
};
}
});

Expand Down Expand Up @@ -731,7 +737,13 @@ const conversionOptions = (node, info, colorScheme) => {
}
}
} else {
metaButtons.forEach(m => setupDisabledButtonWithReason(m, `FFmpeg not found!`, `FFmpeg is required to add metadata. Please install FFmpeg and try again.`));
metaButtons.forEach(m => {
if(m.id == `opt-saveMusicData` && !auth.spotify) {
m.setAttribute(`value`, `false`);
m.style.display = `none`;
//setupDisabledButtonWithReason(m, `Spotify not set up!`, `To save extra data such as the BPM / initial key of a song, ezytdl will need to cross reference it with Spotify. Please set up Spotify in the settings and try again!`)
} else setupDisabledButtonWithReason(m, `FFmpeg not found!`, `FFmpeg is required to add metadata. Please install FFmpeg and try again.`)
});

console.log(node.querySelector(`#confirmDownload`).parentElement, node.querySelector(`#convertDownload`))

Expand Down
4 changes: 2 additions & 2 deletions util/ytdlp.js
Original file line number Diff line number Diff line change
Expand Up @@ -3236,7 +3236,7 @@ const ytdlpObj = {
const originalTitle = thisInfo.media_metadata.general.title;
const originalArtist = thisInfo.media_metadata.general.artist;

resultsInfo.entries = resultsInfo.entries.map(result => {
resultsInfo.entries = resultsInfo.entries?.map(result => {
const { title, artist } = result.media_metadata.general;

result.similarities = {};
Expand Down Expand Up @@ -3305,7 +3305,7 @@ const ytdlpObj = {
return result;
} else return undefined; // if this result doesn't have a duration, AND other results have durations, don't return it
} else return undefined;
});
}) || [];

resultsInfo.entries = resultsInfo.entries.filter(a => a && a !== undefined && typeof a == `object` && typeof a.similarity == `number`).sort((a, b) => b.similarity - a.similarity);

Expand Down
22 changes: 22 additions & 0 deletions util/ytdlpUtil/qualitySorter.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const numRegex = /-?\d+(\.\d+)?/g;

const sorters = {
// go by a.quality and b.quality, higher should go first
// if there is no quality, send before the ones with quality
Expand All @@ -19,6 +21,26 @@ const sorters = {
},
filter: [`audio`, `video`]
},
formatID: {
func: (a,b) => {
const aID = Number(a.format_id?.match(numRegex)?.[0] || undefined);
const bID = Number(b.format_id?.match(numRegex)?.[0] || undefined);
if(aID || bID) {
if(aID == bID) {
return 0;
} else if(aID > bID) {
return -1;
} else if(aID < bID) {
return 1;
} else if(aID && !bID) {
return -1;
} else if(bID && !aID) {
return 1;
} else return 0;
} else return 0;
},
filter: [`audio`, `video`]
},
videoQuality: {
func: (a,b) => {
if(a.width || a.height || b.width || b.height) {
Expand Down

0 comments on commit 4608e7c

Please sign in to comment.