mirror of
https://github.com/kemayo/leech
synced 2026-01-08 16:48:24 +01:00
Support deviantart favourites / galleries
This commit is contained in:
parent
0e4632c709
commit
d532962696
1 changed files with 44 additions and 0 deletions
44
sites/deviantart.py
Normal file
44
sites/deviantart.py
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
#!/usr/bin/python
|
||||
|
||||
import re
|
||||
from bs4 import BeautifulSoup
|
||||
|
||||
from .stash import _extract_chapter
|
||||
|
||||
|
||||
def match(url):
|
||||
# Need a collection page
|
||||
return re.match(r'^https?://[^.]+\.deviantart\.com/(?:gallery|favourites)/\d+/?', url)
|
||||
|
||||
|
||||
def extract(url, fetch):
|
||||
page = fetch(url)
|
||||
soup = BeautifulSoup(page, 'html5lib')
|
||||
content = soup.find(id="output")
|
||||
if not content:
|
||||
return
|
||||
|
||||
story = {}
|
||||
chapters = []
|
||||
|
||||
if "gallery" in url:
|
||||
story['author'] = str(content.select('h1 a.u')[0].string)
|
||||
else:
|
||||
authors = set(str(author.string) for author in content.select('.stream .details a.u'))
|
||||
story['author'] = ', '.join(authors)
|
||||
|
||||
story['title'] = str(content.find(class_="folder-title").string)
|
||||
|
||||
thumbs = content.select(".stream a.thumb")
|
||||
if not thumbs:
|
||||
return
|
||||
for thumb in thumbs:
|
||||
try:
|
||||
if thumb['href'] is not '#':
|
||||
chapters.append(_extract_chapter(thumb['href'], fetch))
|
||||
except Exception as e:
|
||||
print(e)
|
||||
|
||||
story['chapters'] = chapters
|
||||
|
||||
return story
|
||||
Loading…
Reference in a new issue