Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…into 0.8
  • Loading branch information
hammyo-o committed Dec 9, 2024
2 parents 20277f1 + d1c15d2 commit a578054
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
6 changes: 6 additions & 0 deletions src/NHentai/NHentaiHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ class NHSortOrderClass {
name: 'Most Recent',
NHCode: 'date',
shortcuts: ['s:r', 's:recent', 'sort:r', 'sort:recent']
},
{
// Sort by popular this month
name: 'Popular This Month',
NHCode: 'popular-month',
shortcuts: ['s:pm', 's:m', 's:popular-month', 'sort:pm', 'sort:m', 'sort:popular-month']
}
]

Expand Down
19 changes: 13 additions & 6 deletions src/NHentai/NHentaiParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import {
ChapterDetails,
PartialSourceManga,
Tag,
Chapter
Chapter,
SourceStateManager
} from '@paperback/types'

import { NHLanguages } from './NHentaiHelper'
Expand Down Expand Up @@ -60,18 +61,17 @@ export const parseChapterDetails = (data: Gallery, mangaId: string): ChapterDeta
})
}

export const parseSearch = (data: QueryResponse): PartialSourceManga[] => {
export const parseSearch = (data: QueryResponse, readMangaIds: string[]): PartialSourceManga[] => {
const tiles: PartialSourceManga[] = []
const collectedIds: string[] = []

if (!data?.result) {
console.log(JSON.stringify(data))
throw new Error('JSON NO RESULT ERROR!\n\nYou\'ve like set too many additional arguments in this source\'s settings, remove some to see results!\nSo search with tags you need to use arguments like shown in the sourc\'s settings!')
throw new Error('JSON NO RESULT ERROR!\n\nYou\'ve like set too many additional arguments in this source\'s settings, remove some to see results!\nSo search with tags you need to use arguments like shown in the source\'s settings!')
}

for (const gallery of data.result) {

if (collectedIds.includes(gallery.id.toString())) continue
if (collectedIds.includes(gallery.id.toString()) || readMangaIds.includes(gallery.id.toString())) continue
tiles.push(App.createPartialSourceManga({
image: `https://t3.nhentai.net/galleries/${gallery.media_id}/cover.${typeOfImage(gallery.images.cover)}`,
title: gallery.title.pretty,
Expand All @@ -83,11 +83,17 @@ export const parseSearch = (data: QueryResponse): PartialSourceManga[] => {
return tiles
}

export const addToReadMangaIds = async (stateManager: SourceStateManager, mangaId: string): Promise<void> => {
const readMangaIds = await stateManager.retrieve('read_manga_ids') ?? {}
readMangaIds[mangaId] = true
await stateManager.store('read_manga_ids', readMangaIds)
}

// Utility
function capitalizeTags(str: string) {
return str.split(' ').map(word => {
return word.charAt(0).toUpperCase() + word.slice(1)
}).join(' ')
}).join(' ')
}

const typeMap: { [key: string]: string; } = { 'j': 'jpg', 'p': 'png', 'g': 'gif', 'w': 'webp'}
Expand All @@ -96,6 +102,7 @@ const typeOfImage = (image: ImagePageObject): string => {
return typeMap[image.t] ?? ''
}


const getArtist = (gallery: Gallery): string => {
const tags: TagObject[] = gallery.tags
for (const tag of tags) {
Expand Down

0 comments on commit a578054

Please sign in to comment.