all repos — FixYouTube-legacy @ 5e703053115a838fbc8984de5e6c4cbffe526ba5

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
 4import logging
 5logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO)
 6logger = logging.getLogger(__name__)
 7load_dotenv()
 8
 9def new_instance():
10    global INVIDIOUS_INSTANCE
11    instances = get("https://api.invidious.io/instances.json?pretty=1&sort_by=api,type").json()
12    INVIDIOUS_INSTANCE = instances[0][0]
13    logger.info("Using new Invidious instance: " + INVIDIOUS_INSTANCE)
14
15MAX_SIZE_MB = getenv("MAX_SIZE_MB", "50")
16YT_TTL_MINUTES = int(getenv("YT_TTL_MINUTES", 60 * 6))
17DB_URL = getenv("DB_URL", "cache.db")
18INVIDIOUS_INSTANCE = getenv("INVIDIOUS_INSTANCE")
19if INVIDIOUS_INSTANCE is None:
20    new_instance()
21REPO_URL = getenv("REPO_URL", "https://github.com/BiRabittoh/FixYouTube")
22
23UA_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"
24BASE_URL = "https://www.youtube.com/watch?v="
25PROXY_HEADERS_REQUEST = { "Range": f"bytes=0-{MAX_SIZE_MB}000000" }
26PROXY_HEADERS_RESPONSE = { "Content-Type": "video/mp4" }
27INVIDIOUS_ENDPOINT = "https://{instance}/api/v1/videos/{video}?fields=videoId,title,description,author,lengthSeconds,size,formatStreams"
28
29# test stuff
30TELEGRAM_USER_AGENT = "TelegramBot (like TwitterBot)"
31GOOD_VIDEO_ID = "crF2AIDlo54"
32BAD_VIDEO_ID = GOOD_VIDEO_ID[:-1]