mirror of
https://github.com/daniel-j/fimfic2epub.git
synced 2024-06-02 10:34:32 +12:00
more features
This commit is contained in:
parent
44a641e7d3
commit
5555b20d47
|
@ -4,7 +4,7 @@
|
||||||
"name": "fimfic2epub",
|
"name": "fimfic2epub",
|
||||||
"short_name": "fimfic2epub",
|
"short_name": "fimfic2epub",
|
||||||
"description": "Improved EPUB exporter for Fimfiction",
|
"description": "Improved EPUB exporter for Fimfiction",
|
||||||
"version": "1.1.3",
|
"version": "1.1.5",
|
||||||
|
|
||||||
"icons": {
|
"icons": {
|
||||||
"128": "icon-128.png"
|
"128": "icon-128.png"
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "fimfic2epub",
|
"name": "fimfic2epub",
|
||||||
"version": "1.1.3",
|
"version": "1.1.5",
|
||||||
"description": "Tool to generate EPUB ebooks from fimfiction stories",
|
"description": "Tool to generate EPUB ebooks from fimfiction stories",
|
||||||
"author": "djazz",
|
"author": "djazz",
|
||||||
"repository": {
|
"repository": {
|
||||||
|
|
|
@ -19,17 +19,49 @@ const entities = new XmlEntities()
|
||||||
|
|
||||||
module.exports = class FimFic2Epub {
|
module.exports = class FimFic2Epub {
|
||||||
|
|
||||||
constructor (storyId) {
|
static getStoryId (id) {
|
||||||
this.storyId = storyId
|
if (isNaN(id)) {
|
||||||
if (isNaN(storyId)) {
|
let url = URL.parse(id, false, true)
|
||||||
let url = URL.parse(storyId, false, true)
|
|
||||||
if (url.hostname === 'www.fimfiction.net' || url.hostname === 'fimfiction.net') {
|
if (url.hostname === 'www.fimfiction.net' || url.hostname === 'fimfiction.net') {
|
||||||
let m = url.pathname.match(/^\/story\/(\d+)/)
|
let m = url.pathname.match(/^\/story\/(\d+)/)
|
||||||
if (m) {
|
if (m) {
|
||||||
this.storyId = m[1]
|
id = m[1]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return id
|
||||||
|
}
|
||||||
|
|
||||||
|
static getFilename (storyInfo) {
|
||||||
|
return sanitize(storyInfo.title + ' by ' + storyInfo.author.name + '.epub')
|
||||||
|
}
|
||||||
|
|
||||||
|
static fetchStoryInfo (storyId) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
storyId = FimFic2Epub.getStoryId(storyId)
|
||||||
|
let url = 'https://www.fimfiction.net/api/story.php?story=' + storyId
|
||||||
|
fetchRemote(url, (raw, type) => {
|
||||||
|
let data
|
||||||
|
try {
|
||||||
|
data = JSON.parse(raw)
|
||||||
|
} catch (e) {}
|
||||||
|
if (!data) {
|
||||||
|
reject('Unable to fetch story info')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (data.error) {
|
||||||
|
reject(data.error)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (!data.story.chapters) data.story.chapters = []
|
||||||
|
resolve(data.story)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
constructor (storyId) {
|
||||||
|
this.storyId = FimFic2Epub.getStoryId(storyId)
|
||||||
|
|
||||||
this.hasDownloaded = false
|
this.hasDownloaded = false
|
||||||
this.isDownloading = false
|
this.isDownloading = false
|
||||||
this.zip = null
|
this.zip = null
|
||||||
|
@ -69,26 +101,11 @@ module.exports = class FimFic2Epub {
|
||||||
|
|
||||||
console.log('Fetching story metadata...')
|
console.log('Fetching story metadata...')
|
||||||
|
|
||||||
let url = 'https://www.fimfiction.net/api/story.php?story=' + this.storyId
|
FimFic2Epub.fetchStoryInfo(this.storyId).then((storyInfo) => {
|
||||||
fetchRemote(url, (raw, type) => {
|
this.storyInfo = storyInfo
|
||||||
let data
|
|
||||||
try {
|
|
||||||
data = JSON.parse(raw)
|
|
||||||
} catch (e) {}
|
|
||||||
if (!data) {
|
|
||||||
reject('Unable to fetch story json')
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if (data.error) {
|
|
||||||
reject(data.error)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
this.storyInfo = data.story
|
|
||||||
this.storyInfo.chapters = this.storyInfo.chapters || []
|
|
||||||
this.storyInfo.uuid = 'urn:fimfiction:' + this.storyInfo.id
|
this.storyInfo.uuid = 'urn:fimfiction:' + this.storyInfo.id
|
||||||
|
|
||||||
this.filename = sanitize(this.storyInfo.title + ' by ' + this.storyInfo.author.name + '.epub')
|
this.filename = FimFic2Epub.getFilename(this.storyInfo)
|
||||||
|
|
||||||
this.zip.file('Styles/style.css', styleCss)
|
this.zip.file('Styles/style.css', styleCss)
|
||||||
this.zip.file('Styles/coverstyle.css', coverstyleCss)
|
this.zip.file('Styles/coverstyle.css', coverstyleCss)
|
||||||
|
@ -100,14 +117,13 @@ module.exports = class FimFic2Epub {
|
||||||
this.zip.file('Text/nav.xhtml', template.createNav(this))
|
this.zip.file('Text/nav.xhtml', template.createNav(this))
|
||||||
|
|
||||||
this.fetchTitlePage(resolve, reject)
|
this.fetchTitlePage(resolve, reject)
|
||||||
})
|
}).catch(reject)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fetchTitlePage (resolve, reject) {
|
fetchTitlePage (resolve, reject) {
|
||||||
console.log('Fetching index page...')
|
console.log('Fetching index page...')
|
||||||
let url = this.storyInfo.url
|
fetchRemote(this.storyInfo.url, (raw, type) => {
|
||||||
fetchRemote(url, (raw, type) => {
|
|
||||||
this.extractTitlePageInfo(raw).then(() => this.checkCoverImage(resolve, reject))
|
this.extractTitlePageInfo(raw).then(() => this.checkCoverImage(resolve, reject))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue