-
Notifications
You must be signed in to change notification settings - Fork 37
/
adultempire_covers.js
63 lines (55 loc) · 1.46 KB
/
adultempire_covers.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/**
* NOTE this won't work with 0.13.1 or below
*/
async ({
args,
event,
$axios,
$cheerio,
$throw,
$log,
movieName,
$createImage
}) => {
if (event != "movieCreated")
$throw("Uh oh. You shouldn't use the plugin for this type of event");
const name = movieName.replace(/#/g, "").replace(/\s{2,}/g, " ").trim();
$log(
`Scraping movie covers for '${name}', dry mode: ${args.dry ||
false}...`
);
const url = `https://www.adultempire.com/allsearch/search?q=${name}`;
const html = (await $axios.get(url)).data;
const $ = $cheerio.load(html);
const firstResult = $(".boxcover").toArray()[0];
const href = $(firstResult).attr("href");
if (href) {
const movieUrl = "https://adultempire.com" + href;
const html = (await $axios.get(movieUrl)).data;
const $ = $cheerio.load(html);
const frontCover = $("#front-cover img").toArray()[0];
const frontCoverSrc = $(frontCover).attr("src");
const backCoverSrc = frontCoverSrc.replace("h.jpg", "bh.jpg");
if (args.dry === true) {
$log({
movieUrl,
frontCoverSrc,
backCoverSrc
});
} else {
const frontCoverImg = await $createImage(
frontCoverSrc,
`${movieName} (front cover)`
);
const backCoverImg = await $createImage(
backCoverSrc,
`${movieName} (back cover)`
);
return {
frontCover: frontCoverImg,
backCover: backCoverImg
};
}
}
return {};
};