Adds support for cover image and title
This commit is contained in:
parent
e4849f728b
commit
7906f151e6
12
generate.js
12
generate.js
|
@ -13,9 +13,12 @@ const getArticle = async url => {
|
|||
}
|
||||
};
|
||||
|
||||
module.exports = (url, epubPath, language="en-US") => {
|
||||
module.exports = (url, epubPath, title, coverURL, language="en-US") => {
|
||||
getArticle(url).then(res => {
|
||||
let xml = `<dc:title id="epub-title-1">${res.title}</dc:title>
|
||||
|
||||
title = title ? title : res.title;
|
||||
|
||||
let xml = `<dc:title id="epub-title-1">${title}</dc:title>
|
||||
<dc:date>${res.published}</dc:date>
|
||||
<dc:language>${language}</dc:language>
|
||||
<dc:identifier>${url}</dc:identifier>
|
||||
|
@ -26,10 +29,9 @@ module.exports = (url, epubPath, language="en-US") => {
|
|||
|
||||
fs.writeFileSync(html, res.content);
|
||||
fs.writeFileSync(metadata, xml);
|
||||
const imageUrl = coverURL ? coverURL : res.image;
|
||||
|
||||
const imageUrl = res.image;
|
||||
|
||||
const dl = new DownloaderHelper(res.image, "/tmp", {
|
||||
const dl = new DownloaderHelper(imageUrl, "/tmp", {
|
||||
fileName: "epub-to-image.jpg"
|
||||
});
|
||||
|
||||
|
|
544
index.js
544
index.js
|
@ -3,269 +3,281 @@ var argv = require("yargs").argv;
|
|||
const generateEPUB = require("./generate");
|
||||
|
||||
require("yargs") // eslint-disable-line
|
||||
.usage("$0 --output [output] <url>")
|
||||
.help("h")
|
||||
.command(
|
||||
"$0 <url>",
|
||||
"Generate EPUB file from URL",
|
||||
yargs => {
|
||||
yargs
|
||||
.positional("url", {
|
||||
describe: "The URL to download",
|
||||
type: "string"
|
||||
})
|
||||
.option("output", {
|
||||
alias: "o",
|
||||
type: "string",
|
||||
default: "url-to-epub.epub",
|
||||
description: "Output file to save EPUB"
|
||||
})
|
||||
.option("language", {
|
||||
alias: "l",
|
||||
type: "string",
|
||||
default: "en-US",
|
||||
description: "A valid language tag",
|
||||
choices: [
|
||||
"af",
|
||||
"af-ZA",
|
||||
"ar",
|
||||
"ar-AE",
|
||||
"ar-BH",
|
||||
"ar-DZ",
|
||||
"ar-EG",
|
||||
"ar-IQ",
|
||||
"ar-JO",
|
||||
"ar-KW",
|
||||
"ar-LB",
|
||||
"ar-LY",
|
||||
"ar-MA",
|
||||
"ar-OM",
|
||||
"ar-QA",
|
||||
"ar-SA",
|
||||
"ar-SY",
|
||||
"ar-TN",
|
||||
"ar-YE",
|
||||
"az",
|
||||
"az-AZ",
|
||||
"az-Cyrl-AZ",
|
||||
"be",
|
||||
"be-BY",
|
||||
"bg",
|
||||
"bg-BG",
|
||||
"bs-BA",
|
||||
"ca",
|
||||
"ca-ES",
|
||||
"cs",
|
||||
"cs-CZ",
|
||||
"cy",
|
||||
"cy-GB",
|
||||
"da",
|
||||
"da-DK",
|
||||
"de",
|
||||
"de-AT",
|
||||
"de-CH",
|
||||
"de-DE",
|
||||
"de-LI",
|
||||
"de-LU",
|
||||
"dv",
|
||||
"dv-MV",
|
||||
"el",
|
||||
"el-GR",
|
||||
"en",
|
||||
"en-AU",
|
||||
"en-BZ",
|
||||
"en-CA",
|
||||
"en-CB",
|
||||
"en-GB",
|
||||
"en-IE",
|
||||
"en-JM",
|
||||
"en-NZ",
|
||||
"en-PH",
|
||||
"en-TT",
|
||||
"en-US",
|
||||
"en-ZA",
|
||||
"en-ZW",
|
||||
"eo",
|
||||
"es",
|
||||
"es-AR",
|
||||
"es-BO",
|
||||
"es-CL",
|
||||
"es-CO",
|
||||
"es-CR",
|
||||
"es-DO",
|
||||
"es-EC",
|
||||
"es-ES",
|
||||
"es-GT",
|
||||
"es-HN",
|
||||
"es-MX",
|
||||
"es-NI",
|
||||
"es-PA",
|
||||
"es-PE",
|
||||
"es-PR",
|
||||
"es-PY",
|
||||
"es-SV",
|
||||
"es-UY",
|
||||
"es-VE",
|
||||
"et",
|
||||
"et-EE",
|
||||
"eu",
|
||||
"eu-ES",
|
||||
"fa",
|
||||
"fa-IR",
|
||||
"fi",
|
||||
"fi-FI",
|
||||
"fo",
|
||||
"fo-FO",
|
||||
"fr",
|
||||
"fr-BE",
|
||||
"fr-CA",
|
||||
"fr-CH",
|
||||
"fr-FR",
|
||||
"fr-LU",
|
||||
"fr-MC",
|
||||
"gl",
|
||||
"gl-ES",
|
||||
"gu",
|
||||
"gu-IN",
|
||||
"he",
|
||||
"he-IL",
|
||||
"hi",
|
||||
"hi-IN",
|
||||
"hr",
|
||||
"hr-BA",
|
||||
"hr-HR",
|
||||
"hu",
|
||||
"hu-HU",
|
||||
"hy",
|
||||
"hy-AM",
|
||||
"id",
|
||||
"id-ID",
|
||||
"is",
|
||||
"is-IS",
|
||||
"it",
|
||||
"it-CH",
|
||||
"it-IT",
|
||||
"ja",
|
||||
"ja-JP",
|
||||
"ka",
|
||||
"ka-GE",
|
||||
"kk",
|
||||
"kk-KZ",
|
||||
"kn",
|
||||
"kn-IN",
|
||||
"ko",
|
||||
"ko-KR",
|
||||
"kok",
|
||||
"kok-IN",
|
||||
"ky",
|
||||
"ky-KG",
|
||||
"lt",
|
||||
"lt-LT",
|
||||
"lv",
|
||||
"lv-LV",
|
||||
"mi",
|
||||
"mi-NZ",
|
||||
"mk",
|
||||
"mk-MK",
|
||||
"mn",
|
||||
"mn-MN",
|
||||
"mr",
|
||||
"mr-IN",
|
||||
"ms",
|
||||
"ms-BN",
|
||||
"ms-MY",
|
||||
"mt",
|
||||
"mt-MT",
|
||||
"nb",
|
||||
"nb-NO",
|
||||
"nl",
|
||||
"nl-BE",
|
||||
"nl-NL",
|
||||
"nn-NO",
|
||||
"ns",
|
||||
"ns-ZA",
|
||||
"pa",
|
||||
"pa-IN",
|
||||
"pl",
|
||||
"pl-PL",
|
||||
"ps",
|
||||
"ps-AR",
|
||||
"pt",
|
||||
"pt-BR",
|
||||
"pt-PT",
|
||||
"qu",
|
||||
"qu-BO",
|
||||
"qu-EC",
|
||||
"qu-PE",
|
||||
"ro",
|
||||
"ro-RO",
|
||||
"ru",
|
||||
"ru-RU",
|
||||
"sa",
|
||||
"sa-IN",
|
||||
"se",
|
||||
"se-FI",
|
||||
"se-NO",
|
||||
"se-SE",
|
||||
"sk",
|
||||
"sk-SK",
|
||||
"sl",
|
||||
"sl-SI",
|
||||
"sq",
|
||||
"sq-AL",
|
||||
"sr-BA",
|
||||
"sr-Cyrl-BA",
|
||||
"sr-SP",
|
||||
"sr-Cyrl-SP",
|
||||
"sv",
|
||||
"sv-FI",
|
||||
"sv-SE",
|
||||
"sw",
|
||||
"sw-KE",
|
||||
"syr",
|
||||
"syr-SY",
|
||||
"ta",
|
||||
"ta-IN",
|
||||
"te",
|
||||
"te-IN",
|
||||
"th",
|
||||
"th-TH",
|
||||
"tl",
|
||||
"tl-PH",
|
||||
"tn",
|
||||
"tn-ZA",
|
||||
"tr",
|
||||
"tr-TR",
|
||||
"tt",
|
||||
"tt-RU",
|
||||
"ts",
|
||||
"uk",
|
||||
"uk-UA",
|
||||
"ur",
|
||||
"ur-PK",
|
||||
"uz",
|
||||
"uz-UZ",
|
||||
"uz-Cyrl-UZ",
|
||||
"vi",
|
||||
"vi-VN",
|
||||
"xh",
|
||||
"xh-ZA",
|
||||
"zh",
|
||||
"zh-CN",
|
||||
"zh-HK",
|
||||
"zh-MO",
|
||||
"zh-SG",
|
||||
"zh-TW",
|
||||
"zu",
|
||||
"zu-ZA"
|
||||
]
|
||||
})
|
||||
.example(
|
||||
'$0 -o articulated-restraint.epub "https://www.tor.com/2019/02/06/articulated-restraint-mary-robinette-kowal/"'
|
||||
)
|
||||
.demandOption(["url"]);
|
||||
},
|
||||
argv => {
|
||||
generateEPUB(argv.url, argv.output);
|
||||
}
|
||||
).argv;
|
||||
.usage("$0 --output [output] --title [title] <url>")
|
||||
.help("h")
|
||||
.command(
|
||||
"$0 <url>",
|
||||
"Generate EPUB file from URL",
|
||||
yargs => {
|
||||
yargs
|
||||
.positional("url", {
|
||||
describe: "The URL to download",
|
||||
type: "string"
|
||||
})
|
||||
.option("output", {
|
||||
alias: "o",
|
||||
type: "string",
|
||||
default: "url-to-epub.epub",
|
||||
description: "Output file to save EPUB"
|
||||
})
|
||||
.option("title", {
|
||||
alias: "t",
|
||||
type: "string",
|
||||
default: null,
|
||||
description:
|
||||
"Title of the book, if not the same as the page title"
|
||||
})
|
||||
.option("cover-url", {
|
||||
type: "string",
|
||||
default: null,
|
||||
description: "Image URL to download as cover"
|
||||
})
|
||||
.option("language", {
|
||||
alias: "l",
|
||||
type: "string",
|
||||
default: "en-US",
|
||||
description: "A valid language tag",
|
||||
choices: [
|
||||
"af",
|
||||
"af-ZA",
|
||||
"ar",
|
||||
"ar-AE",
|
||||
"ar-BH",
|
||||
"ar-DZ",
|
||||
"ar-EG",
|
||||
"ar-IQ",
|
||||
"ar-JO",
|
||||
"ar-KW",
|
||||
"ar-LB",
|
||||
"ar-LY",
|
||||
"ar-MA",
|
||||
"ar-OM",
|
||||
"ar-QA",
|
||||
"ar-SA",
|
||||
"ar-SY",
|
||||
"ar-TN",
|
||||
"ar-YE",
|
||||
"az",
|
||||
"az-AZ",
|
||||
"az-Cyrl-AZ",
|
||||
"be",
|
||||
"be-BY",
|
||||
"bg",
|
||||
"bg-BG",
|
||||
"bs-BA",
|
||||
"ca",
|
||||
"ca-ES",
|
||||
"cs",
|
||||
"cs-CZ",
|
||||
"cy",
|
||||
"cy-GB",
|
||||
"da",
|
||||
"da-DK",
|
||||
"de",
|
||||
"de-AT",
|
||||
"de-CH",
|
||||
"de-DE",
|
||||
"de-LI",
|
||||
"de-LU",
|
||||
"dv",
|
||||
"dv-MV",
|
||||
"el",
|
||||
"el-GR",
|
||||
"en",
|
||||
"en-AU",
|
||||
"en-BZ",
|
||||
"en-CA",
|
||||
"en-CB",
|
||||
"en-GB",
|
||||
"en-IE",
|
||||
"en-JM",
|
||||
"en-NZ",
|
||||
"en-PH",
|
||||
"en-TT",
|
||||
"en-US",
|
||||
"en-ZA",
|
||||
"en-ZW",
|
||||
"eo",
|
||||
"es",
|
||||
"es-AR",
|
||||
"es-BO",
|
||||
"es-CL",
|
||||
"es-CO",
|
||||
"es-CR",
|
||||
"es-DO",
|
||||
"es-EC",
|
||||
"es-ES",
|
||||
"es-GT",
|
||||
"es-HN",
|
||||
"es-MX",
|
||||
"es-NI",
|
||||
"es-PA",
|
||||
"es-PE",
|
||||
"es-PR",
|
||||
"es-PY",
|
||||
"es-SV",
|
||||
"es-UY",
|
||||
"es-VE",
|
||||
"et",
|
||||
"et-EE",
|
||||
"eu",
|
||||
"eu-ES",
|
||||
"fa",
|
||||
"fa-IR",
|
||||
"fi",
|
||||
"fi-FI",
|
||||
"fo",
|
||||
"fo-FO",
|
||||
"fr",
|
||||
"fr-BE",
|
||||
"fr-CA",
|
||||
"fr-CH",
|
||||
"fr-FR",
|
||||
"fr-LU",
|
||||
"fr-MC",
|
||||
"gl",
|
||||
"gl-ES",
|
||||
"gu",
|
||||
"gu-IN",
|
||||
"he",
|
||||
"he-IL",
|
||||
"hi",
|
||||
"hi-IN",
|
||||
"hr",
|
||||
"hr-BA",
|
||||
"hr-HR",
|
||||
"hu",
|
||||
"hu-HU",
|
||||
"hy",
|
||||
"hy-AM",
|
||||
"id",
|
||||
"id-ID",
|
||||
"is",
|
||||
"is-IS",
|
||||
"it",
|
||||
"it-CH",
|
||||
"it-IT",
|
||||
"ja",
|
||||
"ja-JP",
|
||||
"ka",
|
||||
"ka-GE",
|
||||
"kk",
|
||||
"kk-KZ",
|
||||
"kn",
|
||||
"kn-IN",
|
||||
"ko",
|
||||
"ko-KR",
|
||||
"kok",
|
||||
"kok-IN",
|
||||
"ky",
|
||||
"ky-KG",
|
||||
"lt",
|
||||
"lt-LT",
|
||||
"lv",
|
||||
"lv-LV",
|
||||
"mi",
|
||||
"mi-NZ",
|
||||
"mk",
|
||||
"mk-MK",
|
||||
"mn",
|
||||
"mn-MN",
|
||||
"mr",
|
||||
"mr-IN",
|
||||
"ms",
|
||||
"ms-BN",
|
||||
"ms-MY",
|
||||
"mt",
|
||||
"mt-MT",
|
||||
"nb",
|
||||
"nb-NO",
|
||||
"nl",
|
||||
"nl-BE",
|
||||
"nl-NL",
|
||||
"nn-NO",
|
||||
"ns",
|
||||
"ns-ZA",
|
||||
"pa",
|
||||
"pa-IN",
|
||||
"pl",
|
||||
"pl-PL",
|
||||
"ps",
|
||||
"ps-AR",
|
||||
"pt",
|
||||
"pt-BR",
|
||||
"pt-PT",
|
||||
"qu",
|
||||
"qu-BO",
|
||||
"qu-EC",
|
||||
"qu-PE",
|
||||
"ro",
|
||||
"ro-RO",
|
||||
"ru",
|
||||
"ru-RU",
|
||||
"sa",
|
||||
"sa-IN",
|
||||
"se",
|
||||
"se-FI",
|
||||
"se-NO",
|
||||
"se-SE",
|
||||
"sk",
|
||||
"sk-SK",
|
||||
"sl",
|
||||
"sl-SI",
|
||||
"sq",
|
||||
"sq-AL",
|
||||
"sr-BA",
|
||||
"sr-Cyrl-BA",
|
||||
"sr-SP",
|
||||
"sr-Cyrl-SP",
|
||||
"sv",
|
||||
"sv-FI",
|
||||
"sv-SE",
|
||||
"sw",
|
||||
"sw-KE",
|
||||
"syr",
|
||||
"syr-SY",
|
||||
"ta",
|
||||
"ta-IN",
|
||||
"te",
|
||||
"te-IN",
|
||||
"th",
|
||||
"th-TH",
|
||||
"tl",
|
||||
"tl-PH",
|
||||
"tn",
|
||||
"tn-ZA",
|
||||
"tr",
|
||||
"tr-TR",
|
||||
"tt",
|
||||
"tt-RU",
|
||||
"ts",
|
||||
"uk",
|
||||
"uk-UA",
|
||||
"ur",
|
||||
"ur-PK",
|
||||
"uz",
|
||||
"uz-UZ",
|
||||
"uz-Cyrl-UZ",
|
||||
"vi",
|
||||
"vi-VN",
|
||||
"xh",
|
||||
"xh-ZA",
|
||||
"zh",
|
||||
"zh-CN",
|
||||
"zh-HK",
|
||||
"zh-MO",
|
||||
"zh-SG",
|
||||
"zh-TW",
|
||||
"zu",
|
||||
"zu-ZA"
|
||||
]
|
||||
})
|
||||
.example(
|
||||
'$0 --title "Articulated Restraint" -o articulated-restraint.epub "https://www.tor.com/2019/02/06/articulated-restraint-mary-robinette-kowal/"'
|
||||
)
|
||||
.demandOption(["url"]);
|
||||
},
|
||||
argv => {
|
||||
generateEPUB(argv.url, argv.output, argv.title, argv['cover-url'], argv.language);
|
||||
}
|
||||
).argv;
|
Loading…
Reference in New Issue