-
Notifications
You must be signed in to change notification settings - Fork 6
/
coomersu_downloader.py
107 lines (102 loc) · 7.3 KB
/
coomersu_downloader.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#coding: utf8
#title_en: Coomer.Su
#comment: https://coomer.su/
import downloader
from utils import Downloader, Soup, urljoin, get_ext, clean_title, get_print, print_error
from translator import tr_
@Downloader.register
class Downloader_coomer(Downloader):
type = 'coomer.su'
URLS = ['coomer.party','coomer.su']
icon = 'base64:AAABAAEAGBgAAAEAIAAoCQAAFgAAACgAAAAYAAAAMAAAAAEAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAIwAAAJgAAAGbAAAAlAAAADUAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAEBBwUArRAKAP8BAAD/CQUA/wcEALkAAAACAAAAAAAAAAAAAAEAAAAAAAEAAAAAAAAAAAEAAAAAAAAAAAEAAAAAAAAAAAAAAAEAAAEAAAEAAAAAAAAAAAAAAAAAAAAAAABWj18A/9qWAP+8fgD/0JEA/5JhAP8AAABTAAEAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAABFJMgDY+6sA//+1AP//tAD//7cA//mqAP9DKgHMAAAACQAAAAAAAAAAAAEAAAEAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAA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AAAABEAAAAtAAEATAEAAHUAAABqAAAAVAAAABoAAAAXAAEAAAAAAAAAAAEAAAAADCocAJx6UQH/JBkAlgEAAAACAgCDAAAApgAAABgAAAAAAAAAAAEAAAAAAAEAAAAAAAEAAAAAAAEAAAAAEgEAAAsAAAAKAAEAEQAAAAAAAAAAAAEAAAEAAAAAAAAAAAAAAAEAAAAAAACIAgIA0QEAAA8AAAEuAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAEAAAEAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAEAAAEAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAATQEAABo='
display_name = 'Coomer.Su'
MAX_PARALLEL = 1
MAX_CORE = 4
def read(self):
if '/post/' in self.url:
self.title, self.urls, self.filenames = read_post(self.url, self.cw)
titu = self.filenames[self.urls[0]]
self.cw.setTitle(titu[:titu.find('/')])
else:
self.title, self.urls, self.filenames = read_user(self.url, self.cw)
#self.enableSegment(chunk=2**20,n_threads=2)
def read_user(url, cw):
soup = Soup(downloader.read_html(url))
galerias = []
idp = soup.find('meta', {'name': 'id'})['content']
username = soup.find('meta', {'name': 'artist_name'})['content']
titu = clean_title(username +'('+ idp)
nga = 0
elementos = soup.find('div', class_='card-list__items').findAll('a')
for a in elementos:
galerias.append(a.attrs['href'])
Next = soup.find('a', class_='next')
cw.setTitle('{} {} - {}'.format(tr_('읽는 중...'), titu, nga))
while Next:
href = Next.attrs['href']
soup = Soup(downloader.read_html('https://coomer.su'+href))
elementos = soup.find('div', class_='card-list__items').findAll('a')
for a in elementos:
galerias.append(a.attrs['href'])
Next = soup.find('a', class_='next')
files = []
namefiles = {}
for gale in galerias:
_, urls, filenames = read_post('https://coomer.su'+gale, cw)
files += urls
namefiles.update(filenames)
nga += 1
cw.setTitle('{} {} - {}'.format(tr_('읽는 중...'), titu, nga))
return titu, files, namefiles
def read_post(url, cw):
print_ = get_print(cw)
soup = Soup(downloader.read_html(url))
title = soup.find('h1').text
idp = soup.find('meta', {'name': 'id'})['content']
usid = soup.find('meta', {'name': 'user'})['content']
usuar = soup.find('a', class_='post__user-name').text.strip()
tail = '({}'.format(idp)
info = '{}{}'.format(clean_title(title, allow_dot=True, n=-len(tail)), tail)
imgs = []
filenames = {}
# Downloads
for item in soup.findAll('li', class_='post__attachment'):
href = urljoin(url, item.find('a')['href'])
ext = get_ext(href) or '.item'
filenames[href] = '{}/{:04}{}'.format(info, len(imgs), ext)
imgs.append(href)
# Files
files = soup.find('div', class_='post__files')
if files:
for item in files.findChildren(recursive=False):
a = item if 'href' in item.attrs else item.find('a')
href = urljoin(url, a['href'])
# Imgur
if 'imgur.com/' in href:
print_('Imgur: {}'.format(href))
try:
from extractor import imgur_downloader
for img in imgur_downloader.get_imgs(href):
ext = get_ext(img) or downloader.get_ext(img)
filenames[img] = '{}/{:04}{}'.format(info, len(imgs), ext)
imgs.append(img)
except Exception as e:
print_(print_error(e))
continue
ext = get_ext(href) or '.file'
filenames[href] = '{}/{:04}{}'.format(info, len(imgs), ext)
imgs.append(href)
# Content
content = soup.find('div', class_='post__content')
if content:
for img in content.findAll('img'):
src = urljoin(url, img['src'])
ext = get_ext(src) or downloader.get_ext(src)
filenames[src] = '{}/{:04}{}'.format(info, len(imgs), ext)
imgs.append(src)
for a in content.findAll('a'):
href = a['href']
ext = '.cont'#get_ext(href) or downloader.get_ext(href)
filenames[href] = '{}/{:04}{}'.format(info, len(imgs), ext)
imgs.append(href)
return clean_title(usuar +'('+ usid), imgs, filenames