1
0
Fork 0
mirror of https://github.com/kemayo/leech synced 2026-05-08 12:34:37 +02:00

Explicitly support XenForo

This commit is contained in:
David Lynch 2015-10-28 15:52:11 -05:00
parent ecfe1f35a8
commit 150d0f63d5
2 changed files with 39 additions and 13 deletions

View file

@ -20,6 +20,8 @@ class Site:
def _soup(self, url, method='html5lib'): def _soup(self, url, method='html5lib'):
page = self.fetch(url) page = self.fetch(url)
if not page:
raise SiteException("Couldn't fetch", url)
return BeautifulSoup(page, method) return BeautifulSoup(page, method)
class SiteException(Exception): class SiteException(Exception):
@ -35,4 +37,4 @@ def get(url):
return site_class return site_class
# And now, the things that will use this: # And now, the things that will use this:
from . import spacebattles, fanfictionnet, deviantart, stash from . import xenforo, fanfictionnet, deviantart, stash

View file

@ -4,13 +4,14 @@ import re
from . import register, Site, SiteException from . import register, Site, SiteException
@register class XenForo(Site):
class SpaceBattles(Site): """XenForo is forum software that powers a number of fiction-related forums."""
"""SpaceBattles is a forum..."""
@staticmethod domain = False
def matches(url):
return re.match(r'^https?://forums.(?:spacebattles|sufficientvelocity).com/threads/.*\d+/?.*', url) @classmethod
def matches(cls, url):
return re.match(r'^https?://%s/threads/.*\d+/?.*' % cls.domain, url)
def extract(self, url): def extract(self, url):
soup = self._soup(url) soup = self._soup(url)
@ -101,12 +102,35 @@ class SpaceBattles(Site):
return post.prettify() return post.prettify()
@register class XenForoIndex(XenForo):
class SpaceBattlesIndex(SpaceBattles): @classmethod
"""A spacebattles thread with an index post""" def matches(cls, url):
@staticmethod return re.match(r'^https?://%s/posts/\d+/?.*' % cls.domain, url)
def matches(url):
return re.match(r'^https?://forums.(?:spacebattles|sufficientvelocity).com/posts/\d+/?.*', url)
def _chapter_list(self, url): def _chapter_list(self, url):
return self._chapter_list_index(url) return self._chapter_list_index(url)
@register
class SpaceBattles(XenForo):
domain = 'forums.spacebattles.com'
@register
class SpaceBattlesIndex(XenForoIndex):
domain = 'forums.spacebattles.com'
@register
class SufficientVelocity(XenForo):
domain = 'forums.sufficientvelocity.com'
@register
class QuestionableQuesting(XenForo):
domain = 'forum.questionablequesting.com'
@register
class QuestionableQuestingIndex(QuestionableQuesting, XenForoIndex):
pass