Skip to content

Commit

Permalink
add picture_url on search and recent release, add new regex filter
Browse files Browse the repository at this point in the history
  • Loading branch information
yoshikuniii committed Feb 25, 2023
1 parent 892627d commit 7c514f4
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
6 changes: 4 additions & 2 deletions pynimeapi/classes/datatype.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
class SearchResultObj:
def __init__(self, title: str, category_url: str):
def __init__(self, title: str, category_url: str, picture_url: str):
self.title = title
self.category_url = category_url
self.picture_url = picture_url

def __str__(self):
return f"title: {self.title} | category_url: {self.category_url}"
Expand All @@ -21,7 +22,8 @@ def __init__(
self.image_url = image_url

class RecentAnimeObj:
def __init__(self, title, latest_episode, latest_episode_url):
def __init__(self, title, latest_episode, latest_episode_url, picture_url):
self.title = title
self.latest_episode = latest_episode
self.latest_episode_url = latest_episode_url
self.picture_url = picture_url
21 changes: 17 additions & 4 deletions pynimeapi/pynime.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ class PyNime:
def __init__(self, base_url: str = "https://gogoanime.ar"):
self.baseURL = base_url # domain of GoGoAnime. please update regularly

def version(self):
return "0.1.44"

def search_anime(self, anime_title: str) -> SearchResultObj:
"""
Search anime on given title.
Expand All @@ -35,13 +38,20 @@ def search_anime(self, anime_title: str) -> SearchResultObj:
if r:
title = [_.group(1) for _ in re.finditer(r"<\\/div>(.*?)<\\/a><\\/div>", r.text)]
url = [_.group(1) for _ in re.finditer(r"<a href=\\\"(.*?)\\\" ", r.text)]

picture = [_.group(1) for _ in re.finditer(r"style='background:\surl[\(']\\(.*?)[\)']", r.text)]

for i, v in enumerate(title):
title = v.replace(r"\/", "/")
category_url = url[i].replace(r"\/", "/")
category_url = f"{self.baseURL}/{category_url}"
picture_url = picture[i].replace(r"\/","/").replace(r'"', "")[:-1]
anime_result.append(
SearchResultObj(title=title, category_url=category_url))
SearchResultObj(
title=title,
category_url=category_url,
picture_url=picture_url,
)
)

return anime_result

Expand Down Expand Up @@ -246,7 +256,7 @@ def get_recent_release(self, page=1) -> RecentAnimeObj:
response = requests.get(
f"https://ajax.gogo-load.com/ajax/page-recent-release.html?page={page}").text

regex_filter = r"<li>\s*\n.*\n.*<a\s*href=[\"'](?P<href>.*?-episode-(?P<episode>\d+))[\"']\s*title=[\"'](?P<title>.*?)[\"']"
regex_filter = r"<li>\s*\n.*\n.*<a\shref=[\"'](?P<href>.*?-episode-(?P<episode>\d+))[\"']\s*title=[\"'](?P<title>.*?)[\"']>\n.*<img\ssrc=[\"'](?P<img>.*?)[\"']"

if response:
matches = list(re.findall(regex_filter, response, re.MULTILINE))
Expand All @@ -256,7 +266,10 @@ def get_recent_release(self, page=1) -> RecentAnimeObj:
RecentAnimeObj(
title=match[2],
latest_episode=int(match[1]),
latest_episode_url=f"{self.baseURL}{match[0]}"))
latest_episode_url=f"{self.baseURL}{match[0]}",
picture_url=match[3],
)
)

return recent_release_list
except Exception as e:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from setuptools import setup, find_packages

VERSION = '0.1.43'
VERSION = '0.1.44'
DESCRIPTION = 'Yet simple API wrapper for GoGoAnime'
LONG_DESCRIPTION = 'PyNime is a (simple) straightforward Python3 script to scrape GoGoAnime using Python. The project is a work in progress, not finished yet. But, the code works well, feel free to take part of the code.'

Expand Down

0 comments on commit 7c514f4

Please sign in to comment.