diff --git a/files/classes/orgy.py b/files/classes/orgy.py index 80bee5d2f..1ba4b5eae 100644 --- a/files/classes/orgy.py +++ b/files/classes/orgy.py @@ -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 diff --git a/files/routes/admin.py b/files/routes/admin.py index e745a788c..1e1d7b04d 100644 --- a/files/routes/admin.py +++ b/files/routes/admin.py @@ -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 diff --git a/files/templates/orgy.html b/files/templates/orgy.html index c0dff1f6d..1fe1efb25 100644 --- a/files/templates/orgy.html +++ b/files/templates/orgy.html @@ -17,7 +17,7 @@

{% if orgy.type == 'youtube' %} - + {% elif orgy.type == 'rumble' %} {% elif orgy.type == 'twitch' %} diff --git a/requirements.txt b/requirements.txt index df49441fb..a18e01e29 100644 --- a/requirements.txt +++ b/requirements.txt @@ -15,6 +15,7 @@ greenlet gunicorn imagehash inotify +isodate lxml mistletoe matplotlib