Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/issue.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Issue
about: Log bugs found while using Manga Tagger
title: "[BUG]"
labels: bug
assignees: Inpacchi
assignees: sanchoblaze

---

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,4 @@ dmypy.json
library/
downloads/
wiki/
manga_tagger.db
33 changes: 33 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
FROM python:3.11.4-alpine3.18
LABEL authors="sanchoblaze <me@sanchoblaze.com>"

RUN apk add gcc python3-dev python3-tkinter build-base linux-headers git
RUN python -m pip install --upgrade pip

RUN mkdir /downloads
RUN mkdir /library
RUN mkdir /config
RUN mkdir /manga-tagger

# COPY settings.json /manga-tagger/
COPY MangaTaggerLib /manga-tagger/MangaTaggerLib
COPY MangaTagger.py /manga-tagger/
COPY requirements.txt /manga-tagger/

VOLUME /downloads
VOLUME /library
VOLUME /config

WORKDIR /manga-tagger/

RUN pip install --no-cache -r requirements.txt

RUN groupadd -r -g 100 abc && useradd -r -g abc -u 99 abc
RUN chown -R abc /downloads
RUN chown -R abc /library
VOLUME chown -R abc /config

USER abc:abc

# RUN python MangaTagger.py
CMD [ "python", "./MangaTagger.py"]
224 changes: 108 additions & 116 deletions MangaTaggerLib/MangaTaggerLib.py

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion MangaTaggerLib/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '1.1.6-alpha'
__version__ = '2.0.3-alpha'
18 changes: 12 additions & 6 deletions MangaTaggerLib/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ def __init__(
self.calls_minute = 0
self.last_api_call = datetime.now()

# Rate Limit: 2 requests/second
# Rate Limit: 1 requests/second
def _check_rate_seconds(self):
time.sleep(5)
last_api_call_delta = (datetime.now() - self.last_api_call).total_seconds()

if self.calls_second > 2 and last_api_call_delta < 1:
if self.calls_second > 1 > last_api_call_delta:
time.sleep(1)
elif last_api_call_delta > 1:
self.calls_second = 0
Expand All @@ -32,7 +33,7 @@ def _check_rate_minutes(self):
last_api_call_delta = (datetime.now() - self.last_api_call).total_seconds()

if self.calls_minute > 30 and last_api_call_delta < 60:
time.sleep(61 - last_api_call_delta)
time.sleep(61)
elif last_api_call_delta > 60:
self.calls_minute = 0

Expand All @@ -49,6 +50,7 @@ def search(
self.calls_second += 1
self.calls_minute += 1
self.last_api_call = datetime.now()

search_results = super(MTJikan, self).search(search_type, query, page, parameters)
self.session.close()
return search_results
Expand Down Expand Up @@ -76,12 +78,14 @@ def initialize(cls):

@classmethod
def _post(cls, query, variables, logging_info):
time.sleep(5)
try:
response = requests.post('https://graphql.anilist.co', json={'query': query, 'variables': variables})
if "errors" in response.json():
raise Exception(f"Error: {response.json()['errors']}")
except Exception as e:
cls._log.exception(e, extra=logging_info)
cls._log.warning('Manga Tagger is unfamiliar with this error. Please log an issue for investigation.',
extra=logging_info)
cls._log.exception(e)
cls._log.warning('Manga Tagger is unfamiliar with this error. Please log an issue for investigation.')
return None

cls._log.debug(f'Query: {query}')
Expand All @@ -92,6 +96,7 @@ def _post(cls, query, variables, logging_info):

@classmethod
def search_staff_by_mal_id(cls, mal_id, logging_info):
time.sleep(5)
query = '''
query search_staff_by_mal_id ($mal_id: Int) {
Media (idMal: $mal_id, type: MANGA) {
Expand Down Expand Up @@ -122,6 +127,7 @@ def search_staff_by_mal_id(cls, mal_id, logging_info):

@classmethod
def search_for_manga_title_by_mal_id(cls, mal_id, logging_info):
time.sleep(5)
query = '''
query search_manga_by_mal_id ($mal_id: Int) {
Media (idMal: $mal_id, type: MANGA) {
Expand Down
Loading