Skip to content

Commit

Permalink
feat: Ne pas historiser en navigation privée.
Browse files Browse the repository at this point in the history
  • Loading branch information
regseb committed Feb 1, 2020
1 parent 167d4fe commit 4e60822
Show file tree
Hide file tree
Showing 61 changed files with 610 additions and 290 deletions.
13 changes: 9 additions & 4 deletions src/core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,22 @@ export const cast = async function (action, urls) {
}


const file = await extract(new URL(url), { "depth": 0 });
const file = await extract(new URL(url), {
"depth": 0,
"incognito": browser.extension.inIncognitoContext
});
switch (action) {
case "send": await jsonrpc.send(file); break;
case "insert": await jsonrpc.insert(file); break;
case "add": await jsonrpc.add(file); break;
default: throw new Error(action + " is not supported");
}

const config = await browser.storage.local.get(["general-history"]);
if (config["general-history"]) {
await browser.history.addUrl({ url });
if (!browser.extension.inIncognitoContext) {
const config = await browser.storage.local.get(["general-history"]);
if (config["general-history"]) {
await browser.history.addUrl({ url });
}
}
};

Expand Down
13 changes: 9 additions & 4 deletions src/core/scraper/devtube.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,21 @@ import { matchPattern } from "../../tools/matchpattern.js";
*
* @constant {string}
*/
const PLUGIN_URL = "plugin://plugin.video.youtube/play/?video_id=";
const PLUGIN_URL = "plugin://plugin.video.youtube/play/";

/**
* Extrait les informations nécessaire pour lire la vidéo sur Kodi.
*
* @param {URL} url L'URL d'une vidéo DevTube.
* @param {URL} url L'URL d'une vidéo DevTube.
* @param {HTMLDocument} _doc Le contenu HTML de la page.
* @param {object} options Les options de l'extraction.
* @param {boolean} options.incognito La marque indiquant si l'utilisateur
* est en navigation privée.
* @returns {Promise.<string>} Une promesse contenant le lien du
* <em>fichier</em>.
*/
const action = async function ({ pathname }) {
return PLUGIN_URL + pathname.slice(7);
const action = async function ({ pathname }, _doc, { incognito }) {
return PLUGIN_URL + "?video_id=" + pathname.slice(7) +
"&incognito=" + incognito.toString();
};
export const extract = matchPattern(action, "*://dev.tube/video/*");
53 changes: 37 additions & 16 deletions src/core/scraper/youtube.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,26 @@ const PLUGIN_URL = "plugin://plugin.video.youtube/play/";
/**
* Extrait les informations nécessaire pour lire une vidéo / playlist sur Kodi.
*
* @param {URL} url L'URL d'une vidéo / playlist YouTube (ou Invidious /
* HookTube).
* @param {URL} url L'URL d'une vidéo / playlist YouTube
* (ou Invidious / HookTube).
* @param {HTMLDocument} _doc Le contenu HTML de la page.
* @param {object} options Les options de l'extraction.
* @param {boolean} options.incognito La marque indiquant si l'utilisateur
* est en navigation privée.
* @returns {Promise.<?string>} Une promesse contenant le lien du
* <em>fichier</em> ou <code>null</code>.
*/
const actionVideo = async function ({ searchParams }) {
const actionVideo = async function ({ searchParams }, _doc, { incognito }) {
const config = await browser.storage.local.get(["youtube-playlist"]);
if (searchParams.has("list") &&
("playlist" === config["youtube-playlist"] ||
!searchParams.has("v"))) {
return PLUGIN_URL + "?playlist_id=" + searchParams.get("list");
return PLUGIN_URL + "?playlist_id=" + searchParams.get("list") +
"&incognito=" + incognito.toString();
}
if (searchParams.has("v")) {
return PLUGIN_URL + "?video_id=" + searchParams.get("v");
return PLUGIN_URL + "?video_id=" + searchParams.get("v") +
"&incognito=" + incognito.toString();
}

return null;
Expand All @@ -41,28 +47,38 @@ export const extractVideo = matchPattern(actionVideo,
/**
* Extrait les informations nécessaire pour lire une playlist sur Kodi.
*
* @param {URL} url L'URL d'une playlist YouTube.
* @param {URL} url L'URL d'une playlist YouTube.
* @param {HTMLDocument} _doc Le contenu HTML de la page.
* @param {object} options Les options de l'extraction.
* @param {boolean} options.incognito La marque indiquant si l'utilisateur
* est en navigation privée.
* @returns {Promise.<?string>} Une promesse contenant le lien du
* <em>fichier</em> ou <code>null</code>.
*/
const actionPlaylist = async function ({ searchParams }) {
const actionPlaylist = async function ({ searchParams }, _doc, { incognito }) {
return searchParams.has("list")
? PLUGIN_URL + "?playlist_id=" + searchParams.get("list")
: null;
? PLUGIN_URL + "?playlist_id=" + searchParams.get("list") +
"&incognito=" + incognito.toString()
: null;
};
export const extractPlaylist = matchPattern(actionPlaylist,
"*://*.youtube.com/playlist*");

/**
* Extrait les informations nécessaire pour lire une vidéo sur Kodi.
*
* @param {URL} url L'URL d'une vidéo YouTube intégrée (ou Invidious /
* HookTube).
* @param {URL} url L'URL d'une vidéo YouTube intégrée
* (ou Invidious / HookTube).
* @param {HTMLDocument} _doc Le contenu HTML de la page.
* @param {object} options Les options de l'extraction.
* @param {boolean} options.incognito La marque indiquant si l'utilisateur
* est en navigation privée.
* @returns {Promise.<string>} Une promesse contenant le lien du
* <em>fichier</em>.
*/
const actionEmbed = async function ({ pathname }) {
return PLUGIN_URL + "?video_id=" + pathname.slice(7);
const actionEmbed = async function ({ pathname }, _doc, { incognito }) {
return PLUGIN_URL + "?video_id=" + pathname.slice(7) +
"&incognito=" + incognito.toString();
};
export const extractEmbed = matchPattern(actionEmbed,
"*://www.youtube.com/embed/*",
Expand All @@ -73,11 +89,16 @@ export const extractEmbed = matchPattern(actionEmbed,
/**
* Extrait les informations nécessaire pour lire une vidéo sur Kodi.
*
* @param {URL} url L'URL minifiée d'une vidéo YouTube.
* @param {URL} url L'URL minifiée d'une vidéo YouTube.
* @param {HTMLDocument} _doc Le contenu HTML de la page.
* @param {object} options Les options de l'extraction.
* @param {boolean} options.incognito La marque indiquant si l'utilisateur
* est en navigation privée.
* @returns {Promise.<string>} Une promesse contenant le lien du
* <em>fichier</em>.
*/
const actionMinify = async function ({ pathname }) {
return PLUGIN_URL + "?video_id=" + pathname.slice(1);
const actionMinify = async function ({ pathname }, _doc, { incognito }) {
return PLUGIN_URL + "?video_id=" + pathname.slice(1) +
"&incognito=" + incognito.toString();
};
export const extractMinify = matchPattern(actionMinify, "*://youtu.be/*");
3 changes: 2 additions & 1 deletion test/integration/scraper/acestream.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import { extract } from "../../../src/core/scrapers.js";
describe("Scraper: Ace Stream", function () {
it("should return video URL", async function () {
const url = "acestream://94c2fd8fb9bc8f2fc71a2cbe9d4b866f227a0209";
const options = { "depth": 0, "incognito": false };
const expected = "plugin://program.plexus/?mode=1&name=" +
"&url=acestream%3A%2F%2F94c2fd8fb9b" +
"c8f2fc71a2cbe9d4b866f227a0209";

const file = await extract(new URL(url), { "depth": 0 });
const file = await extract(new URL(url), options);
assert.strictEqual(file, expected);
});
});
15 changes: 10 additions & 5 deletions test/integration/scraper/allocine.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,48 +4,53 @@ import { extract } from "../../../src/core/scrapers.js";
describe("Scraper: AlloCiné", function () {
it("should return URL when it's not a video", async function () {
const url = "http://www.allocine.fr/video/";
const options = { "depth": 0, "incognito": false };
const expected = url;

const file = await extract(new URL(url), { "depth": 0 });
const file = await extract(new URL(url), options);
assert.strictEqual(file, expected);
});

it("should return standard video URL", async function () {
const url = "http://www.allocine.fr/video/video-19577157/";
const options = { "depth": 0, "incognito": false };
const expected = "https://fr.vid.web.acsta.net/nmedia/33/18/02/23/15" +
"/19577157_sd_013.mp4";

const file = await extract(new URL(url), { "depth": 0 });
const file = await extract(new URL(url), options);
assert.strictEqual(file, expected);
});

it("should return high video URL", async function () {
const url = "http://www.allocine.fr/video" +
"/player_gen_cmedia=19583315&cfilm=232669.html";
const options = { "depth": 0, "incognito": false };
const expected = "http://fr.vid.web.acsta.net/nmedia/33/19/04/02/14" +
"//19583315_hd_013.mp4";

const file = await extract(new URL(url), { "depth": 0 });
const file = await extract(new URL(url), options);
assert.strictEqual(file, expected);
});

it("should return medium video URL", async function () {
const url = "http://www.allocine.fr/video" +
"/player_gen_cmedia=19432206&cfilm=1051.html";
const options = { "depth": 0, "incognito": false };
const expected = "http://fr.vid.web.acsta.net/nmedia/s3/33/18/66/14" +
"/37/19432206_sd_013.mp4";

const file = await extract(new URL(url), { "depth": 0 });
const file = await extract(new URL(url), options);
assert.strictEqual(file, expected);
});

it("should return video URL from RSS", async function () {
const url = "http://rss.allocine.fr/~r/ac/actualites/cine/~3" +
"/JT3DmCdQCdQ/fichearticle_gen_carticle=18685966.html";
const options = { "depth": 0, "incognito": false };
const expected = "http://fr.vid.web.acsta.net/nmedia/33/19/11/22/16" +
"//19586672_hd_013.mp4";

const file = await extract(new URL(url), { "depth": 0 });
const file = await extract(new URL(url), options);
assert.strictEqual(file, expected);
});
});
6 changes: 4 additions & 2 deletions test/integration/scraper/applepodcasts.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,21 @@ import { extract } from "../../../src/core/scrapers.js";
describe("Scraper: Apple Podcasts", function () {
it("should return URL when it's not an audio", async function () {
const url = "https://podcasts.apple.com/us/podcast/culture-1999/id";
const options = { "depth": 0, "incognito": false };
const expected = url;

const file = await extract(new URL(url), { "depth": 0 });
const file = await extract(new URL(url), options);
assert.strictEqual(file, expected);
});

it("should return audio URL", async function () {
const url = "https://podcasts.apple.com/fr/podcast" +
"/cest-papy-mamie/id1093080425?i=1000435243113";
const options = { "depth": 0, "incognito": false };
const expected = "https://dts.podtrac.com/redirect.mp3" +
"/www.arteradio.com/podcast_sound/61661310.mp3";

const file = await extract(new URL(url), { "depth": 0 });
const file = await extract(new URL(url), options);
assert.strictEqual(file, expected);
});
});
9 changes: 6 additions & 3 deletions test/integration/scraper/arte.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,34 @@ import { extract } from "../../../src/core/scrapers.js";
describe("Scraper: Arte", function () {
it("should return URL when video is unavailable", async function () {
const url = "https://www.arte.tv/fr/videos/067125-020-A/bits-top-list/";
const options = { "depth": 0, "incognito": false };
const expected = url;

const file = await extract(new URL(url), { "depth": 0 });
const file = await extract(new URL(url), options);
assert.strictEqual(file, expected);
});

it("should return french video URL", async function () {
const url = "https://www.arte.tv/fr/videos/069798-000-A" +
"/revolution-vhs/";
const options = { "depth": 0, "incognito": false };
const expected = "https://arteptweb-a.akamaihd.net/am/ptweb" +
"/069000/069700/069798-000-A_SQ_0_VOF-STF" +
"_04670905_MP4-2200_AMM-PTWEB_1FpKT1ELGYC.mp4";

const file = await extract(new URL(url), { "depth": 0 });
const file = await extract(new URL(url), options);
assert.strictEqual(file, expected);
});

it("should return german video URL", async function () {
const url = "https://www.arte.tv/de/videos/077140-006-A" +
"/blow-up-john-carpenter-aus-der-sicht-von-thierry-jousse/";
const options = { "depth": 0, "incognito": false };
const expected = "https://arteptweb-a.akamaihd.net/am/ptweb" +
"/077000/077100/077140-006-A_SQ_0_VA-STA" +
"_03470223_MP4-2200_AMM-PTWEB_u4hdDbkpd.mp4";

const file = await extract(new URL(url), { "depth": 0 });
const file = await extract(new URL(url), options);
assert.strictEqual(file, expected);
});
});
6 changes: 4 additions & 2 deletions test/integration/scraper/arteradio.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,21 @@ import { extract } from "../../../src/core/scrapers.js";
describe("Scraper: Arte Radio", function () {
it("should return audio URL", async function () {
const url = "https://www.arteradio.com/son/61657661/fais_moi_ouir";
const options = { "depth": 0, "incognito": false };
const expected = "https://download.www.arte.tv/permanent/arteradio" +
"/sites/default/files/sons/01faismoiouir_hq_fr.mp3";

const file = await extract(new URL(url), { "depth": 0 });
const file = await extract(new URL(url), options);
assert.strictEqual(file, expected);
});

it("should return audio URL when protocol is HTTP", async function () {
const url = "http://www.arteradio.com/son/61657661/fais_moi_ouir";
const options = { "depth": 0, "incognito": false };
const expected = "https://download.www.arte.tv/permanent/arteradio" +
"/sites/default/files/sons/01faismoiouir_hq_fr.mp3";

const file = await extract(new URL(url), { "depth": 0 });
const file = await extract(new URL(url), options);
assert.strictEqual(file, expected);
});
});
3 changes: 2 additions & 1 deletion test/integration/scraper/bitchute.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import { extract } from "../../../src/core/scrapers.js";
describe("Scraper: BitChute", function () {
it("should return video URL", async function () {
const url = "https://www.bitchute.com/video/dz5JcCZnJMge/";
const options = { "depth": 0, "incognito": false };
const expected = "https://seed126.bitchute.com/hU2elaB5u3kB" +
"/dz5JcCZnJMge.mp4";

const file = await extract(new URL(url), { "depth": 0 });
const file = await extract(new URL(url), options);
assert.strictEqual(file, expected);
});
});
9 changes: 6 additions & 3 deletions test/integration/scraper/blogtalkradio.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,34 @@ import { extract } from "../../../src/core/scrapers.js";
describe("Scraper: Blog Talk Radio", function () {
it("should return null when it's not an audio", async function () {
const url = "https://www.blogtalkradio.com/technology";
const options = { "depth": 0, "incognito": false };
const expected = url;

const file = await extract(new URL(url), { "depth": 0 });
const file = await extract(new URL(url), options);
assert.strictEqual(file, expected);
});

it("should return audio URL", async function () {
const url = "https://www.blogtalkradio.com/stretchingadollar" +
"/2011/03/02/7-mozilla-firefox-add-ons-to-help" +
"-your-small-business-stretch-a-dollar-to-save";
const options = { "depth": 0, "incognito": false };
const expected = "https://www.blogtalkradio.com/stretchingadollar" +
"/2011/03/02/7-mozilla-firefox-add-ons-to-help" +
"-your-small-business-stretch-a-dollar-to-save.mp3";

const file = await extract(new URL(url), { "depth": 0 });
const file = await extract(new URL(url), options);
assert.strictEqual(file, expected);
});

it("should return audio URL when protocol is HTTP", async function () {
const url = "http://www.blogtalkradio.com/firefoxnews-online" +
"/2011/06/13/firefoxnews-online";
const options = { "depth": 0, "incognito": false };
const expected = "https://www.blogtalkradio.com/firefoxnews-online" +
"/2011/06/13/firefoxnews-online.mp3";

const file = await extract(new URL(url), { "depth": 0 });
const file = await extract(new URL(url), options);
assert.strictEqual(file, expected);
});
});
9 changes: 6 additions & 3 deletions test/integration/scraper/dailymotion.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,31 @@ import { extract } from "../../../src/core/scrapers.js";
describe("Scraper: Dailymotion", function () {
it("should return video id", async function () {
const url = "https://www.dailymotion.com/video/x17qw0a";
const options = { "depth": 0, "incognito": false };
const expected = "plugin://plugin.video.dailymotion_com/" +
"?mode=playVideo&url=x17qw0a";

const file = await extract(new URL(url), { "depth": 0 });
const file = await extract(new URL(url), options);
assert.strictEqual(file, expected);
});

it("should return tiny video id", async function () {
const url = "http://dai.ly/x5riqme";
const options = { "depth": 0, "incognito": false };
const expected = "plugin://plugin.video.dailymotion_com/" +
"?mode=playVideo&url=x5riqme";

const file = await extract(new URL(url), { "depth": 0 });
const file = await extract(new URL(url), options);
assert.strictEqual(file, expected);
});

it("should return embed video id", async function () {
const url = "https://www.dailymotion.com/embed/video/a12bc3d";
const options = { "depth": 0, "incognito": false };
const expected = "plugin://plugin.video.dailymotion_com/" +
"?mode=playVideo&url=a12bc3d";

const file = await extract(new URL(url), { "depth": 0 });
const file = await extract(new URL(url), options);
assert.strictEqual(file, expected);
});
});

0 comments on commit 4e60822

Please sign in to comment.