Skip to content

Commit

Permalink
rouman5 plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
youniaogu committed Oct 21, 2023
1 parent 182b644 commit 0202cc7
Show file tree
Hide file tree
Showing 11 changed files with 489 additions and 102 deletions.
102 changes: 11 additions & 91 deletions src/components/ComicImage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@ import {
StyleProp,
ImageStyle,
} from 'react-native';
import { aspectFit, AsyncStatus, LayoutMode, Orientation, ScrambleType, unscramble } from '~/utils';
import { CachedImage, CacheManager } from '@georstat/react-native-image-cache';
import { aspectFit, AsyncStatus, LayoutMode, Orientation } from '~/utils';
import { useFocusEffect } from '@react-navigation/native';
import { Center, Image } from 'native-base';
import { useDimensions } from '~/hooks';
import Canvas, { Image as CanvasImage } from 'react-native-canvas';
import ErrorWithRetry from '~/components/ErrorWithRetry';
import FastImage, { ImageStyle as FastImageStyle, ResizeMode } from 'react-native-fast-image';
import md5 from 'blueimp-md5';

const groundPoundGif = require('~/assets/ground_pound.gif');
const windowScale = Dimensions.get('window').scale;
Expand Down Expand Up @@ -49,7 +48,8 @@ export interface ImageProps {
onChange?: (state: ImageState, idx?: number) => void;
}
export interface ComicImageProps extends ImageProps {
useJMC?: boolean;
needUnscramble?: boolean;
scrambleType?: ScrambleType;
}

const DefaultImage = ({
Expand Down Expand Up @@ -192,14 +192,15 @@ const DefaultImage = ({
);
};

const JMCImage = ({
const ScrambleImage = ({
uri,
index,
headers = {},
layoutMode = LayoutMode.Horizontal,
prevState = defaultState,
onChange,
}: ImageProps) => {
scrambleType,
}: ImageProps & { scrambleType?: ScrambleType }) => {
const { width: windowWidth, height: windowHeight, orientation } = useDimensions();
const [imageState, setImageState] = useState(prevState);
const defaultFillHeight = useMemo(() => (windowHeight * 3) / 5, [windowHeight]);
Expand Down Expand Up @@ -256,7 +257,7 @@ const JMCImage = ({
// https://github.com/facebook/react-native/issues/33498
const width = event.target.width;
const height = event.target.height;
const step = unscramble(i, width, height);
const step = unscramble(i, width, height, scrambleType);

if (canvasRef.current) {
// if image size more than maxPixelSize, scale image to smaller
Expand Down Expand Up @@ -303,7 +304,7 @@ const JMCImage = ({
handleError();
}
},
[imageState, updateData, handleError, windowWidth, windowHeight]
[imageState, updateData, handleError, windowWidth, windowHeight, scrambleType]
);
const loadImage = useCallback(() => {
setImageState((state) => ({ ...state, loadStatus: AsyncStatus.Pending }));
Expand Down Expand Up @@ -382,90 +383,9 @@ const styles = StyleSheet.create({
},
});

function getChapterId(uri: string) {
const [, id] = uri.match(/\/([0-9]+)\//) || [];
return Number(id);
}
function getPicIndex(uri: string) {
const [, index] = uri.match(/\/([0-9]+)\./) || [];
return index;
}
function getSplitNum(id: number, index: string) {
var a = 10;
if (id >= 268850) {
const str = md5(id + index);
const nub = str.substring(str.length - 1).charCodeAt(0) % (id >= 421926 ? 8 : 10);

switch (nub) {
case 0:
a = 2;
break;
case 1:
a = 4;
break;
case 2:
a = 6;
break;
case 3:
a = 8;
break;
case 4:
a = 10;
break;
case 5:
a = 12;
break;
case 6:
a = 14;
break;
case 7:
a = 16;
break;
case 8:
a = 18;
break;
case 9:
a = 20;
}
}
return a;
}
function unscramble(uri: string, width: number, height: number) {
const step = [];
const id = getChapterId(uri);
const index = getPicIndex(uri);
const numSplit = getSplitNum(id, index);
const perheight = height % numSplit;

for (let i = 0; i < numSplit; i++) {
let sHeight = Math.floor(height / numSplit);
let dy = sHeight * i;
const sy = height - sHeight * (i + 1) - perheight;

if (i === 0) {
sHeight += perheight;
} else {
dy += perheight;
}

step.push({
sx: 0,
sy,
sWidth: width,
sHeight,
dx: 0,
dy,
dWidth: width,
dHeight: sHeight,
});
}

return step;
}

const ComicImage = ({ useJMC, ...props }: ComicImageProps) => {
if (useJMC) {
return <JMCImage {...props} />;
const ComicImage = ({ scrambleType, needUnscramble, ...props }: ComicImageProps) => {
if (needUnscramble) {
return <ScrambleImage scrambleType={scrambleType} {...props} />;
}

return <DefaultImage {...props} />;
Expand Down
18 changes: 11 additions & 7 deletions src/components/Reader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import React, {
ForwardRefRenderFunction,
} from 'react';
import { FlashList, ListRenderItemInfo, ViewToken } from '@shopify/flash-list';
import { LayoutMode, PositionX } from '~/utils';
import { LayoutMode, PositionX, ScrambleType } from '~/utils';
import { useFocusEffect } from '@react-navigation/native';
import { useDimensions } from '~/hooks';
import { Box, Flex } from 'native-base';
Expand All @@ -21,6 +21,7 @@ export interface ReaderProps {
layoutMode?: LayoutMode;
data?: {
uri: string;
scrambleType?: ScrambleType;
needUnscramble?: boolean | undefined;
pre: number;
current: number;
Expand Down Expand Up @@ -148,7 +149,7 @@ const Reader: ForwardRefRenderFunction<ReaderRef, ReaderProps> = (
onPageChangeRef.current && onPageChangeRef.current(last.item[0].pre + last.item[0].current - 1);
};
const renderHorizontalItem = ({ item, index }: ListRenderItemInfo<(typeof data)[0]>) => {
const { uri, needUnscramble } = item;
const { uri, scrambleType, needUnscramble } = item;
const horizontalState = horizontalStateRef.current[index];
return (
<Controller
Expand All @@ -159,7 +160,8 @@ const Reader: ForwardRefRenderFunction<ReaderRef, ReaderProps> = (
<ComicImage
uri={uri}
index={index}
useJMC={needUnscramble}
scrambleType={scrambleType}
needUnscramble={needUnscramble}
headers={headers}
prevState={horizontalState}
layoutMode={LayoutMode.Horizontal}
Expand All @@ -172,7 +174,7 @@ const Reader: ForwardRefRenderFunction<ReaderRef, ReaderProps> = (
);
};
const renderVerticalItem = ({ item, index }: ListRenderItemInfo<(typeof data)[0]>) => {
const { uri, needUnscramble } = item;
const { uri, scrambleType, needUnscramble } = item;
const verticalState = verticalStateRef.current[index];
return (
<Box overflow="hidden">
Expand All @@ -183,7 +185,8 @@ const Reader: ForwardRefRenderFunction<ReaderRef, ReaderProps> = (
<ComicImage
uri={uri}
index={index}
useJMC={needUnscramble}
scrambleType={scrambleType}
needUnscramble={needUnscramble}
headers={headers}
prevState={verticalState}
layoutMode={LayoutMode.Vertical}
Expand All @@ -206,7 +209,7 @@ const Reader: ForwardRefRenderFunction<ReaderRef, ReaderProps> = (
alignItems="center"
justifyContent="center"
>
{item.map(({ uri, needUnscramble, chapterHash, current }, i) => {
{item.map(({ uri, scrambleType, needUnscramble, chapterHash, current }, i) => {
const multipleState = (multipleStateRef.current[index] || [])[i];
return (
<Box key={uri}>
Expand All @@ -218,7 +221,8 @@ const Reader: ForwardRefRenderFunction<ReaderRef, ReaderProps> = (
<ComicImage
uri={uri}
index={index}
useJMC={needUnscramble}
scrambleType={scrambleType}
needUnscramble={needUnscramble}
headers={headers}
prevState={multipleState}
layoutMode={LayoutMode.Multiple}
Expand Down
1 change: 1 addition & 0 deletions src/plugins/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export enum Plugin {
PICA = 'PICA',
MBZ = 'MBZ',
BZM = 'BZM',
RM5 = 'RM5',
}

export enum Options {
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import NH from './nh';
import PICA from './pica';
import MBZ from './mbz';
import BZM from './bzm';
import RM5 from './rm5';

export * from './base';

Expand All @@ -21,6 +22,7 @@ export const PluginMap = new Map<Plugin, Base>([
[JMC.id, JMC],
[NH.id, NH],
[PICA.id, PICA],
[RM5.id, RM5],
[KL.id, KL],
[BZM.id, BZM],
[DMZJ.id, DMZJ],
Expand Down
3 changes: 2 additions & 1 deletion src/plugins/jmc.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Base, { Plugin, Options } from './base';
import { MangaStatus, ErrorMessage } from '~/utils';
import { MangaStatus, ErrorMessage, ScrambleType } from '~/utils';
import { Platform } from 'react-native';
import * as cheerio from 'cheerio';

Expand Down Expand Up @@ -354,6 +354,7 @@ class CopyManga extends Base {
},
images: images.map((uri) => ({
uri,
type: ScrambleType.JMC,
needUnscramble: !uri.includes('.gif') && Number(chapterId) >= Number(scrambleId),
})),
},
Expand Down
Loading

0 comments on commit 0202cc7

Please sign in to comment.