Skip to content

Commit

Permalink
feat: Ajouter le support de Invidious.
Browse files Browse the repository at this point in the history
  • Loading branch information
regseb committed Aug 9, 2019
1 parent 1fddc23 commit 9b9ecf9
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/core/scraper/youtube.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ export const rules = new Map();
* @returns {Promise} L'URL du <em>fichier</em> ou <code>null</code>.
*/
rules.set([
"*://*.youtube.com/watch*", "*://hooktube.com/watch*"
"*://*.youtube.com/watch*", "*://invidio.us/watch*",
"*://hooktube.com/watch*"
], function ({ searchParams }) {
return browser.storage.local.get(["youtube-playlist"])
.then(function (config) {
Expand Down Expand Up @@ -70,7 +71,10 @@ rules.set(["*://*.youtube.com/playlist*"], function ({ searchParams }) {
* @param {string} url L'URL d'une vidéo YouTube intégrée.
* @returns {Promise} L'URL du <em>fichier</em>.
*/
rules.set(["*://www.youtube.com/embed/*"], function ({ pathname }) {
rules.set([
"*://www.youtube.com/embed/*", "*://invidio.us/embed/*",
"*://hooktube.com/embed/*"
], function ({ pathname }) {
return Promise.resolve(PLUGIN_VIDEO_URL + pathname.substring(7));
});

Expand Down
76 changes: 76 additions & 0 deletions test/core/scraper/youtube.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,48 @@ describe("scraper/youtube", function () {
});
});

describe("*://invidio.us/watch*", function () {
let action;
before(function () {
action = Array.from(rules.entries())
.find(([r]) => r.includes(this.test.parent.title))[1];
});

it("should return video id", function () {
browser.storage.local.set({ "youtube-playlist": "video" });

const url = "https://invidio.us/watch?v=e6EQwSadpPk";
const expected = "plugin://plugin.video.youtube/play/" +
"?video_id=e6EQwSadpPk";
return action(new URL(url)).then(function (file) {
assert.strictEqual(file, expected);

browser.storage.local.clear();
});
});
});

describe("*://hooktube.com/watch*", function () {
let action;
before(function () {
action = Array.from(rules.entries())
.find(([r]) => r.includes(this.test.parent.title))[1];
});

it("should return video id", function () {
browser.storage.local.set({ "youtube-playlist": "video" });

const url = "https://hooktube.com/watch?v=LACbVhgtx9I";
const expected = "plugin://plugin.video.youtube/play/" +
"?video_id=LACbVhgtx9I";
return action(new URL(url)).then(function (file) {
assert.strictEqual(file, expected);

browser.storage.local.clear();
});
});
});

describe("*://*.youtube.com/playlist*", function () {
let action;
before(function () {
Expand Down Expand Up @@ -204,6 +246,40 @@ describe("scraper/youtube", function () {
});
});

describe("*://invidio.us/embed/*", function () {
let action;
before(function () {
action = Array.from(rules.entries())
.find(([r]) => r.includes(this.test.parent.title))[1];
});

it("should return video id", function () {
const url = "https://invidio.us/embed/8cmBd7lkunk";
const expected = "plugin://plugin.video.youtube/play/" +
"?video_id=8cmBd7lkunk";
return action(new URL(url)).then(function (file) {
assert.strictEqual(file, expected);
});
});
});

describe("*://hooktube.com/embed/*", function () {
let action;
before(function () {
action = Array.from(rules.entries())
.find(([r]) => r.includes(this.test.parent.title))[1];
});

it("should return video id", function () {
const url = "https://hooktube.com/embed/3lPSQ5KjamI";
const expected = "plugin://plugin.video.youtube/play/" +
"?video_id=3lPSQ5KjamI";
return action(new URL(url)).then(function (file) {
assert.strictEqual(file, expected);
});
});
});

describe("*://youtu.be/*", function () {
let action;
before(function () {
Expand Down

0 comments on commit 9b9ecf9

Please sign in to comment.