sync nonlive youtube orgy and make it end automatically

pull/225/head
Aevann 2024-03-02 22:03:21 +02:00
parent 177a0075a9
commit d33eebb7bb
4 changed files with 14 additions and 1 deletions

View File

@ -36,6 +36,11 @@ class Orgy(Base):
t += 303
return t
@property
@lazy
def seconds_since_starts(self):
return int(time.time() - self.start_utc)
def get_running_orgy(v):
if not (v and v.allowed_in_chat): return None

View File

@ -3,6 +3,7 @@ from math import floor
import os
import ffmpeg
import random
import isodate
from sqlalchemy.orm import load_only
@ -1946,6 +1947,12 @@ def schedule_orgy(v):
if bare_youtube_regex.match(normalized_link):
orgy_type = 'youtube'
data, _ = get_youtube_id_and_t(normalized_link)
if YOUTUBE_KEY != DEFAULT_CONFIG_VALUE:
req = requests.get(f"https://www.googleapis.com/youtube/v3/videos?id={data}&key={YOUTUBE_KEY}&part=contentDetails", headers=HEADERS, timeout=5).json()
duration = req['items'][0]['contentDetails']['duration']
if duration != 'P0D':
duration = isodate.parse_duration(duration).total_seconds()
end_utc = int(start_utc + duration)
elif rumble_regex.match(normalized_link):
orgy_type = 'rumble'
data = normalized_link

View File

@ -17,7 +17,7 @@
<div>
<p id="orgy-file-container" class="resizable">
{% if orgy.type == 'youtube' %}
<iframe style="border: none" sandbox="allow-scripts allow-same-origin allow-popups allow-presentation allow-popups-to-escape-sandbox" title="Play" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen src="https://cdpn.io/pen/debug/NWeVNRj?v={{orgy.data}}&autoplay=1&modestbranding=1"></iframe>
<iframe style="border: none" sandbox="allow-scripts allow-same-origin allow-popups allow-presentation allow-popups-to-escape-sandbox" title="Play" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen src="https://cdpn.io/pen/debug/NWeVNRj?v={{orgy.data}}&autoplay=1&modestbranding=1{% if orgy.end_utc %}&start={{orgy.seconds_since_starts}}{% endif %}"></iframe>
{% elif orgy.type == 'rumble' %}
<iframe src="{{orgy.data}}" frameborder="0" allowfullscreen></iframe>
{% elif orgy.type == 'twitch' %}

View File

@ -15,6 +15,7 @@ greenlet
gunicorn
imagehash
inotify
isodate
lxml
mistletoe
matplotlib