all repos — FixYouTube-legacy @ bc789d7b3a387f7bfb8a1507ccf16cc97453c70c

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

fixyoutube/constants.py (view raw)

 1from dotenv import load_dotenv
 2from os import getenv
 3from requests import get
 4load_dotenv()
 5
 6def new_instance():
 7    global INVIDIOUS_INSTANCE
 8    instances = get("https://api.invidious.io/instances.json?pretty=1&sort_by=api,type").json()
 9    INVIDIOUS_INSTANCE = instances[0][0]
10    return INVIDIOUS_INSTANCE
11
12MAX_SIZE_MB = getenv("MAX_SIZE_MB", "50")
13YT_TTL_MINUTES = int(getenv("YT_TTL_MINUTES", 60 * 6))
14DB_URL = getenv("DB_URL", "cache.db")
15INVIDIOUS_INSTANCE = getenv("INVIDIOUS_INSTANCE", new_instance())
16REPO_URL = getenv("REPO_URL", "https://github.com/BiRabittoh/FixYouTube")
17
18UA_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"
19BASE_URL = "https://www.youtube.com/watch?v="
20PROXY_HEADERS_REQUEST = { "Range": f"bytes=0-{MAX_SIZE_MB}000000" }
21PROXY_HEADERS_RESPONSE = { "Content-Type": "video/mp4" }
22INVIDIOUS_ENDPOINT = "https://{instance}/api/v1/videos/{video}?fields=videoId,title,description,author,lengthSeconds,size,formatStreams"
23
24# test stuff
25TELEGRAM_USER_AGENT = "TelegramBot (like TwitterBot)"
26GOOD_VIDEO_ID = "crF2AIDlo54"
27BAD_VIDEO_ID = GOOD_VIDEO_ID[:-1]