-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerator.py
More file actions
executable file
·134 lines (104 loc) · 3.28 KB
/
generator.py
File metadata and controls
executable file
·134 lines (104 loc) · 3.28 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
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
ay@no-ma..me 20201125 073526 -0800 PST 1606318526 d(-_- )b...
"""
from contextlib import closing
import random
import json
import time
import youtube_dl
from cachetools import cached, LRUCache
from requests import post
from requests.exceptions import RequestException
from bs4 import BeautifulSoup
from logzero import logger as log
import logzero
logzero.json()
ytdllog = logzero.setup_logger(
name="ytdllog", level=logzero.INFO, disableStderrLogger=True
)
class MyLogger:
def debug(self, msg):
ytdllog.debug(msg)
def warning(self, msg):
ytdllog.warning(msg)
def error(self, msg):
log.error(msg)
# Blacklisted sites, these sites "work" with youtube_dl, but don't work for us
blacklist = [
"dailymotion.com",
"facebook.com",
"instagram.com",
"microsoft.com",
"porndig.com",
"rexxx.org",
"spankbang.com",
"tiktok.com",
"tukif.com",
"txxx.com",
"vimeo.com",
"xhamster.com",
"xxxbunker.com",
"youtube.com",
]
ydl_opts = {
"format": "([protocol=https]/[protocol=http])[ext=mp4]",
"ignoreerrors": True,
"quiet": True,
"no_warnings": True,
"noplaylist": True,
"sleep-interval": 1,
"max-sleep-interval": 5,
"user-agent": "Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36,gzip(gfe)",
"logger": MyLogger(),
}
def searchPorn(search, results=105, length=20):
"""See pore porn, see no ads, usin the best search porn enine, Bing!"""
length_param = ""
if length and int(length) >= 20:
length_param = "+filterui:duration-long"
srch = "https://www.bing.com/videos/asyncv2"
srch += '?q="{}" AND NOT (site:{})'
srch += "&async=content"
srch += "&first=0&count={}&qft={}"
blklst = " OR site:".join(blacklist)
search_url = srch.format(search.lower(), blklst, results, length_param)
html = BeautifulSoup(simple_get(search_url), "html.parser")
narrowed_html = html.find_all(class_="vrhdata")
link_list = [json.loads(n_html["vrhm"])["pgurl"] for n_html in narrowed_html]
random.shuffle(link_list)
def url_generator(linklist):
for link in linklist:
stream = getstream(link)
if stream:
log.warn({"link": link, "stream": stream})
yield stream
else:
continue
return url_generator(link_list)
# Boilerplate requests stuff
def simple_get(url):
cookiecontent = "ADLT=OFF&CW=1117&CH=1771&DPR=2&UTC=-360&HV={}"
cookie = {"SRCHHPGUSR": cookiecontent.format(str(int(time.time())))}
try:
with closing(post(url, cookies=cookie)) as resp:
if resp.ok and "html" in resp.headers["Content-Type"]:
return resp.content
return None
except RequestException as err:
log.error(err)
return None
@cached(cache=LRUCache(maxsize=1024))
def getstream(link):
try:
time.sleep(1)
ydl_opts["referer"] = link
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
vidurl = ydl.extract_info(link, download=False).get("url", None)
return vidurl
except AttributeError:
...
if __name__ == "__main__":
...
# vim: set ft=python sw=4 tw=0 fdm=manual et :