Skip to content

Instantly share code, notes, and snippets.

@senadir
Last active July 16, 2020 10:14
Show Gist options
  • Save senadir/6b248407ecc4579b90768416cfbb54a7 to your computer and use it in GitHub Desktop.
Save senadir/6b248407ecc4579b90768416cfbb54a7 to your computer and use it in GitHub Desktop.
const { uniqBy } = require("lodash");
const glob = require("glob-promise");
const fs = require("fs").promises;
glob("episodes-data/*.json")
.then((files) => {
// read the folder or folders if you want: example json/**/*.json
return Promise.all(
files.map((file) => {
return fs
.readFile(file, "utf8")
.then((data) => {
// Read each file
var obj = JSON.parse(data);
return obj;
})
.catch((err) => {
console.log(
"cannot read the file, something goes wrong with the file",
err
);
});
})
);
})
.then((result) => result.flat())
.then((episodes) => uniqBy(episodes, "link"))
.then((episodes) =>
fs.writeFile("episodes.json", JSON.stringify(episodes, null, 2))
);
// get episodes container
const container = () =>
document.querySelector(".sliderContent.row-with-x-columns");
// get current season name
let season = () =>
document.querySelector(".nfDropDown.widthRestricted.theme-lakira").innerText;
// the id we use for the file
let id = () =>
season().toLowerCase().replace(" ", "-") + "-" + new Date().getTime();
// this takes an object and save it as a json file.
let saveText = (ep) => {
var a = document.createElement("a");
a.setAttribute(
"href",
"data:application/json;charset=utf-8," +
encodeURIComponent(JSON.stringify(ep))
);
a.setAttribute("download", id() + ".json");
a.click();
};
// this takes the container and collect the episodes from it (with the needed data).
const epis = (container) =>
Array.from(container.children).map((e) => {
const qc = (c) => e.querySelector(c);
const title = qc(".episodeTitle .ellipsized").innerText;
const number = qc(".episodeNumber").innerText;
const image = qc(".episodeArt").style.backgroundImage.match(
/url\("(.+)"\)/
)[1];
const plot = qc(".episodeSynopsis").innerText;
const link = qc(".episodePlay").href.match(
/https:\/\/www\.netflix\.com\/watch\/\d+/
)[0];
const _season = season().match(/\d+/g)[0];
return {
title,
number,
image,
plot,
link,
season: _season,
};
});
// this function execute them in order.
const dw = () => {
saveText(epis(container()));
};
// execute it each time you scroll the carousel or change the season.
dw();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment