Skip to content

Commit

Permalink
Internal Rework
Browse files Browse the repository at this point in the history
  • Loading branch information
sachaw committed Mar 25, 2022
1 parent 1c1a884 commit 4a4f313
Show file tree
Hide file tree
Showing 4 changed files with 430 additions and 186 deletions.
6 changes: 3 additions & 3 deletions Contents/Code/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from search import search_anime
from update import update_anime
from update import update_anime, update_movie

EN = Locale.Language.English

Expand All @@ -25,7 +25,7 @@ def search(self, results, media, lang, manual):
search_anime('tv', results, media, lang)

def update(self, metadata, media, lang, force):
update_anime('tv', metadata, media, force)
update_anime(metadata, media, force)


class AniListMovie(Agent.Movies):
Expand All @@ -40,4 +40,4 @@ def search(self, results, media, lang, manual):
search_anime('movie', results, media, lang)

def update(self, metadata, media, lang, force):
update_anime('movie', metadata, media, force)
update_movie(metadata, media, force)
39 changes: 19 additions & 20 deletions Contents/Code/providers.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
from datetime import datetime
from time import sleep
import certifi
import requests


def get_anime(id):
query = '''
query {
Page {
media(id: ''' + id + ''') {
genres
duration
episodes
averageScore
description
Expand Down Expand Up @@ -110,27 +109,27 @@ def get_anime(id):


def get_episodes(id):
sleep(4)
sleep(4) #TODO: Rate limit FIX
anime_episodes = {}

mal_request = requests.get(
'https://api.jikan.moe/v3/anime/' + id + '/episodes',
verify=certifi.where()
).content
episodes = JSON.ObjectFromString(mal_request)

page = 1
has_next_page = True
try:
mal_request = requests.get(
'https://api.jikan.moe/v3/anime/' + id + '/episodes',
verify=certifi.where()
).content
episodes = JSON.ObjectFromString(mal_request)

for episode in episodes['episodes']:
if not episode['recap']:
anime_episodes[episode['episode_id']] = episode

while has_next_page:
episodes = get_episode_data(id, page)
has_next_page = episodes['pagination']['has_next_page']
page += 1
for episode in episodes['data']:
if not episode['recap']:
anime_episodes[episode['mal_id']] = episode
return anime_episodes
except:
Log.Error('Error getting mal data')
return

def get_episode_data(id, page):

mal_request = requests.get(
'https://api.jikan.moe/v4/anime/' + id + '/episodes?page=' + str(page),
verify=certifi.where()
).content
return JSON.ObjectFromString(mal_request)
3 changes: 1 addition & 2 deletions Contents/Code/search.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from utils import requests_retry_session
import certifi
import re


def search_anime(type, results, media, lang):
search_term = media.show if type == 'tv' else media.name
Expand Down Expand Up @@ -77,7 +77,6 @@ def search_anime(type, results, media, lang):
id=str(result['id']),
name=result['title']['romaji'],
year=result['startDate']['year'],
thumb=result['coverImage']['extraLarge'],
score=s,
lang=lang
))
Expand Down
Loading

0 comments on commit 4a4f313

Please sign in to comment.