Skip to content

Commit

Permalink
fix: get returns if saved or not
Browse files Browse the repository at this point in the history
  • Loading branch information
eggplants committed Jan 13, 2022
1 parent 8cf6bb2 commit 8fca9c2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ import getjump as g
G = g.GetJump()
next_uri = "https://shonenjumpplus.com/episode/13932016480028799982.json"
while next_uri:
next_uri, prev_title = G.get(next_uri, overwrite=False)
print("saved:", prev_title)
next_uri, prev_title, saved = G.get(next_uri, overwrite=False)
if saved:
print("saved:", prev_title)
print("next:", next_uri)
```

Expand Down
8 changes: 4 additions & 4 deletions getjump/GetJump.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def get(
save_path: str = ".",
overwrite: bool = True,
only_first: bool = False,
) -> tuple[Optional[str], str]:
) -> tuple[Optional[str], str, bool]:
self.__check_url(url)
r = requests.get(url, headers=HEADERS)
self.__check_content_type(r.headers["content-type"])
Expand All @@ -47,18 +47,18 @@ def get(
save_dir = os.path.join(save_path, series_title, title)
if os.path.exists(save_dir) and not overwrite:
print("already existed! (to overwrite, use `-o`)", file=sys.stderr)
return nxt, save_dir
return nxt, save_dir, False
os.makedirs(save_dir, exist_ok=True)

if not j["isPublic"] and not j["hasPurchased"]:
warnings.warn(title, NeedPurchase, stacklevel=1)
return nxt, save_dir
return nxt, save_dir, False
else:
pages = [p for p in j["pageStructure"]["pages"] if "src" in p]

self.__save_images(pages, save_dir, only_first)

return nxt, save_dir
return nxt, save_dir, True

@staticmethod
def is_valid_uri(url: str) -> bool:
Expand Down
10 changes: 6 additions & 4 deletions getjump/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,14 @@ def get_bulk(args: argparse.Namespace) -> None:
print("get:", next_uri)
while next_uri:
# print("get:", next_uri)
next_uri, prev_title = g.get(
next_uri, prev_title, ok = g.get(
next_uri,
save_path=args.savedir,
overwrite=args.overwrite,
only_first=args.first,
)
print("saved:", prev_title)
if ok:
print("saved:", prev_title)
if next_uri is not None:
print("next:", next_uri)
else:
Expand All @@ -138,13 +139,14 @@ def get_one(args: argparse.Namespace) -> None:
g = GetJump()
next_uri = args.url
print("get:", next_uri)
_, prev_title = g.get(
_, prev_title, ok = g.get(
next_uri,
save_path=args.savedir,
overwrite=args.overwrite,
only_first=args.first,
)
print("saved:", prev_title)
if ok:
print("saved:", prev_title)
print("done.")


Expand Down

0 comments on commit 8fca9c2

Please sign in to comment.