[*chan] code cleanup

This commit is contained in:
Mike Fährmann
2016-10-03 08:23:40 +02:00
parent 14237142d8
commit c20a3b3a01
3 changed files with 17 additions and 26 deletions

View File

@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
# Copyright 2015 Mike Fährmann
# Copyright 2015, 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
@@ -11,34 +11,37 @@
from .common import Extractor, Message
from .. import text
class ChanExtractor(Extractor):
class ChanThreadExtractor(Extractor):
"""Base class for extractors for Futaba Channel boards"""
category = "chan"
subcategory = "thread"
directory_fmt = ["{category}", "{board}-{thread}"]
filename_fmt = "{tim}-{filename}{ext}"
api_url = ""
file_url = ""
def __init__(self, board, thread):
def __init__(self, match):
Extractor.__init__(self)
self.metadata = {
"board": board,
"thread": thread,
"board": match.group(1),
"thread": match.group(2),
}
def items(self):
yield Message.Version, 1
posts = self.request(self.api_url.format(**self.metadata)).json()["posts"]
url = self.api_url.format_map(self.metadata)
posts = self.request(url).json()["posts"]
self.metadata["title"] = self.get_thread_title(posts[0])
yield Message.Directory, self.metadata
for post in posts:
if "filename" not in post:
continue
post.update(self.metadata)
yield Message.Url, self.file_url.format(**post), post
yield Message.Url, self.file_url.format_map(post), post
if "extra_files" in post:
for file in post["extra_files"]:
post.update(file)
yield Message.Url, self.file_url.format(**post), post
yield Message.Url, self.file_url.format_map(post), post
@staticmethod
def get_thread_title(post):