-
Notifications
You must be signed in to change notification settings - Fork 470
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 = []; | ||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we really dont need comment for trivial things :) |
||
|
||
if (data.length > 0) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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/', ''); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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`; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. If you try to 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'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
} | ||
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'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove console log |
||
return []; | ||
} | ||
} | ||
|
||
// async iþlevi fetchMangaPages bir sýnýf yöntemi olmalýdýr | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer a simpler approach