Skip to content

Commit

Permalink
[mangoxo] add login support (#184)
Browse files Browse the repository at this point in the history
A very recent change: It is now only possible to see more
than the first 5 images of an album if you are logged in.
  • Loading branch information
mikf committed Apr 10, 2019
1 parent 49a6522 commit d9b94a5
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 2 deletions.
2 changes: 1 addition & 1 deletion docs/supportedsites.rst
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ MangaDex https://mangadex.org/ Chapters, Manga
Mangapanda https://www.mangapanda.com/ Chapters, Manga
MangaPark https://mangapark.me/ Chapters, Manga
Mangareader https://www.mangareader.net/ Chapters, Manga
Mangoxo https://www.mangoxo.com/ Albums, Channels
Mangoxo https://www.mangoxo.com/ Albums, Channels Optional
Newgrounds https://www.newgrounds.com/ Images from Users, individual Images, Videos
Ngomik http://ngomik.in/ Chapters
nhentai https://nhentai.net/ Galleries, Search Results
Expand Down
36 changes: 35 additions & 1 deletion gallery_dl/extractor/mangoxo.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,45 @@
"""Extractors for https://www.mangoxo.com/"""

from .common import Extractor, Message
from .. import text
from .. import text, exception
from ..cache import cache


class MangoxoBase():
"""Base class for mangoxo extractors"""
category = "mangoxo"
root = "https://www.mangoxo.com"
cookiedomain = "www.mangoxo.com"
cookienames = ("SESSION",)
_warning = True

def login(self):
username, password = self._get_auth_info()
if username:
self._update_cookies(self._login_impl(username, password))
elif MangoxoBase._warning:
MangoxoBase._warning = False
self.log.warning("Unauthenticated users cannot see "
"more than 5 images per album")

@cache(maxage=3*3600, keyarg=1)
def _login_impl(self, username, password):
self.log.info("Logging in as %s", username)

url = self.root + "/login/loginxmm"
headers = {
"X-Requested-With": "XMLHttpRequest",
"Referer": self.root + "/login",
}
data = {
"name": username,
"password": password,
}
response = self.request(url, method="POST", headers=headers, data=data)
session = response.cookies.get("SESSION")
if not session:
raise exception.AuthenticationError()
return {"SESSION": session}

@staticmethod
def _total_pages(page):
Expand Down Expand Up @@ -53,6 +85,7 @@ def __init__(self, match):
self.album_id = match.group(1)

def items(self):
self.login()
url = "{}/album/{}/".format(self.root, self.album_id)
page = self.request(url).text
data = self.metadata(page)
Expand Down Expand Up @@ -117,6 +150,7 @@ def __init__(self, match):
self.channel_id = match.group(1)

def items(self):
self.login()
yield Message.Version, 1
url = "{}/channel/{}/".format(self.root, self.channel_id)
num = total = 1
Expand Down
1 change: 1 addition & 0 deletions scripts/supportedsites.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
"flickr" : "Optional (OAuth)",
"idolcomplex": "Optional",
"luscious" : "Optional",
"mangoxo" : "Optional",
"nijie" : "Required",
"pixiv" : "Required",
"reddit" : "Optional (OAuth)",
Expand Down
1 change: 1 addition & 0 deletions test/test_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ def setup_test_config():
config.set(("extractor", "seiga", "username"), email)
config.set(("extractor", "danbooru", "username"), None)
config.set(("extractor", "twitter" , "username"), None)
config.set(("extractor", "mangoxo" , "password"), "VZ8DL3983u")

config.set(("extractor", "deviantart", "client-id"), "7777")
config.set(("extractor", "deviantart", "client-secret"),
Expand Down

0 comments on commit d9b94a5

Please sign in to comment.