Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v0.2.1 -- bugfixes for loading new chapters #22

Merged
merged 4 commits into from
Nov 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"slug": "react-native-manga-reader-app",
"privacy": "public",
"sdkVersion": "33.0.0",
"version": "0.2.0",
"version": "0.2.1",
"platforms": [
"ios",
"android"
Expand Down
2 changes: 0 additions & 2 deletions models/.gitignore

This file was deleted.

24 changes: 17 additions & 7 deletions models/models.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,24 @@ const Manga = types.model('Manga', {
}).actions((self) => ({
loadChapters: flow(function * loadChapters () {
const { chapters, tags, summary } = yield getChapters(self.link)
if (self.chapters.length === 0) {
self.chapters = chapters // just an optimization compared to below
} else {
// merge chapter data if some already persisted
chapters.forEach((chapter, index) => {
self.chapters[index] = { ...self.chapters[index], ...chapter }
})

// merge chapter data if some already persisted
let offset = 0
for (let index = 0; index < self.chapters.length; index++) {
const oldChap = self.chapters[index]
// new set of chapters might be a little ahead, get the offset
for ( ; index + offset < chapters.length; offset++) {
// found the offset, break out
if (oldChap.link === chapters[index + offset].link) break
}
// if no matches, break out
if (index + offset >= chapters.length) break

// merge into the new list with new overriding old
chapters[index + offset] = {...oldChap, ...chapters[index + offset]}
}

self.chapters = chapters // set to the new, merged list
self.tags = tags
self.summary = summary
})
Expand Down
3 changes: 3 additions & 0 deletions models/scraperDrivers/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# don't commit site names or URLs for now
allDrivers.js
driver*URLS.js
59 changes: 59 additions & 0 deletions models/scraperDrivers/driver1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
export { searchURL, latestURL } from './driver1URLs.js'

export function getSearch ($) {
return $('.post-list li')
.map((index, el) => ({
link: $(el).find('a').attr('href'),
title: $(el).find('img').attr('title'),
cover: $(el).find('img').attr('src')
}))
.get()
}

export function getLatest ($) {
return $('.post')
.map((index, el) => ({
link: $(el).find('a').attr('href'),
title: $(el).find('img').attr('title'),
cover: $(el).find('img').attr('src'),
release: $(el).find('em').text()
}))
.get()
}

export function getChapters ($) {
const title = $('.manga-detail-top .title').text().trim()
const chapters = $('.chlist a')
.map((index, el) => {
const dateText = $(el).find(':not(.newch)').text()
// if "hours ago". "days ago", "Today", etc, just use now
const isRelative = dateText.includes('ago') ||
dateText.includes('Today') ||
dateText.includes('Yesterday')
const date = new Date(isRelative ? Date.now() : dateText)

return {
link: $(el).attr('href').replace('//', 'http://'),
title: $(el).text().match(/[0-9]+/)[0] || '0',
date
}
})
.get()
const tags = $('.manga-genres li')
.map((index, el) => $(el).text().trim())
.get()
const summary = $('.manga-summary').text().trim()
return { title, chapters, tags, summary }
}

export function getPages ($) {
return $('.mangaread-page option')
.map((index, el) => ({
link: $(el).attr('value').replace('//', 'http://')
}))
.get()
}

export function getImage ($) {
return $('#viewer img').attr('src')
}
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "react-native-manga-reader-app",
"description": "A React Native / Expo app for cross-platform manga reading",
"version": "0.2.0",
"version": "0.2.1",
"main": "node_modules/expo/AppEntry.js",
"scripts": {
"start": "expo start",
Expand Down