Skip to content

Commit

Permalink
[seiga] require authentication with 'user_session' cookie (#2372)
Browse files Browse the repository at this point in the history
Login with username & password would now require entering a 2FA token.

see also danbooru/danbooru@7b009cc
  • Loading branch information
mikf committed Mar 11, 2022
1 parent 47cf05c commit fc277fa
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 33 deletions.
8 changes: 4 additions & 4 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,11 @@ Download images; in this case from danbooru via tag search for 'bonocho':
$ gallery-dl "https://danbooru.donmai.us/posts?tags=bonocho"
Get the direct URL of an image from a site that requires authentication:
Get the direct URL of an image from a site supporting authentication with username & password:

.. code:: bash
$ gallery-dl -g -u "<username>" -p "<password>" "https://seiga.nicovideo.jp/seiga/im3211703"
$ gallery-dl -g -u "<username>" -p "<password>" "https://twitter.com/i/web/status/604341487988576256"
Filter manga chapters by language and chapter number:
Expand Down Expand Up @@ -199,7 +199,7 @@ Username & Password

Some extractors require you to provide valid login credentials in the form of
a username & password pair. This is necessary for
``nijie`` and ``seiga``
``nijie``
and optional for
``aryion``,
``danbooru``,
Expand All @@ -225,7 +225,7 @@ You can set the necessary information in your configuration file
{
"extractor": {
"seiga": {
"twitter": {
"username": "<username>",
"password": "<password>"
}
Expand Down
1 change: 0 additions & 1 deletion docs/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,6 @@ Description
Specifying a username and password is required for

* ``nijie``
* ``seiga``

and optional for

Expand Down
2 changes: 1 addition & 1 deletion docs/supportedsites.md
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ Consider all sites to be NSFW unless otherwise known.
<td>Niconico Seiga</td>
<td>https://seiga.nicovideo.jp/</td>
<td>individual Images, User Profiles</td>
<td>Required</td>
<td><a href="https://github.com/mikf/gallery-dl#cookies">Cookies</a></td>
</tr>
<tr>
<td>nijie</td>
Expand Down
31 changes: 5 additions & 26 deletions gallery_dl/extractor/seiga.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
# -*- coding: utf-8 -*-

# Copyright 2016-2020 Mike Fährmann
# Copyright 2016-2022 Mike Fährmann
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.

"""Extract images from https://seiga.nicovideo.jp/"""
"""Extractors for https://seiga.nicovideo.jp/"""

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


class SeigaExtractor(Extractor):
Expand All @@ -25,7 +24,9 @@ def __init__(self, match):
self.start_image = 0

def items(self):
self.login()
if not self._check_cookies(("user_session",)):
raise exception.StopExtraction("'user_session' cookie required")

images = iter(self.get_images())
data = next(images)

Expand All @@ -45,28 +46,6 @@ def get_image_url(self, image_id):
url, method="HEAD", allow_redirects=False, notfound="image")
return response.headers["Location"].replace("/o/", "/priv/", 1)

def login(self):
"""Login and set necessary cookies"""
if not self._check_cookies(("user_session",)):
username, password = self._get_auth_info()
self._update_cookies(self._login_impl(username, password))

@cache(maxage=7*24*3600, keyarg=1)
def _login_impl(self, username, password):
if not username or not password:
raise exception.AuthenticationError(
"Username and password required")

self.log.info("Logging in as %s", username)
url = "https://account.nicovideo.jp/api/v1/login"
data = {"mail_tel": username, "password": password}

self.request(url, method="POST", data=data)
if "user_session" not in self.session.cookies:
raise exception.AuthenticationError()
del self.session.cookies["nicosid"]
return self.session.cookies


class SeigaUserExtractor(SeigaExtractor):
"""Extractor for images of a user from seiga.nicovideo.jp"""
Expand Down
2 changes: 1 addition & 1 deletion scripts/supportedsites.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@
"ponybooru" : "API Key",
"reddit" : _OAUTH,
"sankaku" : "Supported",
"seiga" : "Required",
"seiga" : _COOKIES,
"seisoparty" : "Supported",
"smugmug" : _OAUTH,
"subscribestar" : "Supported",
Expand Down

0 comments on commit fc277fa

Please sign in to comment.