Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sponsorblock fix + use new apiLoaded event #463

Merged
merged 6 commits into from
Nov 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
"ytpl": "^2.2.3"
},
"devDependencies": {
"electron": "^12.1.0",
"electron": "^12.2.2",
"electron-builder": "^22.10.5",
"electron-devtools-installer": "^3.1.1",
"electron-icon-maker": "0.0.5",
Expand Down
13 changes: 5 additions & 8 deletions plugins/disable-autoplay/front.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
const { ontimeupdate } = require("../../providers/video-element");

module.exports = () => {
ontimeupdate((videoElement) => {
if (videoElement.currentTime === 0 && videoElement.duration !== NaN) {
// auto-confirm-when-paused plugin can interfere here if not disabled!
videoElement.pause();
}
});
document.addEventListener('apiLoaded', () => {
document.querySelector('video').addEventListener('loadeddata', e => {
e.target.pause();
})
}, { once: true, passive: true })
};
2 changes: 1 addition & 1 deletion plugins/precise-volume/front.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module.exports = (options) => {
document.addEventListener('apiLoaded', e => {
api = e.detail;
firstRun(options);
})
}, { once: true, passive: true })
};

/** Restore saved volume and setup tooltip */
Expand Down
2 changes: 1 addition & 1 deletion plugins/quality-changer/front.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const qualitySettingsButton = ElementFromFile(


module.exports = () => {
document.addEventListener('apiLoaded', setup);
document.addEventListener('apiLoaded', setup, { once: true, passive: true });
}

function setup(event) {
Expand Down
7 changes: 6 additions & 1 deletion plugins/sponsorblock/back.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const fetch = require("node-fetch");
const is = require("electron-is");

const defaultConfig = require("../../config/defaults");
const registerCallback = require("../../providers/song-info");
Expand All @@ -24,6 +25,7 @@ module.exports = (win, options) => {
});
};


const fetchSegments = async (apiURL, categories) => {
const sponsorBlockURL = `${apiURL}/api/skipSegments?videoID=${videoID}&categories=${JSON.stringify(
categories
Expand All @@ -45,7 +47,10 @@ const fetchSegments = async (apiURL, categories) => {
);

return sortedSegments;
} catch {
} catch (e) {
if (is.dev()) {
console.log('error on sponsorblock request:', e);
}
return [];
}
};
28 changes: 14 additions & 14 deletions plugins/sponsorblock/front.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,26 @@ const { ipcRenderer } = require("electron");

const is = require("electron-is");

const { ontimeupdate } = require("../../providers/video-element");

let currentSegments = [];

module.exports = () => {
ipcRenderer.on("sponsorblock-skip", (_, segments) => {
currentSegments = segments;
});

ontimeupdate((videoElement) => {
currentSegments.forEach((segment) => {
if (
videoElement.currentTime >= segment[0] &&
videoElement.currentTime <= segment[1]
) {
videoElement.currentTime = segment[1];
if (is.dev()) {
console.log("SponsorBlock: skipping segment", segment);
document.addEventListener('apiLoaded', () => {
document.querySelector('video').addEventListener('timeupdate', e => {
currentSegments.forEach((segment) => {
if (
e.target.currentTime >= segment[0] &&
e.target.currentTime < segment[1]
) {
e.target.currentTime = segment[1];
if (is.dev()) {
console.log("SponsorBlock: skipping segment", segment);
}
}
}
});
});
});
})
}, { once: true, passive: true })
};
2 changes: 1 addition & 1 deletion providers/song-info-front.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ module.exports = () => {
const data = e.detail.getPlayerResponse();
ipcRenderer.send("song-info-request", JSON.stringify(data));
});
})
}, { once: true, passive: true })
};
22 changes: 0 additions & 22 deletions providers/video-element.js

This file was deleted.

8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3412,10 +3412,10 @@ electron-updater@^4.4.6:
lodash.isequal "^4.5.0"
semver "^7.3.5"

electron@^12.1.0:
version "12.1.0"
resolved "https://registry.yarnpkg.com/electron/-/electron-12.1.0.tgz#615a7f9dbb2fc79cc72361fba9f39d005c697bca"
integrity sha512-joQlYI/nTIrTUldO3GENZ2j225eKar9nTQBSEwSUSWN4h65QGDmXNQ7dbWPmLlkUQWtHhz8lXhFk30OLG9ZjLw==
electron@^12.2.2:
version "12.2.2"
resolved "https://registry.yarnpkg.com/electron/-/electron-12.2.2.tgz#9627594d6b5bb589f00355989d316b6542539e54"
integrity sha512-Oma/nIfvgql9JjAxdB9gQk//qxpJaI6PgMocYMiW4kFyLi+8jS6oGn33QG3FESS//cw09KRnWmA9iutuFAuXtw==
dependencies:
"@electron/get" "^1.0.1"
"@types/node" "^14.6.2"
Expand Down