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

added new connector 'Hattori Manga' #7386

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
117 changes: 117 additions & 0 deletions src/web/mjs/connectors/HattoriManga.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
import Connector from '../engine/Connector.mjs';

export default class HattoriManga extends Connector {
constructor() {
super();
super.id = 'hattorimanga';
super.label = 'Hattori Manga';
this.tags = ['webtoon', 'turkish'];
this.url = 'https://www.hattorimanga.net';
this.links = {
login: 'https://www.hattorimanga.net/giris'
};
}

async _getMangas() {
const mangas = [];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer a simpler approach

   async _getMangas() {
        const mangaList = [];
        for (let page = 1, run = true; run; page++) {
            const mangas = await this._getMangasFromPage(page);
            mangas.length > 0 ? mangaList.push(...mangas) : run = false;
        }
        return mangaList;
    }

    async _getMangasFromPage(page) {
    .....
    }

let page = 1;
let hasMorePages = true;

while (hasMorePages) {
let request = new Request(`${this.url}/manga?page=${page}`, this.requestOptions);
let data = await this.fetchDOM(request, 'div.manga-card h5 a'); // CSS seçicisini özelleþtirir
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we really dont need comment for trivial things :)


if (data.length > 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for that. Map will just do nothing after in case its empty.

mangas.push(...data.map(element => ({
id: this.getRootRelativeOrAbsoluteLink(element, this.url),
title: element.text.trim()
})));

page++;
} else {
hasMorePages = false;
}
}

return mangas;
}

async _getChapters(manga) {
manga.id = manga.id.replace('manga/', '');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dont "replace"

Make sure you keep only the needed part when you gather mangas.

let allChapters = [];
let page = 1;
const lastPage = await this._getLastPage(manga.id);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use this.fetchJSON. you can even use it to populate many variables directly

const chapterList= [];

for (let page = 1, run = true; run = false; page ++ {

 const { chapters, lastPage } = await this.fetchJSON(.....);
 chapterList.push(... chapters.map());
 run = lastPage != page;
}

return chapterList;

while (page <= lastPage) {
let uri = `${this.url}/load-more-chapters${manga.id}?page=${page}`;
try {
const response = await fetch(uri);
const veri = await response.json();
allChapters = allChapters.concat(veri.chapters.map(element => {
let chapterId = `${this.url}/manga/${element.manga_slug}/${element.chapter_slug}`;
return {
id: chapterId,
title: element.title
};
}));
page++;
} catch (error) {
console.error('Hata:', error);
break;
}
}
return allChapters;
}

async _getLastPage(mangaId) {
let uri = `${this.url}/load-more-chapters${mangaId}?page=1`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

useless

try {
const response = await fetch(uri);
const veri = await response.json();
return veri.lastPage;
} catch (error) {
console.error('Hata:', error);
return 1;
}
}

async _getPages(chapter) {
try {
// Verilen chapterUrl'den HTML içeriðini alýr
Copy link
Contributor

@MikeZeDev MikeZeDev Sep 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do not use fetch directly. We have this.fetdhDOM for that

Moreover, what are you doing?

chapter.id, like manga.id are NEVER supposed to be full flegged url.
We only save relative paths, or when the website allows it, the identifier used in the own website api.

If you try to await fetch(chapter.id); i dont see how its supposed to work.

At least, if you save chapter PATH as chapter.id (something like /manga/mymanga/chapterXX" you should create a real url using new URL() and this.url.

const response = await fetch(chapter.id);
if (!response.ok) {
throw new Error('Network response was not ok');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we dont care. Network error ill be thrown in console without that and thats what we want.
use Fetchdom by all means.

}
const html = await response.text();

// HTML içeriði bir DOM nesnesine dönüþür
const parser = new DOMParser();
const doc = parser.parseFromString(html, 'text/html');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The goal of using this.Fetchdom is to get the nodes we wants as an array. use it and remove all that.
One particular thing : in Hakuneko context, CSS selector for img is "source", not "img" .

Use "div.image-wrapper source".


// CSS seçiciyi kullanarak tüm resim elementlerini seçme
const imgElements = doc.querySelectorAll('div.image-wrapper img');

// Resim URL'leri bir diziye dönüþür
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to comments obvious things

const imageUrls = Array.from(imgElements).map(img => `${this.url}${img.getAttribute('data-src') || img.src}`);
console.log(imageUrls);

return imageUrls;
} catch (error) {
console.error('Error fetching the pages:', error);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove console log
No need for a try catch

return [];
}
}

// async iþlevi fetchMangaPages bir sýnýf yöntemi olmalýdýr
Copy link
Contributor

@MikeZeDev MikeZeDev Sep 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you really want to comment, dont do it in turkish. No offense but it wont really help in that case.

async fetchMangaPages(manga) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whats the purpose of this function?

try {
let chapters = await this._getChapters(manga);
for (let chapter of chapters) {
let pages = await this._getPages(chapter);
console.log(`Pages for ${chapter.id}:`, pages);
}
} catch (error) {
console.error('Error fetching manga pages:', error);
}
}
}
Loading