1
0
mirror of https://github.com/mikf/gallery-dl.git synced 2024-11-22 10:42:34 +01:00

[seiga] add extractor

This commit is contained in:
Mike Fährmann 2016-08-09 16:36:30 +02:00
parent dac796879a
commit 6792c68254
No known key found for this signature in database
GPG Key ID: 5680CA389D365A88
3 changed files with 67 additions and 2 deletions

View File

@ -46,7 +46,7 @@ Supported Sites
doujinmode.net, exhentai.org, hbrowse.com, hentai2read.com,
hentaibox.net, hitomi.la, luscious.net, nhentai.net
* Japanese:
nijie.info, pixiv.net
pixiv.net, nijie.info, seiga.nicovideo.jp
* Western:
deviantart.com, hentai-foundry.com, imagefap,com, imgth.com, imgur.com,
tumblr.com
@ -76,7 +76,7 @@ Authentication
==============
Some extractors require you to provide valid login-credentials.
This currently includes ``pixiv``, ``exhentai`` and ``nijie``.
This currently includes ``pixiv``, ``exhentai``, ``nijie`` and ``seiga``.
You can set the necessary information in your configuration file
(cf. gallery-dl.conf_)

View File

@ -52,6 +52,7 @@ modules = [
"powermanga",
"safebooru",
"sankaku",
"seiga",
"senmanga",
"spectrumnexus",
"tumblr",

View File

@ -0,0 +1,64 @@
# -*- coding: utf-8 -*-
# Copyright 2016 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 http://seiga.nicovideo.jp"""
from .common import Extractor, Message
from .. import config, exception
from ..cache import cache
class SeigaImageExtractor(Extractor):
"""Extract a single image from seiga.nicovideo.jp"""
category = "seiga"
subcategory = "image"
directory_fmt = ["{category}"]
filename_fmt = "{category}_{image-id}.jpg"
pattern = [r"(?:https?://)?(?:www\.|seiga\.)?nicovideo\.jp/seiga/im(\d+)"]
test = [("http://seiga.nicovideo.jp/seiga/im5977527", {
"keyword": "e2ea59186c47beb71484ba35d550cf6511ac185a",
"content": "d9202292012178374d57fb0126f6124387265297",
})]
def __init__(self, match):
Extractor.__init__(self)
self.image_id = match.group(1)
def items(self):
self.session.cookies = self.login(
config.interpolate(("extractor", self.category, "username")),
config.interpolate(("extractor", self.category, "password")),
)
data = self.get_job_metadata()
url = self.get_image_url(self.image_id)
yield Message.Version, 1
yield Message.Directory, data
yield Message.Url, url, data
def get_job_metadata(self):
"""Collect metadata for extractor-job"""
return {
"category": self.category,
"image-id": self.image_id,
}
def get_image_url(self, image_id):
"""Get url for an image with id 'image_id'"""
url = "http://seiga.nicovideo.jp/image/source/" + image_id
response = self.session.head(url)
return response.headers["Location"].replace("/o/", "/priv/", 1)
@cache(maxage=30*24*60*60, keyarg=1)
def login(self, username, password):
"""Login and obtain session cookie"""
url = "https://account.nicovideo.jp/api/v1/login"
params = {"mail_tel": username, "password": password}
self.session.post(url, data=params).close()
if "user_session" not in self.session.cookies:
raise exception.AuthenticationError()
del self.session.cookies["nicosid"]
return self.session.cookies