mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-17 13:12:07 +00:00
Merge pull request #463 from Araxeus/use-apiLoaded-event-for-time-update
Sponsorblock fix + use new apiLoaded event
This commit is contained in:
@ -88,7 +88,7 @@
|
|||||||
"ytpl": "^2.2.3"
|
"ytpl": "^2.2.3"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"electron": "^12.1.0",
|
"electron": "^12.2.2",
|
||||||
"electron-builder": "^22.10.5",
|
"electron-builder": "^22.10.5",
|
||||||
"electron-devtools-installer": "^3.1.1",
|
"electron-devtools-installer": "^3.1.1",
|
||||||
"electron-icon-maker": "0.0.5",
|
"electron-icon-maker": "0.0.5",
|
||||||
|
|||||||
@ -1,10 +1,7 @@
|
|||||||
const { ontimeupdate } = require("../../providers/video-element");
|
|
||||||
|
|
||||||
module.exports = () => {
|
module.exports = () => {
|
||||||
ontimeupdate((videoElement) => {
|
document.addEventListener('apiLoaded', () => {
|
||||||
if (videoElement.currentTime === 0 && videoElement.duration !== NaN) {
|
document.querySelector('video').addEventListener('loadeddata', e => {
|
||||||
// auto-confirm-when-paused plugin can interfere here if not disabled!
|
e.target.pause();
|
||||||
videoElement.pause();
|
})
|
||||||
}
|
}, { once: true, passive: true })
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|||||||
@ -9,7 +9,7 @@ module.exports = (options) => {
|
|||||||
document.addEventListener('apiLoaded', e => {
|
document.addEventListener('apiLoaded', e => {
|
||||||
api = e.detail;
|
api = e.detail;
|
||||||
firstRun(options);
|
firstRun(options);
|
||||||
})
|
}, { once: true, passive: true })
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Restore saved volume and setup tooltip */
|
/** Restore saved volume and setup tooltip */
|
||||||
|
|||||||
@ -9,7 +9,7 @@ const qualitySettingsButton = ElementFromFile(
|
|||||||
|
|
||||||
|
|
||||||
module.exports = () => {
|
module.exports = () => {
|
||||||
document.addEventListener('apiLoaded', setup);
|
document.addEventListener('apiLoaded', setup, { once: true, passive: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
function setup(event) {
|
function setup(event) {
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
const fetch = require("node-fetch");
|
const fetch = require("node-fetch");
|
||||||
|
const is = require("electron-is");
|
||||||
|
|
||||||
const defaultConfig = require("../../config/defaults");
|
const defaultConfig = require("../../config/defaults");
|
||||||
const registerCallback = require("../../providers/song-info");
|
const registerCallback = require("../../providers/song-info");
|
||||||
@ -24,6 +25,7 @@ module.exports = (win, options) => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
const fetchSegments = async (apiURL, categories) => {
|
const fetchSegments = async (apiURL, categories) => {
|
||||||
const sponsorBlockURL = `${apiURL}/api/skipSegments?videoID=${videoID}&categories=${JSON.stringify(
|
const sponsorBlockURL = `${apiURL}/api/skipSegments?videoID=${videoID}&categories=${JSON.stringify(
|
||||||
categories
|
categories
|
||||||
@ -45,7 +47,10 @@ const fetchSegments = async (apiURL, categories) => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
return sortedSegments;
|
return sortedSegments;
|
||||||
} catch {
|
} catch (e) {
|
||||||
|
if (is.dev()) {
|
||||||
|
console.log('error on sponsorblock request:', e);
|
||||||
|
}
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@ -2,8 +2,6 @@ const { ipcRenderer } = require("electron");
|
|||||||
|
|
||||||
const is = require("electron-is");
|
const is = require("electron-is");
|
||||||
|
|
||||||
const { ontimeupdate } = require("../../providers/video-element");
|
|
||||||
|
|
||||||
let currentSegments = [];
|
let currentSegments = [];
|
||||||
|
|
||||||
module.exports = () => {
|
module.exports = () => {
|
||||||
@ -11,17 +9,19 @@ module.exports = () => {
|
|||||||
currentSegments = segments;
|
currentSegments = segments;
|
||||||
});
|
});
|
||||||
|
|
||||||
ontimeupdate((videoElement) => {
|
document.addEventListener('apiLoaded', () => {
|
||||||
currentSegments.forEach((segment) => {
|
document.querySelector('video').addEventListener('timeupdate', e => {
|
||||||
if (
|
currentSegments.forEach((segment) => {
|
||||||
videoElement.currentTime >= segment[0] &&
|
if (
|
||||||
videoElement.currentTime <= segment[1]
|
e.target.currentTime >= segment[0] &&
|
||||||
) {
|
e.target.currentTime < segment[1]
|
||||||
videoElement.currentTime = segment[1];
|
) {
|
||||||
if (is.dev()) {
|
e.target.currentTime = segment[1];
|
||||||
console.log("SponsorBlock: skipping segment", segment);
|
if (is.dev()) {
|
||||||
|
console.log("SponsorBlock: skipping segment", segment);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
});
|
})
|
||||||
});
|
}, { once: true, passive: true })
|
||||||
};
|
};
|
||||||
|
|||||||
@ -15,5 +15,5 @@ module.exports = () => {
|
|||||||
const data = e.detail.getPlayerResponse();
|
const data = e.detail.getPlayerResponse();
|
||||||
ipcRenderer.send("song-info-request", JSON.stringify(data));
|
ipcRenderer.send("song-info-request", JSON.stringify(data));
|
||||||
});
|
});
|
||||||
})
|
}, { once: true, passive: true })
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,22 +0,0 @@
|
|||||||
let videoElement = null;
|
|
||||||
|
|
||||||
module.exports.ontimeupdate = (cb) => {
|
|
||||||
const observer = new MutationObserver((mutations, observer) => {
|
|
||||||
if (!videoElement) {
|
|
||||||
videoElement = document.querySelector("video");
|
|
||||||
if (videoElement) {
|
|
||||||
observer.disconnect();
|
|
||||||
videoElement.ontimeupdate = () => cb(videoElement);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!videoElement) {
|
|
||||||
observer.observe(document, {
|
|
||||||
childList: true,
|
|
||||||
subtree: true,
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
videoElement.ontimeupdate = () => cb(videoElement);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
@ -3412,10 +3412,10 @@ electron-updater@^4.4.6:
|
|||||||
lodash.isequal "^4.5.0"
|
lodash.isequal "^4.5.0"
|
||||||
semver "^7.3.5"
|
semver "^7.3.5"
|
||||||
|
|
||||||
electron@^12.1.0:
|
electron@^12.2.2:
|
||||||
version "12.1.0"
|
version "12.2.2"
|
||||||
resolved "https://registry.yarnpkg.com/electron/-/electron-12.1.0.tgz#615a7f9dbb2fc79cc72361fba9f39d005c697bca"
|
resolved "https://registry.yarnpkg.com/electron/-/electron-12.2.2.tgz#9627594d6b5bb589f00355989d316b6542539e54"
|
||||||
integrity sha512-joQlYI/nTIrTUldO3GENZ2j225eKar9nTQBSEwSUSWN4h65QGDmXNQ7dbWPmLlkUQWtHhz8lXhFk30OLG9ZjLw==
|
integrity sha512-Oma/nIfvgql9JjAxdB9gQk//qxpJaI6PgMocYMiW4kFyLi+8jS6oGn33QG3FESS//cw09KRnWmA9iutuFAuXtw==
|
||||||
dependencies:
|
dependencies:
|
||||||
"@electron/get" "^1.0.1"
|
"@electron/get" "^1.0.1"
|
||||||
"@types/node" "^14.6.2"
|
"@types/node" "^14.6.2"
|
||||||
|
|||||||
Reference in New Issue
Block a user