92 lines
3.3 KiB
Python
92 lines
3.3 KiB
Python
#!/usr/bin/env python3
|
|
# -*- encoding: utf-8 -*-
|
|
|
|
import filetype
|
|
from bs4 import BeautifulSoup as _BS
|
|
from ..downloadedData import DownloadedData
|
|
from ... import simpleDownloader
|
|
|
|
def BeautifulSoup(data): return _BS(data, 'html5lib')
|
|
|
|
def works_on(domain):
|
|
return domain.endswith('.deviantart.com')
|
|
|
|
class UserDeviantArtCom(object):
|
|
def recognizes(self, link):
|
|
if (
|
|
'.deviantart.com/art/' in link
|
|
or
|
|
'.deviantart.com/gallery/' in link
|
|
):
|
|
return True
|
|
return False
|
|
|
|
def download(self, link):
|
|
dd = DownloadedData()
|
|
simpleDownloader.cleanCookies()
|
|
simpleDownloader.setCookie('agegate_state',1)
|
|
if '.deviantart.com/art/' in link:
|
|
print(' '*25,end='')
|
|
print('\r',end='')
|
|
print(' `--> Fetching art link',end='')
|
|
print('\r',end='')
|
|
pagebts = simpleDownloader.getUrlBytes(link)
|
|
if pagebts is None:
|
|
return DownloadedData()
|
|
if b'blocked agegate-option-content' in pagebts:
|
|
return None
|
|
pagebs = BeautifulSoup(pagebts)
|
|
imgbs = pagebs.find('img', class_='dev-content-full')
|
|
if imgbs is None:
|
|
return dd
|
|
imglnk = imgbs['src']
|
|
print(' '*25,end='')
|
|
print('\r',end='')
|
|
print(' `--> Fetching art',end='')
|
|
print('\r',end='')
|
|
imgbts = simpleDownloader.getUrlBytes(imglnk)
|
|
if imgbts is not None:
|
|
dd.put(imglnk, imgbts, filetype.guess_extension(imgbts))
|
|
return dd
|
|
elif '.deviantart.com/gallery/' in link:
|
|
print(' '*50,end='')
|
|
print('\r',end='')
|
|
print(' `--> Fetching art gallery page #001',end='')
|
|
print('\r',end='')
|
|
pagebts = simpleDownloader.getUrlBytes(link)
|
|
if pagebts is None:
|
|
return DownloadedData()
|
|
if b'blocked agegate-option-content' in pagebts:
|
|
return None
|
|
nextbs = link
|
|
imglnks = list()
|
|
i=0
|
|
while nextbs is not None:
|
|
i+=1
|
|
print(' '*50,end='')
|
|
print('\r',end='')
|
|
print(' `--> Fetching art gallery page #%03d'%i,end='')
|
|
print('\r',end='')
|
|
pagebs = BeautifulSoup(pagebts)
|
|
nextbs = pagebs.find('head').find('link',rel='next')
|
|
if nextbs is not None:
|
|
nextbs = nextbs['href']
|
|
pagebts = simpleDownloader.getUrlBytes(nextbs)
|
|
containerbs = pagebs.find(class_='folderview-art')
|
|
imgsbs = list(map(lambda a: a['href'], containerbs.find_all('a', class_='torpedo-thumb-link')))
|
|
imgsbs = list(filter(lambda a: '.deviantart.com/art/' in a, imgsbs))
|
|
imglnks = list(set(list(imgsbs)+list(imglnks)))
|
|
limgs = len(imglnks)
|
|
for seq, imglnk in enumerate(imglnks):
|
|
print(' '*50,end='')
|
|
print('\r',end='')
|
|
print(' '*25,end='')
|
|
print('#%03d of %03d'%(seq+1,limgs),end='')
|
|
print('\r',end='')
|
|
dd.merge(self.download(imglnk))
|
|
return dd
|
|
return None
|
|
|
|
def get_class():
|
|
return UserDeviantArtCom
|