-
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
136 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/*"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(`"`, """)}"></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(); | ||
}); | ||
}); | ||
}); |