Skip to content

Commit

Permalink
feat: Ajouter le support de ZDF.
Browse files Browse the repository at this point in the history
  • Loading branch information
regseb committed May 14, 2021
1 parent 0864359 commit 45be3f7
Show file tree
Hide file tree
Showing 8 changed files with 136 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ des vidéos et des musiques sur **Kodi** :
My Cloud Player, Odysee, Overcast, PeerTube, Pippa, podCloud, Pokémon TV,
Radio, Radioline, Steam, Streamable, TikTok, Ultimedia, Veoh, VideoPress,
Viously ;
- Allemagne : Arte ;
- Allemagne : Arte, ZDF ;
- Belgique : VRT NU, VTM GO ;
- États-Unis : KCAA Radio ;
- France : 20 Minutes, AlloCiné, Arte, Arte Radio, France Inter, Futura
Expand Down
6 changes: 3 additions & 3 deletions locales/en/amo_description.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
<li>
YouTube, Twitch, Vimeo, SoundCloud as well as Ace&nbsp;Stream, Apple&nbsp;Podcasts, Bigo&nbsp;Live, BitChute, Blog&nbsp;Talk&nbsp;Radio, Castbox, Dailymotion, DevTube, Facebook, Flickr, Instagram, ItemFix, Jamendo, LBRY, Megaphone, Metacafe, Mixcloud, My&nbsp;Cloud&nbsp;Player, Odysee, Overcast, PeerTube, Pippa, podCloud, Pokémon&nbsp;TV, Radio, Radioline, Steam, Streamable, TikTok, Ultimedia, Veoh, VideoPress, Viously;
<ul>
<li>Germany: Arte;</li>
<li>Belgium: VRT&nbsp;NU, VTM&nbsp;GO;</li>
<li>USA: KCAA&nbsp;Radio;</li>
<li>France: 20&nbsp;Minutes, AlloCiné, Arte, Arte&nbsp;Radio, France&nbsp;Inter, Futura&nbsp;Sciences, Gamekult, JeuxVideoCom, Konbini, Le&nbsp;Monde, Le&nbsp;Point, L'Internaute, Melty, Ouest-France;</li>
<li>Germany: Arte, ZDF;</li>
<li>Greece: StarGR;</li>
<li>Iran: آپارات;</li>
<li>Iceland: Útvarp&nbsp;Saga;</li>
<li>Iran: آپارات;</li>
<li>Netherlands: Dumpert;</li>
<li>Russia: Первый&nbsp;канал;</li>
<li>United Kingdom: Daily&nbsp;Mail, The&nbsp;Guardian.</li>
<li>USA: KCAA&nbsp;Radio;</li>
</ul>
</li>
</ul>
Expand Down
2 changes: 1 addition & 1 deletion locales/fr/amo_description.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<li>
YouTube, Twitch, Vimeo, SoundCloud ainsi que Ace&nbsp;Stream, Apple&nbsp;Podcasts, Bigo&nbsp;Live, BitChute, Blog&nbsp;Talk&nbsp;Radio, Castbox, Dailymotion, DevTube, Facebook, Flickr, Instagram, ItemFix, Jamendo, LBRY, Megaphone, Metacafe, Mixcloud, My&nbsp;Cloud&nbsp;Player, Odysee, Overcast, PeerTube, Pippa, podCloud, Pokémon&nbsp;TV, Radio, Radioline, Steam, Streamable, TikTok, Ultimedia, Veoh, VideoPress, Viously&nbsp;;
<ul>
<li>Allemagne&nbsp;: Arte&nbsp;;</li>
<li>Allemagne&nbsp;: Arte, ZDF&nbsp;;</li>
<li>Belgique&nbsp;: VRT&nbsp;NU&nbsp;, VTM&nbsp;GO&nbsp;;</li>
<li>États-Unis&nbsp;: KCAA&nbsp;Radio&nbsp;;</li>
<li>France&nbsp;: 20&nbsp;Minutes, AlloCiné, Arte, Arte&nbsp;Radio, France&nbsp;Inter, Futura&nbsp;Sciences, Gamekult, JeuxVideoCom, Konbini, Le&nbsp;Monde, Le&nbsp;Point, L'Internaute, Melty, Ouest-France&nbsp;;</li>
Expand Down
6 changes: 3 additions & 3 deletions locales/sk/amo_description.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
<li>
YouTube, Twitch, Vimeo, SoundCloud a tiež Ace&nbsp;Stream, Apple&nbsp;Podcasty, Bigo&nbsp;Live, BitChute, Blog&nbsp;Talk&nbsp;Radio, Castbox, Dailymotion, DevTube, Facebook, Flickr, Instagram, Jamendo, ItemFix, LBRY, Megaphone, Metacafe, Mixcloud, My&nbsp;Cloud&nbsp;Player, Odysee, Overcast, PeerTube, Pippa, podCloud, Pokémon&nbsp;TV, Radio, Radioline, Steam, Streamable, TikTok, Ultimedia, Veoh, VideoPress, Viously;
<ul>
<li>Nemecko: Arte;</li>
<li>Belgicko: VRT&nbsp;NU, VTM&nbsp;GO;</li>
<li>USA: KCAA&nbsp;Radio;</li>
<li>Francúzsko: 20&nbsp;Minutes, AlloCiné, Arte, Arte&nbsp;Radio, France&nbsp;Inter, Futura&nbsp;Sciences, Gamekult, JeuxVideoCom, Konbini, Le&nbsp;Monde, Le&nbsp;Point, L'Internaute, Melty, Ouest-France;</li>
<li>Grécko: StarGR;</li>
<li>Holandsko: Dumpert;</li>
<li>Irán: آپارات;</li>
<li>Island: Útvarp&nbsp;Saga;</li>
<li>Holandsko: Dumpert;</li>
<li>Nemecko: Arte, ZDF;</li>
<li>Rusko: Первый&nbsp;канал;</li>
<li>Spojené kráľovstvo: Daily&nbsp;Mail, The&nbsp;Guardian.</li>
<li>USA: KCAA&nbsp;Radio;</li>
</ul>
</li>
</ul>
Expand Down
33 changes: 33 additions & 0 deletions src/core/scraper/zdf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* @module
*/
/* eslint-disable require-await */

import { matchPattern } from "../../tools/matchpattern.js";

/**
* Extrait les informations nécessaire pour lire une vidéo sur Kodi.
*
* @param {URL} _url L'URL d'une vidéo de ZDF.
* @param {Object} content Le contenu de l'URL.
* @param {Function} content.html La fonction retournant la promesse contenant
* le document HTML.
* @returns {Promise<?string>} Une promesse contenant le lien du
* <em>fichier</em> ou <code>null</code>.
*/
const action = async function (_url, content) {
const doc = await content.html();
const button = doc.querySelector("button.download-btn[data-dialog]");
if (null === button) {
return null;
}

const { contentUrl, apiToken } = JSON.parse(button.dataset.dialog);
const url = contentUrl.replace("{playerId}", "ngplayer_2_4");
const response = await fetch(url, {
headers: new Headers({ "Api-Auth": `Bearer ${apiToken}` }),
});
const json = await response.json();
return json.priorityList[0].formitaeten[0].qualities[0].audio.tracks[0].uri;
};
export const extract = matchPattern(action, "*://www.zdf.de/*");
2 changes: 2 additions & 0 deletions src/core/scrapers.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ import * as viously from "./scraper/viously.js";
import * as vrtnu from "./scraper/vrtnu.js";
import * as vtmgo from "./scraper/vtmgo.js";
import * as youtube from "./scraper/youtube.js";
import * as zdf from "./scraper/zdf.js";

/**
* La liste des extracteurs (retournant le <em>fichier</em> extrait ou
Expand Down Expand Up @@ -124,6 +125,7 @@ const SCRAPERS = [
vrtnu,
vtmgo,
youtube,
zdf,
// Utiliser les scrapers génériques en dernier recours.
video,
audio,
Expand Down
23 changes: 23 additions & 0 deletions test/integration/scraper/zdf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import assert from "node:assert";
import { extract } from "../../../src/core/scrapers.js";

describe("Scraper: ZDF", function () {
it("should return URL when it's not a video", async function () {
const url = new URL("https://www.zdf.de/filme");
const options = { depth: false, incognito: false };

const file = await extract(url, options);
assert.strictEqual(file, url.href);
});

it("should return video URL", async function () {
const url = new URL("https://www.zdf.de/dokumentation/37-grad" +
"/37-im-schuldenstrudel-100.html");
const options = { depth: false, incognito: false };

const file = await extract(url, options);
assert.strictEqual(file,
"https://nrodlzdf-a.akamaihd.net/none/zdf/21/04" +
"/210427_sendung_37g/4/210427_sendung_37g_a1a2_2128k_p18v15.webm");
});
});
70 changes: 70 additions & 0 deletions test/unit/core/scraper/zdf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import assert from "node:assert";
import sinon from "sinon";
import { extract } from "../../../../src/core/scraper/zdf.js";

describe("core/scraper/zdf.js", function () {
describe("extract()", function () {
it("should return null when it's a unsupported URL", async function () {
const url = new URL("https://www.zdftext.de/");

const file = await extract(url);
assert.strictEqual(file, null);
});

it("should return null when it's not a video", async function () {
const url = new URL("https://www.zdf.de/foo");
const content = {
html: () => Promise.resolve(new DOMParser().parseFromString(`
<html>
<body></body>
</html>`, "text/html")),
};

const file = await extract(url, content);
assert.strictEqual(file, null);
});

it("should return video URL", async function () {
const stub = sinon.stub(globalThis, "fetch").resolves(new Response(
JSON.stringify({
priorityList: [{
formitaeten: [{
qualities: [{
audio: {
tracks: [{
uri: "https://quux.de/corge.webm",
}],
},
}],
}],
}],
}),
));

const url = new URL("https://www.zdf.de/foo");
const content = {
html: () => Promise.resolve(new DOMParser().parseFromString(`
<html>
<body>
<button class="download-btn"
data-dialog="${JSON.stringify({
contentUrl: "http://bar.de/{playerId}/baz.json",
apiToken: "qux",
}).replaceAll(`"`, "&quot;")}"></button>
</body>
</html>`, "text/html")),
};

const file = await extract(url, content);
assert.strictEqual(file, "https://quux.de/corge.webm");

assert.strictEqual(stub.callCount, 1);
assert.deepStrictEqual(stub.firstCall.args, [
"http://bar.de/ngplayer_2_4/baz.json",
{ headers: new Headers({ "Api-Auth": "Bearer qux" }) },
]);

stub.restore();
});
});
});

0 comments on commit 45be3f7

Please sign in to comment.