-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathCDownloaderPornHD.py
More file actions
56 lines (49 loc) · 2.17 KB
/
CDownloaderPornHD.py
File metadata and controls
56 lines (49 loc) · 2.17 KB
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
import requests
import bs4
import os
from CConection import Conection
import json
import io
import subprocess
from subprocess import DEVNULL, STDOUT, check_call
class DownloaderPornHD:
def __init__(self, _output_dir, _search, _first_page, _last_page):
self.output_dir = _output_dir
self.search = str(_search).replace("+", "-")
self.first_page = _first_page
self.last_page = _last_page
self.i = 1
self.j = 1
self.Conection = Conection()
self.list_link = []
def download(self):
self.list_link = self.get_list_link()
if self.list_link != 0:
for j in range(0, len(self.list_link)):
self.json_details_write(len(self.list_link), j, self.list_link[j])
command = 'youtube-dl \"' + self.list_link[j] + '\"' + ' --output \\' + self.output_dir + '\\%(title)s.%(ext)s'
os.system(command)
def get_list_link(self):
if self.Conection.get_status():
for self.i in range(self.first_page, self.last_page):
response = requests.get(str('https://www.pornhd.com/popular/' + self.search + '?page=' + str(self.i)))
soup = bs4.BeautifulSoup(response.text, "html.parser")
for div in soup.find_all(class_='thumb videoThumb popTrigger'): # thumb videoThumb popTrigger é a classe de div que contem os links
link = "https://www.pornhd.com" + str(div['href'])
self.list_link.append(link)
return self.list_link
else:
print("No conection... ")
return 0
# writing a json file to the graphic layer
def json_details_write(self, _list_size, _current_number, _current_link):
percent = (_current_number/_list_size)*100 # percent calc
# Define data
data = {'%': percent,
'range': _list_size,
'current': _current_number,
'link': _current_link}
# Write JSON file
with io.open('data.json', 'w', encoding='utf8') as outfile:
str_ = json.dumps(data, indent=4, sort_keys=True, separators=(',', ': '), ensure_ascii=False)
outfile.write(str_)