Compare commits

...

2 Commits

Author SHA1 Message Date
cddbbcc866 fix expire 2023-07-22 23:25:56 -07:00
a007796147 total bypass from pc vrchat with id 2023-07-22 23:09:56 -07:00

View File

@ -11,15 +11,6 @@ import logging
import re
from textvid import generate_video_from_text
def get_expire(url):
alt_expire = datetime.now() + timedelta(hours=5)
if not url: return alt_expire
q = parse_qs(urlparse(url).query)
expire = q.get('expire')
if not expire: return alt_expire
expire = datetime.fromtimestamp(int(expire[0])) #this seems to always be +6 hours
return min([expire, alt_expire])
ctx_cache = {}
ips_running_ytdl = []
@ -56,7 +47,15 @@ class Handler(BaseHTTPRequestHandler):
path = unquote(self.path)
match = re.match("\/(?:id\/|(?:https?:\/\/)?(?:(?:www\.)?youtube\.com\/(?:watch\?v=|shorts\/)|youtu\.be\/))([A-Za-z0-9_-]{11})", path)
query = match[1] if match else "ytsearch:" + path[1:]
if match:
if self.is_pc_vrchat():
self.send_response(302)
self.send_header("Location", "https://www.youtube.com/watch?v=" + match[1])
self.end_headers()
return
query = match[1]
else:
query = "ytsearch:" + path[1:]
ctx = ctx_cache.get(query)
@ -67,7 +66,10 @@ class Handler(BaseHTTPRequestHandler):
return
try:
ips_running_ytdl.append(client_ip)
ctx_cache[query] = ctx = {'event': Event()}
ctx_cache[query] = ctx = {
'event': Event(),
'expire': datetime.now() + timedelta(hours=5)
}
with YoutubeDL() as ydl:
info = ydl.extract_info(query, download=False)
@ -86,7 +88,11 @@ class Handler(BaseHTTPRequestHandler):
best_format = max(suitable_formats, key=lambda x: x['height'])
ctx['url'] = best_format['url']
ctx['expire'] = get_expire(best_format['url'])
expire = parse_qs(urlparse(best_format['url']).query).get('expire', [])[0]
if expire:
expire = datetime.fromtimestamp(int(expire))
if expire < ctx['expire']: ctx['expire'] = expire
except Exception as e:
logging.exception(e)
ctx['exception'] = e