Skip to content

Commit

Permalink
Merge pull request #4 from qoo-nyan/dev
Browse files Browse the repository at this point in the history
リファクタリング
  • Loading branch information
popo-nyan committed Apr 27, 2024
2 parents 2d36760 + dd238ef commit ff77fd6
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 63 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff
otokomae/
yamadalv999/
.idea
.idea/**/workspace.xml
Expand Down
Binary file modified GanmaDownloader/__pycache__/client.cpython-311.pyc
Binary file not shown.
Binary file modified GanmaDownloader/__pycache__/utils.cpython-311.pyc
Binary file not shown.
60 changes: 25 additions & 35 deletions GanmaDownloader/client.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import uuid
import httpx
from string import punctuation
from json import dumps
import aiofiles

Expand All @@ -11,24 +12,23 @@
class Client:

def __init__(self):
self.__session = httpx.AsyncClient(http2=True, headers={
'Host': 'reader.ganma.jp',
'User-Agent': 'GanmaReader/9.0.0 Android releaseVersion:12 model:samsung/SC-51D',
'X-From': 'https://reader.ganma.jp/api/',
'X-Noescape': 'true',
'Connection': 'close'})
self.__session = httpx.AsyncClient(http2=True,
headers={'Host': 'reader.ganma.jp',
'User-Agent': 'GanmaReader/9.0.0 Android releaseVersion:12 model:samsung/SC-51D',
'X-From': 'https://reader.ganma.jp/api/',
'X-Noescape': 'true',
'Connection': 'close'})
self._play_session = ""

async def create_account(self) -> CreateAccountResponseModel | None:
create_account_response = await self.__session.post(url="https://reader.ganma.jp/api/1.0/account")
if create_account_response.status_code == httpx.codes.OK:
params = {'clientType': 'app',
'installationId': str(uuid.uuid4()),
'explicit': 'false'}
data = {"id": create_account_response.json()['root']['id'],
"password": create_account_response.json()['root']['password']}
login_response = await self.__session.post(url="https://reader.ganma.jp/api/3.0/session",
params=params,
params={'clientType': 'app',
'installationId': str(uuid.uuid4()),
'explicit': 'false'},
data=data)
if login_response.status_code == httpx.codes.OK and login_response.json()['success']:
self._play_session = login_response.cookies.get("PLAY_SESSION")
Expand All @@ -44,28 +44,17 @@ async def get_magazine_data(self,
response_json = response.json()['root']
stories = []
for story in response_json['items']:
if story.get("subtitle") is not None:
stories.append(MagazineItemBaseModel(storyId=story['storyId'],
title=story['title'],
seriesTitle=story['seriesTitle'],
subtitle=story['subtitle'],
thumbnailImageUrl=story['thumbnailImageURL'],
kind=story['kind'],
releaseStart=story['releaseStart'],
heartCount=story['heartCount'],
disableCm=story['disableCM'],
hasExchange=story['hasExchange']))
if story.get("subtitle") is None:
continue
else:
stories.append(MagazineItemBaseModel(storyId=story['storyId'],
title=story['title'],
seriesTitle=story['seriesTitle'],
thumbnailImageUrl=story['thumbnailImageURL'],
kind=story['kind'],
releaseStart=story['releaseStart'],
heartCount=story['heartCount'],
disableCm=story['disableCM'],
hasExchange=story['hasExchange']))
stories.append(MagazineItemBaseModel(storyId=story['storyId'],
title=story['title'],
seriesTitle=story['seriesTitle'],
subtitle=story['subtitle'],
thumbnailImageUrl=story['thumbnailImageURL'],
kind=story['kind'],
releaseStart=story['releaseStart'],
heartCount=story['heartCount'],
disableCm=story['disableCM']))

return MagazineResponseModel(alias=response_json['alias'],
author=response_json['author'],
Expand Down Expand Up @@ -149,14 +138,15 @@ async def download_story_image(self,
alias: str,
title: str,
subtitle: str):
make_directory(alias.strip("\\?()!@#$%^&*()_+{}?>!"))
save_image_path = alias.strip("\\?()!@#$%^&*()_+{}?>!") + r"\\" + title.strip("\\?()!@#$%^&*()_+{}?>!") + "-" + subtitle.strip("\\?()!@#$%^&*()_+{}?>!")
save_image_path = (alias.strip(r"\\" + punctuation) + r"\\" +
title.strip(r"\\" + punctuation) + "-" +
subtitle.strip(r"\\" + punctuation))
make_directory(alias.strip(r"\\" + punctuation))
make_directory(save_image_path)
response = await self.__session.get(url=base_url + str(page_count) + ".jpg?" + image_sign,
headers={'Host': 'd1bzi54d5ruxfk.cloudfront.net',
'Accept-Encoding': 'gzip, deflate, br',
'User-Agent': 'Dalvik/2.1.0 (Linux; U; Android 9; SM-G973N Build/PPR1.190810.011)',
'User-Agent': 'GanmaReader/9.2.0 Android releaseVersion:9 model:samsung/SM-G973N'})
'User-Agent': 'GanmaReader/9.0.0 Android releaseVersion:12 model:samsung/SC-51D'})
if response.status_code == httpx.codes.OK:
async with aiofiles.open(save_image_path + r"\\" + str(page_count) + ".jpg", "wb") as f:
await f.write(response.content)
Expand Down
1 change: 0 additions & 1 deletion GanmaDownloader/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,3 @@ def make_directory(directory_name):
return
else:
os.mkdir(directory_name)

24 changes: 0 additions & 24 deletions tests/reader_test.py

This file was deleted.

3 changes: 0 additions & 3 deletions tests/test.py

This file was deleted.

0 comments on commit ff77fd6

Please sign in to comment.