2019-06-23 22:02:54 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2023-09-11 16:30:55 +02:00
|
|
|
# Copyright 2019-2023 Mike Fährmann
|
2019-06-23 22:02:54 +02:00
|
|
|
#
|
|
|
|
# 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://vanilla-rock.com/"""
|
|
|
|
|
|
|
|
from .common import Extractor, Message
|
|
|
|
from .. import text
|
|
|
|
|
|
|
|
|
|
|
|
class VanillarockExtractor(Extractor):
|
|
|
|
"""Base class for vanillarock extractors"""
|
|
|
|
category = "vanillarock"
|
|
|
|
root = "https://vanilla-rock.com"
|
|
|
|
|
|
|
|
def __init__(self, match):
|
|
|
|
Extractor.__init__(self, match)
|
|
|
|
self.path = match.group(1)
|
|
|
|
|
|
|
|
|
|
|
|
class VanillarockPostExtractor(VanillarockExtractor):
|
|
|
|
"""Extractor for blogposts on vanilla-rock.com"""
|
|
|
|
subcategory = "post"
|
|
|
|
directory_fmt = ("{category}", "{path}")
|
|
|
|
filename_fmt = "{num:>02}.{extension}"
|
|
|
|
archive_fmt = "{filename}"
|
|
|
|
pattern = (r"(?:https?://)?(?:www\.)?vanilla-rock\.com"
|
2020-10-22 23:12:59 +02:00
|
|
|
r"(/(?!category/|tag/)[^/?#]+)/?$")
|
2023-09-11 16:30:55 +02:00
|
|
|
example = "https://vanilla-rock.com/TITLE"
|
2019-06-23 22:02:54 +02:00
|
|
|
|
|
|
|
def items(self):
|
|
|
|
extr = text.extract_from(self.request(self.root + self.path).text)
|
2021-02-14 15:40:37 +01:00
|
|
|
name = extr('<h1 class="entry-title">', "<")
|
2019-06-23 22:02:54 +02:00
|
|
|
|
|
|
|
imgs = []
|
|
|
|
while True:
|
|
|
|
img = extr('<div class="main-img">', '</div>')
|
|
|
|
if not img:
|
|
|
|
break
|
2022-11-04 23:39:38 +01:00
|
|
|
imgs.append(text.extr(img, 'href="', '"'))
|
2019-06-23 22:02:54 +02:00
|
|
|
|
|
|
|
data = {
|
|
|
|
"count": len(imgs),
|
2021-02-14 15:40:37 +01:00
|
|
|
"title": text.unescape(name),
|
2019-06-23 22:02:54 +02:00
|
|
|
"path" : self.path.strip("/"),
|
|
|
|
"date" : text.parse_datetime(extr(
|
|
|
|
'<div class="date">', '</div>'), "%Y-%m-%d %H:%M"),
|
|
|
|
"tags" : text.split_html(extr(
|
|
|
|
'<div class="cat-tag">', '</div>'))[::2],
|
|
|
|
}
|
|
|
|
|
|
|
|
yield Message.Directory, data
|
|
|
|
for data["num"], url in enumerate(imgs, 1):
|
|
|
|
yield Message.Url, url, text.nameext_from_url(url, data)
|
|
|
|
|
|
|
|
|
|
|
|
class VanillarockTagExtractor(VanillarockExtractor):
|
|
|
|
"""Extractor for vanillarock blog posts by tag or category"""
|
|
|
|
subcategory = "tag"
|
|
|
|
pattern = (r"(?:https?://)?(?:www\.)?vanilla-rock\.com"
|
2020-10-22 23:12:59 +02:00
|
|
|
r"(/(?:tag|category)/[^?#]+)")
|
2023-09-11 16:30:55 +02:00
|
|
|
example = "https://vanilla-rock.com/tag/TAG"
|
2019-06-23 22:02:54 +02:00
|
|
|
|
|
|
|
def items(self):
|
|
|
|
url = self.root + self.path
|
|
|
|
data = {"_extractor": VanillarockPostExtractor}
|
|
|
|
|
|
|
|
while url:
|
|
|
|
extr = text.extract_from(self.request(url).text)
|
|
|
|
while True:
|
|
|
|
post = extr('<h2 class="entry-title">', '</h2>')
|
|
|
|
if not post:
|
|
|
|
break
|
2022-11-04 23:39:38 +01:00
|
|
|
yield Message.Queue, text.extr(post, 'href="', '"'), data
|
2019-06-23 22:02:54 +02:00
|
|
|
url = text.unescape(extr('class="next page-numbers" href="', '"'))
|