aboutsummaryrefslogtreecommitdiffstats
path: root/gallery_dl/extractor/lineblog.py
blob: adb27a805cc9b73607b32d708aaed9b5859e130e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# -*- coding: utf-8 -*-

# Copyright 2019-2020 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.

"""Extractors for https://www.lineblog.me/"""

from .livedoor import LivedoorBlogExtractor, LivedoorPostExtractor
from .. import text


class LineblogBase():
    """Base class for lineblog extractors"""
    category = "lineblog"
    root = "https://lineblog.me"

    def _images(self, post):
        imgs = []
        body = post.pop("body")

        for num, img in enumerate(text.extract_iter(body, "<img ", ">"), 1):
            src = text.extr(img, 'src="', '"')
            alt = text.extr(img, 'alt="', '"')

            if not src:
                continue
            if src.startswith("https://obs.line-scdn.") and src.count("/") > 3:
                src = src.rpartition("/")[0]

            imgs.append(text.nameext_from_url(alt or src, {
                "url" : src,
                "num" : num,
                "hash": src.rpartition("/")[2],
                "post": post,
            }))

        return imgs


class LineblogBlogExtractor(LineblogBase, LivedoorBlogExtractor):
    """Extractor for a user's blog on lineblog.me"""
    pattern = r"(?:https?://)?lineblog\.me/(\w+)/?(?:$|[?#])"
    test = ("https://lineblog.me/mamoru_miyano/", {
        "range": "1-20",
        "count": 20,
        "pattern": r"https://obs.line-scdn.net/[\w-]+$",
        "keyword": {
            "post": {
                "categories" : tuple,
                "date"       : "type:datetime",
                "description": str,
                "id"         : int,
                "tags"       : list,
                "title"      : str,
                "user"       : "mamoru_miyano"
            },
            "filename": str,
            "hash"    : r"re:\w{32,}",
            "num"     : int,
        },
    })


class LineblogPostExtractor(LineblogBase, LivedoorPostExtractor):
    """Extractor for blog posts on lineblog.me"""
    pattern = r"(?:https?://)?lineblog\.me/(\w+)/archives/(\d+)"
    test = ("https://lineblog.me/mamoru_miyano/archives/1919150.html", {
        "url": "24afeb4044c554f80c374b52bf8109c6f1c0c757",
        "keyword": "76a38e2c0074926bd3362f66f9fc0e6c41591dcb",
    })