better filtering, add thumbnail
Marco Andronaco andronacomarco@gmail.com
Wed, 23 Aug 2023 14:52:52 +0200
3 files changed,
15 insertions(+),
17 deletions(-)
M
fxyoutube/constants.py
→
fxyoutube/constants.py
@@ -5,6 +5,7 @@
UA_REGEX = r"bot|facebook|embed|got|firefox\/92|firefox\/38|curl|wget|go-http|yahoo|generator|whatsapp|preview|link|proxy|vkshare|images|analyzer|index|crawl|spider|python|cfnetwork|node" BASE_URL = "https://www.youtube.com/watch?v=" REPO_URL = "https://github.com/BiRabittoh/FixYouTube" -TS_FORMAT = "%Y-%m-%d %H:%M:%S" PROXY_HEADERS = { "Content-Type": "video/mp4" } -YTDL_OPTS = { "format": f"best[ext=mp4][filesize<{ MAX_SIZE_MB }M][protocol^=http][protocol!*=dash]" } +YTDL_OPTS = { "format": f"best[ext=mp4][filesize<{ MAX_SIZE_MB }M][protocol^=http][protocol!*=dash] / (bv*+ba/b)" } +YTDL_KEYS = [ "id", "title", "description", "uploader", "duration", "height", "width", "url" ] +URL_KEY = YTDL_KEYS[-1]
M
fxyoutube/templates/base.html
→
fxyoutube/templates/base.html
@@ -15,10 +15,16 @@ <link rel="canonical" href="{{ base_url }}{{ info['id'] }}" />
<meta property="theme-color" content="0000FF" /> <meta property="twitter:card" content="player" /> <meta property="twitter:site" content="{{ info['uploader'] }}" /> - <meta property="twitter:creator" content="{{ info['uploader'] }} ({{ info['uploader_id'] }})" /> + <meta property="twitter:creator" content="{{ info['uploader'] }}" /> <meta property="twitter:title" content="{{ info['title'] }}" /> <meta http-equiv="refresh" content="0;url={{ base_url }}{{ info['id'] }}" /> - {% if info['url'] != "" %} + <meta property="og:url" content="{{ base_url }}{{ info['id'] }}" /> + <meta property="og:image" content="https://i.ytimg.com/vi_webp/{{ info['id'] }}/maxresdefault.webp" /> + <meta property="twitter:image" content="https://i.ytimg.com/vi_webp/{{ info['id'] }}/maxresdefault.webp" /> + <meta property="og:title" content="{{ info['title'] }}" /> + <meta property="og:description" content="{{ info['description'] }}" /> + <meta property="og:site_name" content="FixYouTube ({{ info['uploader'] }})" /> + {% if info['url'] %} <meta property="twitter:player:stream:content_type" content="video/mp4" /> <meta property="twitter:player:height" content="{{ info['height'] }}" /> <meta property="twitter:player:width" content="{{ info['width'] }}" />@@ -29,8 +35,4 @@ <meta property="og:video:width" content="{{ info['width'] }}" />
<meta property="og:video:duration" content="{{ info['duration'] }}"> <meta property="og:video:type" content="video/mp4" /> {% endif %} - <meta property="twitter:image" content="0" /> - <meta property="og:title" content="{{ info['title'] }}" /> - <meta property="og:description" content="{{ info['description'] }}" /> - <meta property="og:site_name" content="FixYouTube ({{ info['uploader'] }})" /> </head><body></body></html>
M
fxyoutube/yt_info.py
→
fxyoutube/yt_info.py
@@ -1,8 +1,6 @@
from yt_dlp import YoutubeDL, DownloadError import fxyoutube.constants as c -ydl_keys = ["id", "title", "description", "uploader", "duration", "height", "width", "url"] - def truncate_lines(input_str: str, max: int = 4): return "\n".join(input_str.splitlines()[:max])@@ -10,13 +8,10 @@ def get_info_ytdl(yt_id: str):
try: with YoutubeDL(c.YTDL_OPTS) as ydl: info = ydl.extract_info(c.BASE_URL + yt_id, download=False) - yt_info = { k: info[k] for k in ydl_keys } + yt_info = { k: info[k] for k in c.YTDL_KEYS[:-1] } + yt_info[c.URL_KEY] = info.get(c.URL_KEY, "") except DownloadError: - with YoutubeDL() as ydl: - info = ydl.extract_info(c.BASE_URL + yt_id, download=False) - yt_info = { k: info[k] for k in ydl_keys[:-3] } - yt_info["height"] = yt_info["width"] = 0 - yt_info["url"] = "" - + return None + yt_info["description"] = truncate_lines(yt_info["description"]) return yt_info