Add ReadLightNovel
This commit is contained in:
@@ -21,6 +21,7 @@ import { githubUpdateChecker } from "../Hooks/githubUpdateChecker";
|
||||
import NewUpdateDialog from "../Components/NewUpdateDialog";
|
||||
import { NavigationContainer } from "@react-navigation/native";
|
||||
import BrowseNovelUpdates from "../Screens/Browse/discover/BrowseNovelUpdates";
|
||||
import NewExtension from "../Screens/testnewsource";
|
||||
|
||||
const Stack = createStackNavigator();
|
||||
|
||||
@@ -59,6 +60,7 @@ const MainNavigator = () => {
|
||||
<Stack.Screen name="MoreStack" component={MoreStack} />
|
||||
<Stack.Screen name="Extension" component={Extension} />
|
||||
<Stack.Screen name="BrowseMal" component={MalTopNovels} />
|
||||
<Stack.Screen name="NewExt" component={NewExtension} />
|
||||
<Stack.Screen
|
||||
name="BrowseNovelUpdates"
|
||||
component={BrowseNovelUpdates}
|
||||
|
||||
@@ -6,6 +6,7 @@ import {
|
||||
FlatList,
|
||||
ActivityIndicator,
|
||||
RefreshControl,
|
||||
Button,
|
||||
} from "react-native";
|
||||
import { useTheme } from "../../Hooks/reduxHooks";
|
||||
import { useDispatch, useSelector } from "react-redux";
|
||||
@@ -90,7 +91,10 @@ const Browse = ({ navigation }) => {
|
||||
},
|
||||
]}
|
||||
/>
|
||||
|
||||
<Button
|
||||
title="Read Light Novel"
|
||||
onPress={() => navigation.navigate("NewExt")}
|
||||
/>
|
||||
<FlatList
|
||||
contentContainerStyle={{ flexGrow: 1 }}
|
||||
data={!searchText ? sources : search}
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
import React from "react";
|
||||
import { useState } from "react";
|
||||
import { Button, Text } from "react-native";
|
||||
import { ScreenContainer } from "../Components/Common";
|
||||
import { useTheme } from "../Hooks/reduxHooks";
|
||||
import {
|
||||
popularNovels,
|
||||
parseNovelAndChapters,
|
||||
} from "../sources/en/readlightnovel";
|
||||
|
||||
const NewExtension = () => {
|
||||
const theme = useTheme();
|
||||
|
||||
const [novels, setNovels] = useState([]);
|
||||
const [novel, setNovel] = useState([]);
|
||||
|
||||
const onPress = async () => {
|
||||
const data = await parseNovelAndChapters("martial-god-asura");
|
||||
console.log(data);
|
||||
};
|
||||
|
||||
return (
|
||||
<ScreenContainer theme={theme}>
|
||||
<Text style={{ color: theme.colorAccent, paddingTop: 80 }}>
|
||||
New Ext
|
||||
</Text>
|
||||
<Button title="Popular Novels" onPress={onPress} />
|
||||
{novels && (
|
||||
<Text style={{ color: theme.colorAccent, paddingTop: 80 }}>
|
||||
{JSON.stringify(novels)}
|
||||
</Text>
|
||||
)}
|
||||
</ScreenContainer>
|
||||
);
|
||||
};
|
||||
|
||||
export default NewExtension;
|
||||
@@ -0,0 +1,126 @@
|
||||
import cheerio from "react-native-cheerio";
|
||||
|
||||
const sourceId = 2;
|
||||
|
||||
const sourceName = "ReadLightNovel";
|
||||
|
||||
const lang = "en";
|
||||
|
||||
const baseUrl = "https://www.readlightnovel.org";
|
||||
|
||||
const searchUrl = "https://www.readlightnovel.org/detailed-search";
|
||||
|
||||
const popularNovels = async (page) => {
|
||||
const url = `${baseUrl}/top-novel/${page}`;
|
||||
|
||||
const result = await fetch(url);
|
||||
const body = await result.text();
|
||||
|
||||
const $ = cheerio.load(body);
|
||||
|
||||
const novels = [];
|
||||
|
||||
$(".top-novel-block").each(function (result) {
|
||||
const novelName = $(this).find("h2 > a").text();
|
||||
const novelCover = $(this).find("img").attr("src");
|
||||
const novelUrl = $(this)
|
||||
.find("h2 > a")
|
||||
.attr("href")
|
||||
.replace(`${baseUrl}/`, "");
|
||||
|
||||
const novel = {
|
||||
novelName,
|
||||
novelCover,
|
||||
novelUrl,
|
||||
};
|
||||
|
||||
novels.push(novel);
|
||||
});
|
||||
|
||||
return novels;
|
||||
};
|
||||
|
||||
const parseNovelAndChapters = async (novelUrl) => {
|
||||
const url = `${baseUrl}/${novelUrl}`;
|
||||
|
||||
const result = await fetch(url);
|
||||
const body = await result.text();
|
||||
|
||||
$ = cheerio.load(body);
|
||||
|
||||
let novel;
|
||||
|
||||
const novelName = $(".block-title > h1").text();
|
||||
|
||||
const novelCover = $(".novel-cover > a > img").attr("src");
|
||||
|
||||
let author, artist, genre, summary;
|
||||
|
||||
$(".novel-detail-item").each(function (result) {
|
||||
const detailName = $(this).find(".novel-detail-header > h6").text();
|
||||
const detail = $(this).find(".novel-detail-body").text();
|
||||
|
||||
switch (detailName) {
|
||||
case "Genre":
|
||||
genre = detail.replace(/[\t\n]/g, ",");
|
||||
break;
|
||||
case "Author(s)":
|
||||
author = detail.trim();
|
||||
break;
|
||||
case "Artist(s)":
|
||||
artist = detail.trim();
|
||||
break;
|
||||
case "Description":
|
||||
summary = detail;
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
let chapters = [];
|
||||
|
||||
$(".panel").each(function (res) {
|
||||
let volumeName = $(this).find("h4.panel-title").text();
|
||||
|
||||
$(this)
|
||||
.find("ul.chapter-chs > li")
|
||||
.each(function (result) {
|
||||
let chapterName = $(this).find("a").text();
|
||||
|
||||
const releaseDate = null;
|
||||
|
||||
const chapterUrl = $(this)
|
||||
.find("a")
|
||||
.attr("href")
|
||||
.replace(`${baseUrl}/${novelUrl}/`, "");
|
||||
|
||||
if (volumeName.includes("Volume")) {
|
||||
chapterName = volumeName + " " + chapterName;
|
||||
}
|
||||
|
||||
const chapter = {
|
||||
chapterName,
|
||||
releaseDate,
|
||||
chapterUrl,
|
||||
};
|
||||
|
||||
chapters.push(chapter);
|
||||
});
|
||||
});
|
||||
|
||||
novel = {
|
||||
sourceId,
|
||||
sourceName,
|
||||
url,
|
||||
novelName,
|
||||
novelCover,
|
||||
genre,
|
||||
author,
|
||||
artist,
|
||||
summary,
|
||||
chapters,
|
||||
};
|
||||
|
||||
return novel;
|
||||
};
|
||||
|
||||
export { popularNovels, parseNovelAndChapters };
|
||||
Reference in New Issue
Block a user