ytdl-sub/tests/e2e/conftest.py
Jesse Bannon f1a2187a17
[FEATURE] Add throttle_protection plugin (#799)
Provides options to make ytdl-sub look more 'human-like' to protect from throttling. For range-based values, a random number will be chosen within the range to avoid sleeps looking scripted.

Usage:
```
    throttle_protection:
      sleep_per_download_s:
        min: 2.2
        max: 10.8
      sleep_per_subscription_s:
        min: 9.0
        max: 14.1
      max_downloads_per_subscription:
        min: 10
        max: 36
      subscription_download_probability: 1.0
```
2023-11-05 08:23:12 -08:00

39 lines
906 B
Python

import shlex
import sys
import tempfile
from typing import List
from unittest.mock import patch
import pytest
from ytdl_sub.cli.entrypoint import main
from ytdl_sub.subscriptions.subscription import Subscription
from ytdl_sub.utils.file_handler import FileHandler
@pytest.fixture
def timestamps_file_path():
timestamps = [
"0:00 Intro\n",
"00:10 Part 1\n",
"0:20 Part 2\n",
"00:30 Part 3\n",
"0:00:40 Part 4\n",
"00:01:01 Part 5\n",
]
with tempfile.NamedTemporaryFile(
mode="w", encoding="utf-8", suffix=".txt", delete=False
) as tmp:
tmp.writelines(timestamps)
try:
yield tmp.name
finally:
FileHandler.delete(tmp.name)
def mock_run_from_cli(args: str) -> List[Subscription]:
args_list = ["ytdl-sub"] + shlex.split(args)
with patch.object(sys, "argv", args_list):
return main()