Spaces:
Running
Running
NotLucifer18 commited on
Commit ·
cb57a9e
1
Parent(s): 9c4d6bf
Add MangaKatana scraper
Browse filesFiles changed (6)
- .claude/settings.local.json+14-1
- Webs/__init__.py+2
- Webs/mangakatana.pyAdded+138
- Webs/scraper.py+9-2
- test_images.pyAdded+19
- test_sites.pyAdded+43
87 unmodified lines8889909192939487 unmodified lines"Bash(cd /tmp)","Bash(gh api:*)","WebFetch(domain:www.urlert.com)","Bash(python3:*)"]}}87 unmodified lines88899091929394959697989910010110210310410510610787 unmodified lines"Bash(cd /tmp)","Bash(gh api:*)","WebFetch(domain:www.urlert.com)","Bash(python3:*)","WebFetch(domain:gist.github.com)","Bash(xargs cat:*)","Bash(curl -sL \"https://raw.githubusercontent.com/keiyoushi/extensions-source/main/src/all/allmanga/src/eu/kanade/tachiyomi/extension/all/allmanga/AllManga.kt\")","Bash(curl -sL \"https://api.github.com/search/code?q=tobeparsed+repo:keiyoushi/extensions-source\" -H \"Accept: application/vnd.github.v3+json\")","Bash(gh search:*)","Bash(curl -sL \"https://codeberg.org/api/v1/repos/keiyoushi/extensions-source/contents/src/all\")","WebFetch(domain:tachiyomii-apk.com)","WebFetch(domain:www.techmediatoday.com)","WebFetch(domain:edimakor.hitpaw.com)","WebFetch(domain:deepwiki.com)","WebFetch(domain:fliflik.com)","WebFetch(domain:comick-source-api.notaspider.dev)","WebFetch(domain:everythingmoe.com)"]}}
12 unmodified lines13141516171811 unmodified lines3031323312 unmodified linesfrom .mangapill import MangaPillWebsfrom .roliascans import RoliaScanWebsfrom .allmanga import AllMangaWebsweb_data = {" Asura Scans ": AsuraScansWebs(),11 unmodified lines" MangaPill ": MangaPillWebs()," RoliaScan ": RoliaScanWebs()," AllManga ": AllMangaWebs(),}12 unmodified lines1314151617181911 unmodified lines313233343512 unmodified linesfrom .mangapill import MangaPillWebsfrom .roliascans import RoliaScanWebsfrom .allmanga import AllMangaWebsfrom .mangakatana import MangaKatanaWebsweb_data = {" Asura Scans ": AsuraScansWebs(),11 unmodified lines" MangaPill ": MangaPillWebs()," RoliaScan ": RoliaScanWebs()," AllManga ": AllMangaWebs()," MangaKatana ": MangaKatanaWebs(),}
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138from .scraper import Scraperfrom bs4 import BeautifulSoupimport refrom loguru import loggerfrom urllib.parse import quote_plus, urljoinfrom .utitls import DEAULT_MSG_FORMAT
class MangaKatanaWebs(Scraper): def __init__(self): super().__init__() self.url = "https://mangakatana.com/" self.bg = None self.sf = "mkatana" self.headers = { "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", "Accept-Language": "en-US,en;q=0.9", "Connection": "keep-alive", "Referer": "https://mangakatana.com/", "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36" }
async def search(self, query: str = ""): url = f"https://mangakatana.com/?search={quote_plus(query)}&search_by=book_name" content = await self.get(url, cs=True, headers=self.headers) if not content: return []
results = [] bs = BeautifulSoup(content, "html.parser") items = bs.find_all("div", class_="item") for item in items: try: a_tag = item.find("a") if not a_tag: continue href = a_tag.get("href", "").strip() if not href: continue title_tag = item.find("h3", class_="title") title = title_tag.text.strip() if title_tag else a_tag.get("title", "Unknown") img_tag = item.find("img") poster = "" if img_tag: poster = (img_tag.get("src") or img_tag.get("data-src", "")).strip() results.append({ "url": href, "title": title, "poster": poster }) except Exception as e: logger.error(f"MangaKatana parse search item error: {e}") continue
return results
async def get_chapters(self, data, page: int = 1): results = data content = await self.get(results["url"], cs=True, headers=self.headers) if not content: return results
bs = BeautifulSoup(content, "html.parser") # Meta info desc = "N/A" desc_meta = bs.find("meta", property="og:description") if desc_meta and desc_meta.get("content"): desc = desc_meta["content"].strip() genres = "N/A" genres_container = bs.find("div", class_="genres") if genres_container: genres_list = [a.text.strip() for a in genres_container.find_all("a")] if genres_list: genres = ", ".join(genres_list) status_tag = bs.find("div", class_="status") status = "N/A" if status_tag: status = status_tag.text.replace("Status:", "").strip()
# Try to update poster just in case high-res version exists og_img = bs.find("meta", property="og:image") if og_img and og_img.get("content"): results["poster"] = og_img["content"].strip()
results["msg"] = DEAULT_MSG_FORMAT.format( title=results.get("title", ""), status=status, genres=genres, summary=desc[:200], url=results["url"] )
chapters = [] chapter_list = bs.find("div", class_="chapters") if chapter_list: for a in chapter_list.find_all("a", href=True): ch_href = a.get("href", "").strip() ch_title = a.text.strip() if ch_href and ch_title: chapters.append({"title": ch_title, "url": ch_href})
results["chapters"] = chapters # Usually already newest first in site HTML return results
def iter_chapters(self, data, page: int = 1): chapters_list = [] for ch in data.get("chapters", []): chapters_list.append({ "title": ch.get("title", ""), "url": ch.get("url", ""), "manga_title": data.get("title", ""), "poster": data.get("poster", None), }) return chapters_list[(page - 1) * 60:page * 60] if page != 1 else chapters_list
async def get_pictures(self, url, data=None): content = await self.get(url, cs=True, headers=self.headers) if not content: return []
images_url = [] # Search for inline JS array containing image servers match = re.search(r'var\s+thzq\s*=\s*\[(.*?)\];', content) if match: # Clean and parse strings raw_array = match.group(1).split(',') for img in raw_array: cleaned = img.strip().strip("'").strip('"') if cleaned: images_url.append(cleaned) return images_url51 unmodified lines5253545556575851 unmodified linesreturn Noneasync def get(self, url, rjson=False, cs=False, **kwargs):return await self._make_request("GET", url, rjson, cs, **kwargs)async def post(self, url, rjson=False, cs=False, **kwargs):return await self._make_request("POST", url, rjson, cs, **kwargs)51 unmodified lines525354555657585960616263646551 unmodified linesreturn Noneasync def get(self, url, rjson=False, cs=False, **kwargs):result = await self._make_request("GET", url, rjson, cs, **kwargs)# Auto-fallback: if cloudscraper failed, retry with plain requestsif result is None and cs:result = await self._make_request("GET", url, rjson, False, **kwargs)return resultasync def post(self, url, rjson=False, cs=False, **kwargs):result = await self._make_request("POST", url, rjson, cs, **kwargs)if result is None and cs:result = await self._make_request("POST", url, rjson, False, **kwargs)return result
12345678910111213141516171819import cloudscraperfrom bs4 import BeautifulSoupimport rescraper = cloudscraper.create_scraper(browser='chrome')r = scraper.get('https://mangakatana.com/manga/lookism.693/c1')print(r.status_code)# Search script tagsbs = BeautifulSoup(r.text, 'html.parser')scripts = bs.find_all('script')for s in scripts: if s.string and 'var thzq=' in s.string: match = re.search(r'var thzq=\[(.*?)\];', s.string) if match: imgs = [x.strip().strip("'").strip('"') for x in match.group(1).split(',')] print('Images found:', len(imgs)) if imgs: print(imgs[0]) break else: print("Found thzq but regex failed.")12345678910111213141516171819202122232425262728293031323334353637383940414243import requestsfrom bs4 import BeautifulSoupimport cloudscraper
def test_mangakatana(): print('Testing MangaKatana...') scraper = cloudscraper.create_scraper(browser='chrome') r = scraper.get('https://mangakatana.com/?search=lookism&search_by=book_name') print('MK Status:', r.status_code) try: bs = BeautifulSoup(r.text, 'html.parser') books = bs.find_all('div', class_='item') print('MK Results:', len(books)) if books: book_url = books[0].find('a')['href'] print('Top match:', book_url) # Chapters r2 = scraper.get(book_url) bs2 = BeautifulSoup(r2.text, 'html.parser') chapters = bs2.find_all('a', href=lambda h: h and '/c' in str(h)) print('MK Chapters:', len(chapters)) if chapters: # Images r3 = scraper.get(chapters[0]['href']) import re images = re.findall(r"var thzq=\[(.*?)\];", r3.text) if images: img_links = [x.strip().strip("'") for x in images[0].split(',')] print('MK Images Found directly in JS array:', len(img_links)) except Exception as e: print('Error MK:', e)
def test_mangahub(): print('\nTesting MangaHub...') headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)' } r = requests.get('https://mangahub.io/search/q/lookism', headers=headers) print('MH Status:', r.status_code) # Mangahub can be tested further if we want, it uses an API usually.
test_mangakatana()test_mangahub().claude/settings.local.json+14-1
Webs/__init__.py+2
Webs/mangakatana.pyAdded+138
Webs/scraper.py+9-2
test_images.pyAdded+19
test_sites.pyAdded+43