Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support multi-page URL #79

Merged
merged 4 commits into from
Feb 26, 2018
Merged

support multi-page URL #79

merged 4 commits into from
Feb 26, 2018

Conversation

journey-ad
Copy link
Contributor

@journey-ad journey-ad commented Feb 26, 2018

Hello, I modified sankaku.py and idolcomplex.py. It now supports multi-page URL like https://chan.sankakucomplex.com/?tags=marie_rose&page=98&next=3874906 (NSFW).

Please review my code.

@mikf
Copy link
Owner

mikf commented Feb 26, 2018

Thanks for your contribution.

As a general rule, you should check your code with flake8 and also add a test-case for your implemented feature.

In this case you should just add, for example

("https://chan.sankakucomplex.com/?tags=marie_rose&page=98&next=3874906", None),

to the list.

r"/\?(?:[^&#]*&)*tags=([^&#]+)"]
r"/\?(?:[^&#]*&)*tags=([^&#]+)"
r"((?:[^&#]*&)*page=([^&#]+))*"
r"((?:[^&#]*&)*next=([^&#]+))*"]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of capturing every query-parameter on its own, capture the whole query string ((?:\?([^#]*)?) and parse it with text.parse_query(...)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... OK ignore this one. What I wrote wouldn't work. Just leave it as it is.

r"/\?(?:[^&#]*&)*tags=([^&#]+)"]
r"/\?(?:[^&#]*&)*tags=([^&#]+)"
r"((?:[^&#]*&)*page=([^&#]+))*"
r"((?:[^&#]*&)*next=([^&#]+))*"]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

@@ -150,6 +152,8 @@ class SankakuTagExtractor(SankakuExtractor):
def __init__(self, match):
SankakuExtractor.__init__(self)
self.tags = text.unquote(match.group(1).replace("+", " "))
self.start_page = 1 if match.group(3) is None else int(text.unquote(match.group(3)))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use util.safe_int(..., 1).
You don't need to check if this particular group is None, safe_int() already handles that.

Also don't unquote something that should be a number.

@@ -150,6 +152,8 @@ class SankakuTagExtractor(SankakuExtractor):
def __init__(self, match):
SankakuExtractor.__init__(self)
self.tags = text.unquote(match.group(1).replace("+", " "))
self.start_page = 1 if match.group(3) is None else int(text.unquote(match.group(3)))
self.next = 0 if match.group(5) is None else int(text.unquote(match.group(5)))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here. util.safe_int(..., 0).

@@ -170,6 +174,7 @@ def get_metadata(self):

def get_posts(self):
params = {"tags": self.tags, "page": self.start_page}
if self.next > 0 : params["next"] = self.next
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No space between condition and :. flake8 should tell you that as well.

@mikf
Copy link
Owner

mikf commented Feb 26, 2018

Nice, thank you.

The only remaining issue is the regex, which now also matches the URLs of the other two extractors.
It should be fixed with some smaller changes and adding a $ at the end. Something like this should do the trick:

r"(?:https?://)?chan\.sankakucomplex\.com"
r"/?(?:\?([^#]*))?(?:#.*)?$"

@journey-ad
Copy link
Contributor Author

journey-ad commented Feb 26, 2018

@mikf Oh, I did not see your message, it seems we still need to commit it once.😂
edit: Or not? it seems work well.

@mikf mikf merged commit 49463f7 into mikf:master Feb 26, 2018
@journey-ad journey-ad deleted the patch-1 branch February 28, 2018 00:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants