Add conditional check to setup bgutils token generation script.

TODO: Update tests
pull/222/head
erinhmclark 2025-03-18 14:54:57 +00:00
rodzic b83bfda187
commit c4e63ebd8c
4 zmienionych plików z 21 dodań i 23 usunięć

Wyświetl plik

@ -7,7 +7,7 @@ GEN_SCRIPT="$TARGET_DIR/build/generate_once.js"
# Ensure the server directory exists # Ensure the server directory exists
if [ ! -d "$TARGET_DIR" ]; then if [ ! -d "$TARGET_DIR" ]; then
echo "Error: PO Token provider server directory is missing! Please run update_pot_provider.sh first." echo "Error: PO Token provider server directory is missing! Please run scripts/update_pot_provider.sh first."
exit 1 exit 1
fi fi
@ -23,18 +23,19 @@ else
fi fi
# Check if build directory exists and if transpiling is needed # Check if build directory exists and if transpiling is needed
if [ ! -d "build" ] || [ "src" -nt "$GEN_SCRIPT" ]; then if [ ! -d "build" ]; then
echo "Build directory missing or outdated. Running transpilation..." echo "Build directory missing or outdated. Running transpilation..."
npx tsc npx tsc
else else
echo "Build directory is up to date. Skipping transpilation." echo "Build directory is up to date. Skipping transpilation."
fi fi
# Ensure the script exists after transpilation
if [ ! -f "$GEN_SCRIPT" ]; then ## Ensure the script exists after transpilation
echo "Error: PO Token script not found after attempting transpilation." #if [ ! -f "$GEN_SCRIPT" ]; then
exit 1 # echo "Error: PO Token script not found after attempting transpilation."
fi # exit 1
#fi
# Confirm success # Confirm success

Wyświetl plik

@ -74,9 +74,9 @@ If you are having issues with the extractor, you can review the version of `yt-d
"default": "inf", "default": "inf",
"help": "Use to limit the number of videos to download when a channel or long page is being extracted. 'inf' means no limit.", "help": "Use to limit the number of videos to download when a channel or long page is being extracted. 'inf' means no limit.",
}, },
"update_pots": { "pot_provider": {
"default": False, "default": "bgutils",
"help": "If set, will run the script to update the pot generation script.", "help": "The Proof of origin provider method.",
}, },
"extractor_args": { "extractor_args": {
"default": {}, "default": {},

Wyświetl plik

@ -71,23 +71,21 @@ class GenericExtractor(Extractor):
def setup_token_script(self): def setup_token_script(self):
"""Setup PO Token provider https://github.com/Brainicism/bgutil-ytdlp-pot-provider.""" """Setup PO Token provider https://github.com/Brainicism/bgutil-ytdlp-pot-provider."""
# Determine the default location for the transpiled PO token script. if self.pot_provider == "bgutils":
default_script = os.path.join(
# "scripts", "potoken_provider", "bgutil-server", "build", "generate_once.js" # Check if the PO token generation script exists, set it up if not.
"scripts", "potoken_provider", "bgutil-provider", "server", "build", "generate_once.js"
)
# Check if the PO token script exists. if not, trigger the script generation.
if not os.path.exists(default_script):
logger.info("PO Token script not found. Running setup...")
try: try:
subprocess.run(["bash", "scripts/potoken_provider/setup_pot_provider.sh"], check=True) subprocess.run(["bash", "scripts/potoken_provider/setup_pot_provider.sh"], check=True)
except subprocess.CalledProcessError as e: except subprocess.CalledProcessError as e:
logger.error(f"Failed to setup PO Token script: {e}") logger.error(f"Failed to setup PO Token script: {e}")
return return
# Use the PO Token script in yt-dlp to fetch tokens on demand. # Use the PO Token script in yt-dlp to fetch tokens on demand.
self.extractor_args.setdefault("youtube", {})["getpot_bgutil_script"] = default_script pot_script = os.path.join(
logger.info(f"Using PO Token script at: {default_script}") "scripts", "potoken_provider", "bgutil-provider", "build", "generate_once.js"
)
self.extractor_args.setdefault("youtube", {})["getpot_bgutil_script"] = pot_script
def suitable_extractors(self, url: str) -> Generator[str, None, None]: def suitable_extractors(self, url: str) -> Generator[str, None, None]:
""" """
@ -446,8 +444,6 @@ class GenericExtractor(Extractor):
"--write-subs" if self.subtitles else "--no-write-subs", "--write-subs" if self.subtitles else "--no-write-subs",
"--write-auto-subs" if self.subtitles else "--no-write-auto-subs", "--write-auto-subs" if self.subtitles else "--no-write-auto-subs",
"--live-from-start" if self.live_from_start else "--no-live-from-start", "--live-from-start" if self.live_from_start else "--no-live-from-start",
# TODO
"--verbose"
] ]
# proxy handling # proxy handling

Wyświetl plik

@ -29,6 +29,7 @@ class TestGenericExtractor(TestExtractorBase):
"proxy": None, "proxy": None,
"cookies_from_browser": False, "cookies_from_browser": False,
"cookie_file": None, "cookie_file": None,
"pot_provider": False,
} }
def test_load_dropin(self): def test_load_dropin(self):