all repos — FixYouTube-legacy @ 094043cf7ddb5d4defea2dfb10e77d75f6a04df0

A better way to embed YouTube videos everywhere (inspired by FixTweet).

minor fixes
Marco Andronaco andronacomarco@gmail.com
Wed, 23 Aug 2023 11:35:10 +0200
commit

094043cf7ddb5d4defea2dfb10e77d75f6a04df0

parent

426c6dead1e6a32ff0ed779990527d5e08011927

3 files changed, 12 insertions(+), 19 deletions(-)

jump to
M docker-compose.yamldocker-compose.yaml

@@ -3,5 +3,6 @@ app:

build: . image: birabittoh/fxyoutube:latest container_name: fxyoutube + restart: unless-stopped ports: - 127.0.0.1:1111:80
M fxyoutube/db.pyfxyoutube/db.py

@@ -32,14 +32,13 @@ def get_video_from_cache(video):

result = get_video_db(video) try: temp = result[0] + timestamp = datetime.strptime(temp[8], c.TS_FORMAT) + delta = datetime.now() - timestamp + if delta > timedelta(minutes=c.YT_TTL_MINUTES): + raise IndexError except IndexError: return None - timestamp = datetime.strptime(temp[8], c.TS_FORMAT) - delta = datetime.now() - timestamp - - if delta > timedelta(minutes=c.YT_TTL_MINUTES): - raise IndexError - + return { "id": temp[0], "title": temp[1],
M fxyoutube/yt_info.pyfxyoutube/yt_info.py

@@ -38,24 +38,17 @@ "title": info["title"],

"description": truncate_lines(info["description"]), "uploader": info["uploader"], "duration": info["duration"], + "height": 0, + "width": 0, + "url": None } formats = map(handle_format, info["formats"]) formats = filter(lambda x: x is not None, formats) try: max_format = max(formats, key=lambda x:x["quality"]) + yt_info.update({ k: max_format[k] for k in ["height", "width", "url"] }) except ValueError: - yt_info.update({ - "height": 0, - "width": 0, - "url": None - }) + pass + finally: return yt_info - - yt_info.update({ - "height": max_format["height"], - "width": max_format["width"], - "url": max_format["url"], - }) - - return yt_info