all repos — FixYouTube-legacy @ f3d2077af5474ab76e6286695a0c6e8880073d57

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

polish
Marco Andronaco andronacomarco@gmail.com
Mon, 21 Aug 2023 23:03:50 +0200
commit

f3d2077af5474ab76e6286695a0c6e8880073d57

parent

8e6cea5cba756c2a1d1ca5cdea41395ea4b5acbc

2 files changed, 9 insertions(+), 5 deletions(-)

jump to
M fxyoutube/views.pyfxyoutube/views.py

@@ -42,8 +42,9 @@ def proxy(path):

result = get_video(path) try: url = result[0][8] + ext = result[0][5] except IndexError: return abort(400) result = get(url) - return Response(result.content, headers={ "Content-Type": "video/mp4" }) + return Response(result.content, headers={ "Content-Type": "video/" + ext })
M fxyoutube/yt_info.pyfxyoutube/yt_info.py

@@ -20,23 +20,26 @@ if format["filesize"] > c.MAX_SIZE_BYTES:

return None # too large except TypeError: if format["filesize_approx"] > c.MAX_SIZE_BYTES: - return None + return None # too large return format +def truncate_lines(input_str: str, max: int = 5): + return "\n".join(input_str.splitlines()[:5]) + def get_info_ytdl(yt_id: str): info = ydl.extract_info(c.BASE_URL + yt_id, download=False) formats = map(handle_format, info["formats"]) - formats = list(filter(lambda x: x is not None, formats)) + formats = filter(lambda x: x is not None, formats) try: max_format = max(formats, key=lambda x:x["quality"]) except ValueError: return None - + return { "id": info["id"], "title": info["title"], - "description": info["description"], + "description": truncate_lines(info["description"]), "uploader": info["uploader"], "uploader_id": info["uploader_id"], "video_ext": max_format["video_ext"],