forked from rDrama/rDrama
automate more aspects of mn + allow scheduling orgies
parent
672fee15ef
commit
f978df8580
|
@ -1,5 +1,6 @@
|
||||||
import time
|
import time
|
||||||
from flask import g, abort
|
from flask import g, abort
|
||||||
|
import requests
|
||||||
|
|
||||||
from sqlalchemy import Column, or_
|
from sqlalchemy import Column, or_
|
||||||
from sqlalchemy.sql.sqltypes import *
|
from sqlalchemy.sql.sqltypes import *
|
||||||
|
@ -7,6 +8,7 @@ from sqlalchemy.sql.sqltypes import *
|
||||||
from files.classes import Base
|
from files.classes import Base
|
||||||
|
|
||||||
from files.helpers.lazy import lazy
|
from files.helpers.lazy import lazy
|
||||||
|
from files.helpers.config.const import *
|
||||||
|
|
||||||
class Orgy(Base):
|
class Orgy(Base):
|
||||||
__tablename__ = "orgies"
|
__tablename__ = "orgies"
|
||||||
|
@ -15,7 +17,9 @@ class Orgy(Base):
|
||||||
data = Column(String)
|
data = Column(String)
|
||||||
title = Column(String)
|
title = Column(String)
|
||||||
created_utc = Column(Integer)
|
created_utc = Column(Integer)
|
||||||
|
start_utc = Column(Integer)
|
||||||
end_utc = Column(Integer)
|
end_utc = Column(Integer)
|
||||||
|
started = Column(Boolean, default=False)
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
if "created_utc" not in kwargs: kwargs["created_utc"] = int(time.time())
|
if "created_utc" not in kwargs: kwargs["created_utc"] = int(time.time())
|
||||||
|
@ -26,8 +30,8 @@ class Orgy(Base):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@lazy
|
@lazy
|
||||||
def real_created_utc(self):
|
def real_start_utc(self):
|
||||||
t = self.created_utc
|
t = self.start_utc
|
||||||
if int(time.time()) - t > 3000:
|
if int(time.time()) - t > 3000:
|
||||||
t += 303
|
t += 303
|
||||||
return t
|
return t
|
||||||
|
@ -35,10 +39,17 @@ class Orgy(Base):
|
||||||
def get_orgy(v):
|
def get_orgy(v):
|
||||||
if not (v and v.allowed_in_chat): return None
|
if not (v and v.allowed_in_chat): return None
|
||||||
|
|
||||||
orgy = g.db.query(Orgy).one_or_none()
|
expired_orgies = g.db.query(Orgy).filter(Orgy.end_utc != None, Orgy.end_utc < time.time()).all()
|
||||||
|
for x in expired_orgies:
|
||||||
|
g.db.delete(x)
|
||||||
|
|
||||||
if orgy and orgy.end_utc and orgy.end_utc < time.time():
|
if expired_orgies:
|
||||||
g.db.delete(orgy)
|
requests.post('http://localhost:5001/refresh_chat', headers={"Host": SITE})
|
||||||
return None
|
|
||||||
|
orgy = g.db.query(Orgy).filter(Orgy.start_utc < time.time()).order_by(Orgy.start_utc).first()
|
||||||
|
if orgy and not orgy.started:
|
||||||
|
orgy.started = True
|
||||||
|
g.db.add(orgy)
|
||||||
|
requests.post('http://localhost:5001/refresh_chat', headers={"Host": SITE})
|
||||||
|
|
||||||
return orgy
|
return orgy
|
||||||
|
|
|
@ -306,7 +306,7 @@ MODACTION_TYPES = {
|
||||||
"icon": 'fa-eye-slash',
|
"icon": 'fa-eye-slash',
|
||||||
"color": 'bg-danger'
|
"color": 'bg-danger'
|
||||||
},
|
},
|
||||||
'start_orgy': {
|
'schedule_orgy': {
|
||||||
"str": 'started orgy',
|
"str": 'started orgy',
|
||||||
"icon": 'fa-tv',
|
"icon": 'fa-tv',
|
||||||
"color": 'bg-success'
|
"color": 'bg-success'
|
||||||
|
|
|
@ -88,7 +88,7 @@ def cron_fn(every_5m, every_1d, every_fri_12, every_fri_23, every_sat_00, every_
|
||||||
|
|
||||||
|
|
||||||
if every_fri_12:
|
if every_fri_12:
|
||||||
_create_post(f'Movie Night', f'''Our Movie Night today will show `{get_name()}`.\nThe movies will start at 8 PM EST. [Here is a timezone converter for whoever needs it.](https://dateful.com/time-zone-converter?t=8pm&tz1=EST-EDT-Eastern-Time). You can also check this [countdown timer](https://www.tickcounter.com/countdown/4435809/movie-night) instead.\nThey will be shown [here](/chat).\nThere will be a 5-minute bathroom break at the 50:00 mark.\nRerun will be Sunday 4 PM EST.''', 11)
|
_create_post(f'Movie Night', f'''Our Movie Night today will show `{get_names()}`.\nThe movies will start at 8 PM EST. [Here is a timezone converter for whoever needs it.](https://dateful.com/time-zone-converter?t=8pm&tz1=EST-EDT-Eastern-Time). You can also check this [countdown timer](https://www.tickcounter.com/countdown/4435809/movie-night) instead.\nThey will be shown [here](/chat).\nThere will be a 5-minute bathroom break at the 50:00 mark.\nRerun will be Sunday 4 PM EST.''', 11)
|
||||||
g.db.commit()
|
g.db.commit()
|
||||||
|
|
||||||
if every_fri_23:
|
if every_fri_23:
|
||||||
|
@ -96,16 +96,13 @@ def cron_fn(every_5m, every_1d, every_fri_12, every_fri_23, every_sat_00, every_
|
||||||
g.db.commit()
|
g.db.commit()
|
||||||
|
|
||||||
if every_sun_07:
|
if every_sun_07:
|
||||||
_create_post(f'Movie Night Rerun', f'''Our Movie Night Rerun today will show `{get_name()}`.\nThe movies will start at 4 PM EST. [Here is a timezone converter for whoever needs it.](https://dateful.com/time-zone-converter?t=4pm&tz1=EST-EDT-Eastern-Time). You can also check this [countdown timer](https://www.tickcounter.com/countdown/4465675/movie-night-rerun) instead.\nThey will be shown [here](/chat).\nThere will be a 5-minute bathroom break at the 50:00 mark.''', 1)
|
_create_post(f'Movie Night Rerun', f'''Our Movie Night Rerun today will show `{get_names()}`.\nThe movies will start at 4 PM EST. [Here is a timezone converter for whoever needs it.](https://dateful.com/time-zone-converter?t=4pm&tz1=EST-EDT-Eastern-Time). You can also check this [countdown timer](https://www.tickcounter.com/countdown/4465675/movie-night-rerun) instead.\nThey will be shown [here](/chat).\nThere will be a 5-minute bathroom break at the 50:00 mark.''', 1)
|
||||||
g.db.commit()
|
g.db.commit()
|
||||||
|
|
||||||
if every_sun_19:
|
if every_sun_19:
|
||||||
_create_post(f'Movie Night Rerun in 60 minutes', 'It will be shown [here](/chat).\nThere will be a 5-minute bathroom break at the 50:00 mark.', 1)
|
_create_post(f'Movie Night Rerun in 60 minutes', 'It will be shown [here](/chat).\nThere will be a 5-minute bathroom break at the 50:00 mark.', 1)
|
||||||
g.db.commit()
|
g.db.commit()
|
||||||
|
|
||||||
if every_sat_00 or every_sun_20:
|
|
||||||
_create_and_delete_orgy()
|
|
||||||
|
|
||||||
if every_sat_03 or every_sun_23:
|
if every_sat_03 or every_sun_23:
|
||||||
_delete_all_posts()
|
_delete_all_posts()
|
||||||
g.db.commit()
|
g.db.commit()
|
||||||
|
@ -140,16 +137,13 @@ def cron_fn(every_5m, every_1d, every_fri_12, every_fri_23, every_sat_00, every_
|
||||||
def cron(**kwargs):
|
def cron(**kwargs):
|
||||||
cron_fn(**kwargs)
|
cron_fn(**kwargs)
|
||||||
|
|
||||||
def get_file():
|
def get_names():
|
||||||
return max(glob.glob('/orgies/*'), key=os.path.getctime).split('/orgies/')[1]
|
return ' and '.join([x[0] for x in g.db.query(Orgy.title).filter_by(type='file').order_by(Orgy.start_utc)])
|
||||||
|
|
||||||
def get_name():
|
|
||||||
return get_file().split('.')[0]
|
|
||||||
|
|
||||||
def _create_post(title, body, pin_hours):
|
def _create_post(title, body, pin_hours):
|
||||||
_delete_all_posts()
|
_delete_all_posts()
|
||||||
|
|
||||||
title += f': {get_name()}'
|
title += f': {get_names()}'
|
||||||
|
|
||||||
title_html = filter_emojis_only(title)
|
title_html = filter_emojis_only(title)
|
||||||
body_html = sanitize(body)
|
body_html = sanitize(body)
|
||||||
|
@ -184,26 +178,6 @@ def _create_post(title, body, pin_hours):
|
||||||
|
|
||||||
cache.delete_memoized(frontlist)
|
cache.delete_memoized(frontlist)
|
||||||
|
|
||||||
def _create_and_delete_orgy():
|
|
||||||
video_info = ffmpeg.probe(f'/orgies/{get_file()}')
|
|
||||||
seconds = float(video_info['streams'][0]['duration'])
|
|
||||||
end_utc = int(time.time() + seconds)
|
|
||||||
|
|
||||||
orgy = Orgy(
|
|
||||||
title=get_name(),
|
|
||||||
type='file',
|
|
||||||
data=f'https://videos.watchpeopledie.tv/orgies/{get_file()}',
|
|
||||||
end_utc = end_utc,
|
|
||||||
)
|
|
||||||
g.db.add(orgy)
|
|
||||||
g.db.commit()
|
|
||||||
g.db.close()
|
|
||||||
del g.db
|
|
||||||
stdout.flush()
|
|
||||||
|
|
||||||
requests.post('http://localhost:5001/refresh_chat', headers={"Host": SITE})
|
|
||||||
|
|
||||||
|
|
||||||
def _delete_all_posts():
|
def _delete_all_posts():
|
||||||
posts = g.db.query(Post).filter_by(author_id=AUTOJANNY_ID, deleted_utc=0).all()
|
posts = g.db.query(Post).filter_by(author_id=AUTOJANNY_ID, deleted_utc=0).all()
|
||||||
for p in posts:
|
for p in posts:
|
||||||
|
|
|
@ -1942,14 +1942,14 @@ def admin_reset_password(user_id, v):
|
||||||
@app.get("/admin/orgy")
|
@app.get("/admin/orgy")
|
||||||
@admin_level_required(PERMS['ORGIES'])
|
@admin_level_required(PERMS['ORGIES'])
|
||||||
def orgy_control(v):
|
def orgy_control(v):
|
||||||
orgy = g.db.query(Orgy).one_or_none()
|
return render_template("admin/orgy_control.html", v=v, orgy=get_orgy(v))
|
||||||
return render_template("admin/orgy_control.html", v=v, orgy=orgy)
|
|
||||||
|
|
||||||
@app.post("/admin/start_orgy")
|
@app.post("/admin/schedule_orgy")
|
||||||
@admin_level_required(PERMS['ORGIES'])
|
@admin_level_required(PERMS['ORGIES'])
|
||||||
def start_orgy(v):
|
def schedule_orgy(v):
|
||||||
link = request.values.get("link", "").strip()
|
link = request.values.get("link", "").strip()
|
||||||
title = request.values.get("title", "").strip()
|
title = request.values.get("title", "").strip()
|
||||||
|
start_utc = request.values.get("start_utc", "").strip()
|
||||||
|
|
||||||
if not link:
|
if not link:
|
||||||
abort(400, "A link is required!")
|
abort(400, "A link is required!")
|
||||||
|
@ -1961,6 +1961,12 @@ def start_orgy(v):
|
||||||
abort(400, "An orgy is already in progress")
|
abort(400, "An orgy is already in progress")
|
||||||
|
|
||||||
normalized_link = normalize_url(link)
|
normalized_link = normalize_url(link)
|
||||||
|
|
||||||
|
if start_utc:
|
||||||
|
start_utc = int(start_utc)
|
||||||
|
else:
|
||||||
|
start_utc = int(time.time())
|
||||||
|
|
||||||
end_utc = None
|
end_utc = None
|
||||||
|
|
||||||
if bare_youtube_regex.match(normalized_link):
|
if bare_youtube_regex.match(normalized_link):
|
||||||
|
@ -1982,7 +1988,8 @@ def start_orgy(v):
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
seconds = float(video_info['streams'][0]['duration'])
|
seconds = float(video_info['streams'][0]['duration'])
|
||||||
end_utc = int(time.time() + seconds)
|
if seconds > 2.0:
|
||||||
|
end_utc = int(start_utc + seconds)
|
||||||
else:
|
else:
|
||||||
abort(400)
|
abort(400)
|
||||||
|
|
||||||
|
@ -1990,20 +1997,18 @@ def start_orgy(v):
|
||||||
title=title,
|
title=title,
|
||||||
type=orgy_type,
|
type=orgy_type,
|
||||||
data=data,
|
data=data,
|
||||||
|
start_utc=start_utc,
|
||||||
end_utc=end_utc,
|
end_utc=end_utc,
|
||||||
)
|
)
|
||||||
g.db.add(orgy)
|
g.db.add(orgy)
|
||||||
|
|
||||||
ma = ModAction(
|
ma = ModAction(
|
||||||
kind="start_orgy",
|
kind="schedule_orgy",
|
||||||
user_id=v.id,
|
user_id=v.id,
|
||||||
_note=data,
|
_note=data,
|
||||||
)
|
)
|
||||||
g.db.add(ma)
|
g.db.add(ma)
|
||||||
|
|
||||||
g.db.commit()
|
|
||||||
requests.post('http://localhost:5001/refresh_chat', headers={"Host": SITE})
|
|
||||||
|
|
||||||
return redirect('/chat')
|
return redirect('/chat')
|
||||||
|
|
||||||
@app.post("/admin/stop_orgy")
|
@app.post("/admin/stop_orgy")
|
||||||
|
@ -2021,8 +2026,9 @@ def stop_orgy(v):
|
||||||
)
|
)
|
||||||
g.db.add(ma)
|
g.db.add(ma)
|
||||||
|
|
||||||
g.db.delete(orgy)
|
orgy.end_utc = int(time.time())
|
||||||
|
g.db.add(orgy)
|
||||||
|
|
||||||
requests.post('http://localhost:5001/refresh_chat', headers={"Host": SITE})
|
get_orgy(v) #don't remove this, it's necessary (trust)
|
||||||
|
|
||||||
return {"message": "Orgy stopped successfully!"}
|
return {"message": "Orgy stopped successfully!"}
|
||||||
|
|
|
@ -71,13 +71,7 @@ def chat(v):
|
||||||
|
|
||||||
orgy = get_orgy(v)
|
orgy = get_orgy(v)
|
||||||
if orgy:
|
if orgy:
|
||||||
m = md5()
|
return render_template("orgy.html", v=v, messages=displayed_messages, orgy=orgy)
|
||||||
with open('files/assets/subtitles.vtt', "rb") as f:
|
|
||||||
data = f.read()
|
|
||||||
m.update(data)
|
|
||||||
subtitles_hash = m.hexdigest()
|
|
||||||
|
|
||||||
return render_template("orgy.html", v=v, messages=displayed_messages, orgy=orgy, subtitles_hash=subtitles_hash)
|
|
||||||
|
|
||||||
return render_template("chat.html", v=v, messages=displayed_messages)
|
return render_template("chat.html", v=v, messages=displayed_messages)
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
{% if v.admin_level >= PERMS['ORGIES'] %}
|
{% if v.admin_level >= PERMS['ORGIES'] %}
|
||||||
<h4>Orgies</h4>
|
<h4>Orgies</h4>
|
||||||
<ul>
|
<ul>
|
||||||
<li><a href="/admin/orgy">Start/Stop Orgy</a></li>
|
<li><a href="/admin/orgy">Schedule/Stop Orgy</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
<div class="body d-lg-flex">
|
<div class="body d-lg-flex">
|
||||||
<div class="w-lg-100">
|
<div class="w-lg-100">
|
||||||
{% if not orgy %}
|
{% if not orgy %}
|
||||||
<form id="orgy" action="/admin/start_orgy" method="post">
|
<form id="orgy" action="/admin/schedule_orgy" method="post">
|
||||||
<div class="d-lg-flex border-bottom">
|
<div class="d-lg-flex border-bottom">
|
||||||
<div class="title w-lg-25">
|
<div class="title w-lg-25">
|
||||||
<label for="title">Title</label>
|
<label for="title">Title</label>
|
||||||
|
@ -22,17 +22,25 @@
|
||||||
<input id="title" autocomplete="off" type="text" name="title" class="form-control">
|
<input id="title" autocomplete="off" type="text" name="title" class="form-control">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="d-lg-flex border-bottom">
|
<div class="d-lg-flex border-bottom mt-3">
|
||||||
<div class="title w-lg-25">
|
<div class="title w-lg-25">
|
||||||
<label for="link">Livestream link (youtube, twitch, rumble, mp4 file)</label>
|
<label for="link">Link (youtube, twitch, rumble, mp4 file)</label>
|
||||||
</div>
|
</div>
|
||||||
<div class="body w-lg-100">
|
<div class="body w-lg-100">
|
||||||
<input id="link" autocomplete="off" type="text" name="link" class="form-control">
|
<input id="link" autocomplete="off" type="text" name="link" class="form-control">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="d-lg-flex border-bottom mt-3">
|
||||||
|
<div class="title w-lg-25">
|
||||||
|
<label for="link">Start time (as an <a rel="nofollow noopener" href="https://epochconverter.com">epoch timestamp</a>)</label>
|
||||||
|
</div>
|
||||||
|
<div class="body w-lg-100">
|
||||||
|
<input autocomplete="off" type="number" step="any" name="start_utc" max="2147483647" class="form-control" placeholder="Leave blank to start orgy now">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<input hidden name="formkey" value="{{v|formkey}}">
|
<input hidden name="formkey" value="{{v|formkey}}">
|
||||||
<div class="d-flex mt-2">
|
<div class="d-flex mt-3">
|
||||||
<input id="start-orgy" autocomplete="off" class="btn btn-primary ml-auto" type="submit" value="Start Orgy">
|
<input id="start-orgy" autocomplete="off" class="btn btn-primary ml-auto" type="submit" value="Schedule Orgy">
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
{% else %}
|
{% else %}
|
||||||
|
|
|
@ -24,8 +24,11 @@
|
||||||
<iframe src="https://player.twitch.tv/?channel={{orgy.data}}&parent={{SITE}}" frameborder="0" allowfullscreen></iframe>
|
<iframe src="https://player.twitch.tv/?channel={{orgy.data}}&parent={{SITE}}" frameborder="0" allowfullscreen></iframe>
|
||||||
{% elif orgy.type == 'file' %}
|
{% elif orgy.type == 'file' %}
|
||||||
<meta name="referrer" content="strict-origin-when-cross-origin">
|
<meta name="referrer" content="strict-origin-when-cross-origin">
|
||||||
<video id="orgy-file" data-created_utc="{{orgy.real_created_utc}}" controls preload="none" src="{{orgy.data}}">
|
<video id="orgy-file" data-created_utc="{{orgy.real_start_utc}}" controls preload="none" src="{{orgy.data}}">
|
||||||
<track label="English" kind="subtitles" srclang="en" src="/assets/subtitles.vtt?x={{subtitles_hash}}" default>
|
{% set subtitles_path = '/assets/' ~ orgy.data.split('/')[-1].split('.')[0] ~ '.vtt' %}
|
||||||
|
{% if os_path.exists(subtitles_path) %}
|
||||||
|
<track label="English" kind="subtitles" srclang="en" src="{{subtitles_path}}" default>
|
||||||
|
{% endif %}
|
||||||
</video>
|
</video>
|
||||||
<video id="break-file" class="d-none" controls preload="none" src="/assets/break.mp4" data-run="0"></video>
|
<video id="break-file" class="d-none" controls preload="none" src="/assets/break.mp4" data-run="0"></video>
|
||||||
<script defer src="{{'js/orgy_file.js' | asset}}"></script>
|
<script defer src="{{'js/orgy_file.js' | asset}}"></script>
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
alter table orgies add column start_utc int not null;
|
||||||
|
alter table orgies add column started bool not null;
|
||||||
|
update modactions set kind='schedule_orgy' where kind='start_orgy';
|
Loading…
Reference in New Issue