Skip to content

Commit

Permalink
add new function to get recent uploaded anime
Browse files Browse the repository at this point in the history
  • Loading branch information
yoshikuniii committed Dec 10, 2022
1 parent 1153ebe commit 2827979
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 9 deletions.
7 changes: 3 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@
*.mkv
*.ts
test.py
secret.txt

# ignore folder
__pycache__/
build/
temp/
dist/
build/
__pycache__/
pynime.egg-info/
temp/
7 changes: 7 additions & 0 deletions example.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,12 @@
resolution = str(input("Select resolution: "))
api.download_video(stream_url = stream_urls[resolution], filename = f"{anime_details.title}_EP{episode_selection + 1}_{resolution}p")

# Get recent uploaded anime
recent_anime = api.get_recent_release(page=1)

for anime in recent_anime:
# print first 20 anime recently uploaded on GoGoAnime homepage
print(f"{anime.title} [EP : {anime.latest_episode}] [URL : {anime.latest_episode_url}]")

# Get Schedule
api.get_schedule(int(time.time()))
8 changes: 7 additions & 1 deletion pynimeapi/classes/datatype.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,10 @@ def __init__(
self.genres = genres
self.released = released
self.status = status
self.image_url = image_url
self.image_url = image_url

class RecentAnimeObj:
def __init__(self, title, latest_episode, latest_episode_url):
self.title = title
self.latest_episode = latest_episode
self.latest_episode_url = latest_episode_url
30 changes: 28 additions & 2 deletions pynimeapi/pynime.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def search_anime(self, anime_title: str) -> SearchResultObj:
except Exception as e:
print(e)

def get_anime_details(self, anime_category_url: str):
def get_anime_details(self, anime_category_url: str) -> AnimeDetailsObj:
''' Get basic anime info/details.
It will return an object:
.season : season of anime aired
Expand Down Expand Up @@ -128,7 +128,7 @@ def get_stream_urls(self, anime_episode_url: str):

return result

def grab_stream(self, anime_title: str, episode: int, resolution=1080):
def grab_stream(self, anime_title: str, episode: int, resolution=1080) -> str:
''' It just a shortcut for retrieve the streaming url.
As default, it will get the best resolution whics is 1080p.
'''
Expand Down Expand Up @@ -227,10 +227,36 @@ def download_video(self, stream_url: str, filename: str):
ts_file_to_merge.close()
else:
print("[!] Some file missing, aborting.")
return None
break

shutil.rmtree("temp") # delete folder and files inside them after finished

return filename

def get_schedule(self, unix_time: int):
schedule = GetSchedule()
schedule.print_schedule(unix_time)

def get_recent_release(self, page=1) -> RecentAnimeObj:
try:
recent_release_list = list()
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>.*?)[\"']"

if response:
matches = list(re.findall(regex_filter, response, re.MULTILINE))

for match in matches:
recent_release_list.append(
RecentAnimeObj(
title=match[2],
latest_episode=int(match[1]),
latest_episode_url=f"{self.baseURL}{match[0]}"))

return recent_release_list
except Exception as e:
print(e)

3 changes: 2 additions & 1 deletion pynimeapi/schedule.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import re
import json
import requests

from datetime import datetime
from collections import defaultdict

from pynimeapi.classes.datatype import *
from pynimeapi.classes.color import bcolors

class GetSchedule:
Expand Down Expand Up @@ -37,7 +39,6 @@ def __init__(self):
}"""



def arrange_template(self, data):
''' Convert JSON data from iter_schedule to Python dictonary fromat. '''
template = defaultdict(lambda: defaultdict(list))
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.38'
VERSION = '0.1.39'
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 2827979

Please sign in to comment.