Skip to content
This repository has been archived by the owner on Oct 23, 2024. It is now read-only.

Commit

Permalink
fix: fixed video downloading not working on yt music ( #3 )
Browse files Browse the repository at this point in the history
  • Loading branch information
madkarmaa committed Feb 3, 2024
1 parent bbeb25d commit 0a1bd48
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions script.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,9 @@ input {
function Cobalt(videoUrl, audioOnly = false) {
// Use Promise because GM.xmlHttpRequest is async and behaves differently with different userscript managers
return new Promise((resolve, reject) => {
if (YOUTUBE_SERVICE === 'MUSIC') videoUrl = videoUrl.split('&')[0].replace('music.youtube', 'www.youtube');
logger('Parsed video url is:', videoUrl);

// https://github.com/wukko/cobalt/blob/current/docs/api.md
GM_xmlhttpRequest({
method: 'POST',
Expand Down Expand Up @@ -307,7 +310,8 @@ input {
if (!window.location.pathname.slice(1))
return notify('Hey!', 'The video/song player is not open, I cannot see the link to download!'); // do nothing if video is not focused

if (!VIDEO_DATA) return notify("The video data hasn't been loaded yet", 'Try again in a few seconds...');
if (YOUTUBE_SERVICE !== 'MUSIC' && !VIDEO_DATA)
return notify("The video data hasn't been loaded yet", 'Try again in a few seconds...');

try {
// window.open(await Cobalt(window.location.href), '_blank');
Expand Down Expand Up @@ -504,15 +508,15 @@ input {
const resetButton = document.createElement('button');
resetButton.textContent = 'Reset to default';
resetButton.addEventListener('click', () => {
codeTextArea.value = `(async () => {\n\n${Cobalt.toString()}\n\nwindow.open(await Cobalt('{{ video_url }}'), '_blank');\n\n})();`;
codeTextArea.value = `(async () => {\n\n${Cobalt.toString()}\n\nwindow.open(await Cobalt(window.location.href), '_blank');\n\n})();`;
logger('Code reset');
});

menuPopup.append(codeTextArea, resetButton);

codeTextArea.value =
localStorage.getItem('yt-dl-code') ||
`(async () => {\n\n${Cobalt.toString()}\n\nwindow.open(await Cobalt('{{ video_url }}'), '_blank');\n\n})();`;
`(async () => {\n\n${Cobalt.toString()}\n\nwindow.open(await Cobalt(window.location.href), '_blank');\n\n})();`;
localStorage.setItem('yt-dl-code', codeTextArea.value);
logger('Code retrieved and set to textarea');

Expand Down

0 comments on commit 0a1bd48

Please sign in to comment.