yt-dlp-utils 0.0.2__tar.gz → 0.0.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of yt-dlp-utils might be problematic. Click here for more details.

@@ -1,15 +1,14 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: yt-dlp-utils
3
- Version: 0.0.2
3
+ Version: 0.0.4
4
4
  Summary: Utilities for programmatic use of yt-dlp.
5
5
  License: MIT
6
6
  Keywords: command line,yt-dlp
7
7
  Author: Andrew Udvare
8
8
  Author-email: audvare@gmail.com
9
9
  Requires-Python: >=3.10,<3.14
10
- Classifier: Development Status :: 2 - Pre-Alpha
10
+ Classifier: Development Status :: 4 - Beta
11
11
  Classifier: Intended Audience :: Developers
12
- Classifier: License :: OSI Approved :: MIT License
13
12
  Classifier: Programming Language :: Python
14
13
  Classifier: Programming Language :: Python :: 3.10
15
14
  Classifier: Programming Language :: Python :: 3.11
@@ -17,8 +16,8 @@ Classifier: Programming Language :: Python :: 3.12
17
16
  Classifier: Programming Language :: Python :: 3.13
18
17
  Classifier: Typing :: Typed
19
18
  Requires-Dist: requests (>=2.32.3,<3.0.0)
20
- Requires-Dist: typing-extensions (>=4.13.1,<5.0.0)
21
- Requires-Dist: yt-dlp[default] (>=2025.3.31,<2026.0.0)
19
+ Requires-Dist: typing-extensions (>=4.13.2,<5.0.0)
20
+ Requires-Dist: yt-dlp[default] (>=2025.5.22,<2026.0.0)
22
21
  Project-URL: Documentation, https://yt-dlp-utils.readthedocs.org
23
22
  Project-URL: Homepage, https://tatsh.github.io/yt-dlp-utils/
24
23
  Project-URL: Issues, https://github.com/Tatsh/yt-dlp-utils/issues
@@ -27,24 +26,25 @@ Description-Content-Type: text/markdown
27
26
 
28
27
  # yt-dlp-utils
29
28
 
29
+ [![Python versions](https://img.shields.io/pypi/pyversions/yt-dlp-utils.svg?color=blue&logo=python&logoColor=white)](https://www.python.org/)
30
+ [![PyPI - Version](https://img.shields.io/pypi/v/yt-dlp-utils)](https://pypi.org/project/yt-dlp-utils/)
31
+ [![GitHub tag (with filter)](https://img.shields.io/github/v/tag/Tatsh/yt-dlp-utils)](https://github.com/Tatsh/yt-dlp-utils/tags)
32
+ [![License](https://img.shields.io/github/license/Tatsh/yt-dlp-utils)](https://github.com/Tatsh/yt-dlp-utils/blob/master/LICENSE.txt)
33
+ [![GitHub commits since latest release (by SemVer including pre-releases)](https://img.shields.io/github/commits-since/Tatsh/yt-dlp-utils/v0.0.4/master)](https://github.com/Tatsh/yt-dlp-utils/compare/v0.0.4...master)
30
34
  [![QA](https://github.com/Tatsh/yt-dlp-utils/actions/workflows/qa.yml/badge.svg)](https://github.com/Tatsh/yt-dlp-utils/actions/workflows/qa.yml)
31
35
  [![Tests](https://github.com/Tatsh/yt-dlp-utils/actions/workflows/tests.yml/badge.svg)](https://github.com/Tatsh/yt-dlp-utils/actions/workflows/tests.yml)
32
36
  [![Coverage Status](https://coveralls.io/repos/github/Tatsh/yt-dlp-utils/badge.svg?branch=master)](https://coveralls.io/github/Tatsh/yt-dlp-utils?branch=master)
33
37
  [![Documentation Status](https://readthedocs.org/projects/yt-dlp-utils/badge/?version=latest)](https://yt-dlp-utils.readthedocs.org/?badge=latest)
34
- [![PyPI - Version](https://img.shields.io/pypi/v/yt-dlp-utils)](https://pypi.org/project/yt-dlp-utils/)
35
- [![GitHub tag (with filter)](https://img.shields.io/github/v/tag/Tatsh/yt-dlp-utils)](https://github.com/Tatsh/yt-dlp-utils/tags)
36
- [![License](https://img.shields.io/github/license/Tatsh/yt-dlp-utils)](https://github.com/Tatsh/yt-dlp-utils/blob/master/LICENSE.txt)
37
- [![GitHub commits since latest release (by SemVer including pre-releases)](https://img.shields.io/github/commits-since/Tatsh/yt-dlp-utils/v0.0.2/master)](https://github.com/Tatsh/yt-dlp-utils/compare/v0.0.2...master)
38
- ![License](https://img.shields.io/badge/License-MIT-success.svg)
39
38
  [![mypy](https://www.mypy-lang.org/static/mypy_badge.svg)](http://mypy-lang.org/)
40
39
  [![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white)](https://github.com/pre-commit/pre-commit)
41
40
  [![pydocstyle](https://img.shields.io/badge/pydocstyle-enabled-AD4CD3)](http://www.pydocstyle.org/en/stable/)
42
41
  [![pytest](https://img.shields.io/badge/pytest-zz?logo=Pytest&labelColor=black&color=black)](https://docs.pytest.org/en/stable/)
43
- [![Python](https://img.shields.io/badge/Python-3.12-3776AB.svg?style=flat&logo=python&logoColor=white)](https://www.python.org)
44
42
  [![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
43
+ [![Downloads](https://static.pepy.tech/badge/yt-dlp-utils/month)](https://pepy.tech/project/yt-dlp-utils)
44
+ [![Stargazers](https://img.shields.io/github/stars/Tatsh/yt-dlp-utils?logo=github&style=flat)](https://github.com/Tatsh/yt-dlp-utils/stargazers)
45
45
 
46
- [![@Tatsh](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fpublic.api.bsky.app%2Fxrpc%2Fapp.bsky.actor.getProfile%2F%3Factor%3Ddid%3Aplc%3Auq42idtvuccnmtl57nsucz72%26query%3D%24.followersCount%26style%3Dsocial%26logo%3Dbluesky%26label%3DFollow%2520%40Tatsh&query=%24.followersCount&style=social&logo=bluesky&label=Follow%20%40Tatsh)](https://bsky.app/profile/tatsh.bsky.social)
47
- [![Mastodon Follow](https://img.shields.io/mastodon/follow/109370961877277568?domain=hostux.social&style=social)](https://hostux.social/@tatsh)
46
+ [![@Tatsh](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fpublic.api.bsky.app%2Fxrpc%2Fapp.bsky.actor.getProfile%2F%3Factor%3Ddid%3Aplc%3Auq42idtvuccnmtl57nsucz72%26query%3D%24.followersCount%26style%3Dsocial%26logo%3Dbluesky%26label%3DFollow%2520%40Tatsh&query=%24.followersCount&style=social&logo=bluesky&label=Follow%20%40Tatsh)](https://bsky.app/profile/Tatsh.bsky.social)
47
+ [![Mastodon Follow](https://img.shields.io/mastodon/follow/109370961877277568?domain=hostux.social&style=social)](https://hostux.social/@Tatsh)
48
48
 
49
49
  Utilities for programmatic use of yt-dlp.
50
50
 
@@ -1,23 +1,24 @@
1
1
  # yt-dlp-utils
2
2
 
3
+ [![Python versions](https://img.shields.io/pypi/pyversions/yt-dlp-utils.svg?color=blue&logo=python&logoColor=white)](https://www.python.org/)
4
+ [![PyPI - Version](https://img.shields.io/pypi/v/yt-dlp-utils)](https://pypi.org/project/yt-dlp-utils/)
5
+ [![GitHub tag (with filter)](https://img.shields.io/github/v/tag/Tatsh/yt-dlp-utils)](https://github.com/Tatsh/yt-dlp-utils/tags)
6
+ [![License](https://img.shields.io/github/license/Tatsh/yt-dlp-utils)](https://github.com/Tatsh/yt-dlp-utils/blob/master/LICENSE.txt)
7
+ [![GitHub commits since latest release (by SemVer including pre-releases)](https://img.shields.io/github/commits-since/Tatsh/yt-dlp-utils/v0.0.4/master)](https://github.com/Tatsh/yt-dlp-utils/compare/v0.0.4...master)
3
8
  [![QA](https://github.com/Tatsh/yt-dlp-utils/actions/workflows/qa.yml/badge.svg)](https://github.com/Tatsh/yt-dlp-utils/actions/workflows/qa.yml)
4
9
  [![Tests](https://github.com/Tatsh/yt-dlp-utils/actions/workflows/tests.yml/badge.svg)](https://github.com/Tatsh/yt-dlp-utils/actions/workflows/tests.yml)
5
10
  [![Coverage Status](https://coveralls.io/repos/github/Tatsh/yt-dlp-utils/badge.svg?branch=master)](https://coveralls.io/github/Tatsh/yt-dlp-utils?branch=master)
6
11
  [![Documentation Status](https://readthedocs.org/projects/yt-dlp-utils/badge/?version=latest)](https://yt-dlp-utils.readthedocs.org/?badge=latest)
7
- [![PyPI - Version](https://img.shields.io/pypi/v/yt-dlp-utils)](https://pypi.org/project/yt-dlp-utils/)
8
- [![GitHub tag (with filter)](https://img.shields.io/github/v/tag/Tatsh/yt-dlp-utils)](https://github.com/Tatsh/yt-dlp-utils/tags)
9
- [![License](https://img.shields.io/github/license/Tatsh/yt-dlp-utils)](https://github.com/Tatsh/yt-dlp-utils/blob/master/LICENSE.txt)
10
- [![GitHub commits since latest release (by SemVer including pre-releases)](https://img.shields.io/github/commits-since/Tatsh/yt-dlp-utils/v0.0.2/master)](https://github.com/Tatsh/yt-dlp-utils/compare/v0.0.2...master)
11
- ![License](https://img.shields.io/badge/License-MIT-success.svg)
12
12
  [![mypy](https://www.mypy-lang.org/static/mypy_badge.svg)](http://mypy-lang.org/)
13
13
  [![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white)](https://github.com/pre-commit/pre-commit)
14
14
  [![pydocstyle](https://img.shields.io/badge/pydocstyle-enabled-AD4CD3)](http://www.pydocstyle.org/en/stable/)
15
15
  [![pytest](https://img.shields.io/badge/pytest-zz?logo=Pytest&labelColor=black&color=black)](https://docs.pytest.org/en/stable/)
16
- [![Python](https://img.shields.io/badge/Python-3.12-3776AB.svg?style=flat&logo=python&logoColor=white)](https://www.python.org)
17
16
  [![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
17
+ [![Downloads](https://static.pepy.tech/badge/yt-dlp-utils/month)](https://pepy.tech/project/yt-dlp-utils)
18
+ [![Stargazers](https://img.shields.io/github/stars/Tatsh/yt-dlp-utils?logo=github&style=flat)](https://github.com/Tatsh/yt-dlp-utils/stargazers)
18
19
 
19
- [![@Tatsh](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fpublic.api.bsky.app%2Fxrpc%2Fapp.bsky.actor.getProfile%2F%3Factor%3Ddid%3Aplc%3Auq42idtvuccnmtl57nsucz72%26query%3D%24.followersCount%26style%3Dsocial%26logo%3Dbluesky%26label%3DFollow%2520%40Tatsh&query=%24.followersCount&style=social&logo=bluesky&label=Follow%20%40Tatsh)](https://bsky.app/profile/tatsh.bsky.social)
20
- [![Mastodon Follow](https://img.shields.io/mastodon/follow/109370961877277568?domain=hostux.social&style=social)](https://hostux.social/@tatsh)
20
+ [![@Tatsh](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fpublic.api.bsky.app%2Fxrpc%2Fapp.bsky.actor.getProfile%2F%3Factor%3Ddid%3Aplc%3Auq42idtvuccnmtl57nsucz72%26query%3D%24.followersCount%26style%3Dsocial%26logo%3Dbluesky%26label%3DFollow%2520%40Tatsh&query=%24.followersCount&style=social&logo=bluesky&label=Follow%20%40Tatsh)](https://bsky.app/profile/Tatsh.bsky.social)
21
+ [![Mastodon Follow](https://img.shields.io/mastodon/follow/109370961877277568?domain=hostux.social&style=social)](https://hostux.social/@Tatsh)
21
22
 
22
23
  Utilities for programmatic use of yt-dlp.
23
24
 
@@ -4,9 +4,8 @@ requires = ["poetry-core"]
4
4
 
5
5
  [project]
6
6
  classifiers = [
7
- "Development Status :: 2 - Pre-Alpha",
7
+ "Development Status :: 4 - Beta",
8
8
  "Intended Audience :: Developers",
9
- "License :: OSI Approved :: MIT License",
10
9
  "Programming Language :: Python",
11
10
  "Programming Language :: Python :: 3.10",
12
11
  "Programming Language :: Python :: 3.11",
@@ -20,7 +19,7 @@ keywords = ["command line", "yt-dlp"]
20
19
  license = "MIT"
21
20
  name = "yt-dlp-utils"
22
21
  readme = "README.md"
23
- version = "0.0.2"
22
+ version = "0.0.4"
24
23
 
25
24
  [[project.authors]]
26
25
  email = "audvare@gmail.com"
@@ -34,21 +33,18 @@ documentation = "https://yt-dlp-utils.readthedocs.org"
34
33
  homepage = "https://tatsh.github.io/yt-dlp-utils/"
35
34
  repository = "https://github.com/Tatsh/yt-dlp-utils"
36
35
 
37
- [tool]
38
-
39
36
  [tool.commitizen]
40
37
  tag_format = "v$version"
41
38
  version_files = [
42
39
  ".wiswa.jsonnet",
43
40
  "CITATION.cff",
44
41
  "README.md",
42
+ "docs/index.rst",
45
43
  "package.json",
46
44
  "yt_dlp_utils/__init__.py",
47
45
  ]
48
46
  version_provider = "pep621"
49
47
 
50
- [tool.coverage]
51
-
52
48
  [tool.coverage.report]
53
49
  exclude_also = ["if TYPE_CHECKING:"]
54
50
  omit = ["conftest.py", "tests.py", "tests/test_*.py"]
@@ -79,27 +75,23 @@ strict = true
79
75
  strict_optional = true
80
76
  warn_unreachable = true
81
77
 
82
- [tool.poetry]
83
-
84
78
  [tool.poetry.dependencies]
85
79
  python = ">=3.10,<3.14"
86
80
  requests = "^2.32.3"
87
- typing-extensions = "^4.13.1"
81
+ typing-extensions = "^4.13.2"
88
82
 
89
83
  [tool.poetry.dependencies.yt-dlp]
90
84
  extras = ["default"]
91
- version = "^2025.3.31"
92
-
93
- [tool.poetry.group]
85
+ version = "^2025.5.22"
94
86
 
95
87
  [tool.poetry.group.dev]
96
88
  optional = true
97
89
 
98
90
  [tool.poetry.group.dev.dependencies]
99
- commitizen = "^4.5.0"
91
+ commitizen = "^4.8.2"
100
92
  djlint = "^1.36.4"
101
93
  mypy = ">=1.12,<1.16"
102
- ruff = "^0.11.7"
94
+ ruff = "^0.11.11"
103
95
  types-requests = "^2.32.0.20250328"
104
96
  yapf = "^0.43.0"
105
97
  yt-dlp-types = "^0"
@@ -114,19 +106,22 @@ docutils = "^0.21.2"
114
106
  esbonio = "^0.16.5"
115
107
  numpydoc = "^1.8.0"
116
108
  restructuredtext-lint = "^1.4.0"
117
- sphinx = "<8.2.0"
118
109
  sphinx-click = "^6.0.0"
119
110
  sphinx-datatables = "^0.2.1"
120
111
  sphinx-hoverxref = "^1.4.2"
121
- sphinx-immaterial = "^0.13.4"
112
+ sphinx-immaterial = "^0.13.5"
122
113
 
123
114
  [tool.poetry.group.docs.dependencies.enum-tools]
124
115
  extras = ["sphinx"]
125
- version = "^0.12.0"
116
+ version = "^0.13.0"
126
117
 
127
- [tool.poetry.group.docs.dependencies.erdantic]
128
- optional = true
129
- version = "<2.0"
118
+ [[tool.poetry.group.docs.dependencies.sphinx]]
119
+ python = ">=3.11"
120
+ version = "^8.2.0"
121
+
122
+ [[tool.poetry.group.docs.dependencies.sphinx]]
123
+ python = "<3.11"
124
+ version = "^7.2.5"
130
125
 
131
126
  [tool.poetry.group.tests]
132
127
  optional = true
@@ -135,7 +130,7 @@ optional = true
135
130
  mock = "^5.2.0"
136
131
  pytest = "^8.3.5"
137
132
  pytest-cov = "^6.1.1"
138
- pytest-mock = "^3.14.0"
133
+ pytest-mock = "^3.14.1"
139
134
 
140
135
  [tool.poetry.group.tests.dependencies.coveralls]
141
136
  python = "<3.13"
@@ -160,8 +155,6 @@ reportUnnecessaryTypeIgnoreComment = "none"
160
155
  typeCheckingMode = "off"
161
156
  useLibraryCodeForTypes = false
162
157
 
163
- [tool.pytest]
164
-
165
158
  [tool.pytest.ini_options]
166
159
  mock_use_standalone_module = true
167
160
  norecursedirs = ["node_modules"]
@@ -191,6 +184,7 @@ extend-select = [
191
184
  "CPY",
192
185
  "D",
193
186
  "DJ",
187
+ "DOC",
194
188
  "DTZ",
195
189
  "E",
196
190
  "EM",
@@ -198,6 +192,7 @@ extend-select = [
198
192
  "EXE",
199
193
  "F",
200
194
  "FA",
195
+ "FAST",
201
196
  "FBT",
202
197
  "FIX",
203
198
  "FLY",
@@ -229,11 +224,12 @@ extend-select = [
229
224
  "SLOT",
230
225
  "T10",
231
226
  "T20",
232
- "TCH",
227
+ "TC",
233
228
  "TD",
234
229
  "TID",
235
230
  "TRY",
236
231
  "UP",
232
+ "W",
237
233
  "YTT",
238
234
  ]
239
235
  ignore = [
@@ -245,17 +241,11 @@ ignore = [
245
241
  "C901",
246
242
  "COM812",
247
243
  "CPY001",
248
- "D100",
249
- "D101",
250
- "D102",
251
- "D103",
252
- "D104",
253
- "D105",
254
- "D106",
255
- "D107",
244
+ "D201",
256
245
  "D203",
257
246
  "D204",
258
247
  "D212",
248
+ "DOC201",
259
249
  "EM101",
260
250
  "N818",
261
251
  "PLR0912",
@@ -4,4 +4,4 @@ from __future__ import annotations
4
4
  from .lib import YoutubeDLLogger, get_configured_yt_dlp, setup_session
5
5
 
6
6
  __all__ = ('YoutubeDLLogger', 'get_configured_yt_dlp', 'setup_session')
7
- __version__ = '0.0.2'
7
+ __version__ = '0.0.4'
@@ -1,3 +1,4 @@
1
+ """Constants."""
1
2
  from __future__ import annotations
2
3
 
3
4
  __all__ = ('DEFAULT_RETRY_BACKOFF_FACTOR', 'DEFAULT_RETRY_STATUS_FORCELIST', 'SHARED_HEADERS',
@@ -1,12 +1,13 @@
1
1
  """Utilities."""
2
2
  from __future__ import annotations
3
3
 
4
- from typing import TYPE_CHECKING, Any
4
+ from typing import TYPE_CHECKING
5
5
  import logging
6
6
  import re
7
7
  import sys
8
8
 
9
9
  from requests.adapters import HTTPAdapter
10
+ from typing_extensions import Unpack
10
11
  from urllib3 import Retry
11
12
  from yt_dlp.cookies import extract_cookies_from_browser
12
13
  import requests
@@ -15,14 +16,14 @@ import yt_dlp
15
16
  from .constants import DEFAULT_RETRY_BACKOFF_FACTOR, DEFAULT_RETRY_STATUS_FORCELIST, SHARED_HEADERS
16
17
 
17
18
  if TYPE_CHECKING:
18
- from collections.abc import Collection, Mapping
19
+ from collections.abc import Collection, Iterable, Mapping
19
20
 
20
21
  __all__ = ('YoutubeDLLogger', 'get_configured_yt_dlp', 'setup_session')
21
22
 
22
23
  log = logging.getLogger(__name__)
23
24
 
24
25
 
25
- class YoutubeDLLogger:
26
+ class YoutubeDLLogger(yt_dlp.cookies.YDLLogger):
26
27
  """Logger for yt-dlp."""
27
28
  def debug(self, message: str) -> None:
28
29
  """Log a debug message."""
@@ -34,7 +35,11 @@ class YoutubeDLLogger:
34
35
  """Log an info message."""
35
36
  log.info('%s', re.sub(r'^\[info\]\s+', '', message))
36
37
 
37
- def warning(self, message: str) -> None:
38
+ def warning(
39
+ self,
40
+ message: str,
41
+ once: bool = False, # noqa: FBT001, FBT002
42
+ only_once: bool = False) -> None: # noqa: FBT001, FBT002
38
43
  """Log a warning message."""
39
44
  log.warning('%s', re.sub(r'^\[warn(?:ing)?\]\s+', '', message))
40
45
 
@@ -44,23 +49,24 @@ class YoutubeDLLogger:
44
49
 
45
50
 
46
51
  def get_configured_yt_dlp(sleep_time: int = 3,
47
- logger: Any = None,
48
52
  *,
49
- debug: bool = False) -> yt_dlp.YoutubeDL:
53
+ debug: bool = False,
54
+ **kwargs: Unpack[yt_dlp.YDLOpts]) -> yt_dlp.YoutubeDL:
50
55
  """
51
56
  Get a configured ``YoutubeDL`` instance.
52
57
 
53
58
  This function sets up a ``yt_dlp.YoutubeDL`` instance with the user's configuration (e.g.
54
- located at ``~/.config/yt-dlp/config``). It overrides the default logger, disables colours, and
55
- sets the sleep time between requests. It also sets the verbose flag based on the ``debug``
59
+ located at ``~/.config/yt-dlp/config``). It overrides the default logger (``logger`` option),
60
+ disables colours (``color`` option), and sets the sleep time between requests
61
+ (``sleep_interval_requests`` option). It also sets the ``verbose`` flag based on the ``debug``
56
62
  parameter.
57
63
 
64
+ All other keyword arguments are passed directly to the ``yt_dlp.YoutubeDL`` constructor.
65
+
58
66
  Parameters
59
67
  ----------
60
68
  sleep_time : int
61
69
  The time to sleep between requests, in seconds. Default is 3 seconds.
62
- logger : Any
63
- The logger to use. See :py:class:`YoutubeDLLogger` for details.
64
70
  debug : bool
65
71
  Whether to enable debug mode. Default is False.
66
72
 
@@ -73,20 +79,21 @@ def get_configured_yt_dlp(sleep_time: int = 3,
73
79
  sys.argv = [sys.argv[0]]
74
80
  ydl_opts = yt_dlp.parse_options()[-1]
75
81
  ydl_opts['color'] = {'stdout': 'never', 'stderr': 'never'}
76
- ydl_opts['logger'] = logger or YoutubeDLLogger()
82
+ ydl_opts['logger'] = kwargs.pop('logger', YoutubeDLLogger())
77
83
  ydl_opts['sleep_interval_requests'] = sleep_time
78
84
  ydl_opts['verbose'] = debug
79
85
  sys.argv = old_sys_argv
80
- return yt_dlp.YoutubeDL(ydl_opts)
86
+ return yt_dlp.YoutubeDL(ydl_opts | kwargs)
81
87
 
82
88
 
83
89
  def setup_session(browser: str,
84
90
  profile: str,
85
- headers: Mapping[str, str] | None = None,
86
91
  add_headers: Mapping[str, str] | None = None,
87
92
  backoff_factor: float = DEFAULT_RETRY_BACKOFF_FACTOR,
88
- status_forcelist: Collection[int] = DEFAULT_RETRY_STATUS_FORCELIST,
93
+ domains: Iterable[str] | None = None,
94
+ headers: Mapping[str, str] | None = None,
89
95
  session: requests.Session | None = None,
96
+ status_forcelist: Collection[int] = DEFAULT_RETRY_STATUS_FORCELIST,
90
97
  *,
91
98
  setup_retry: bool = False) -> requests.Session:
92
99
  """
@@ -98,12 +105,14 @@ def setup_session(browser: str,
98
105
  The browser to extract cookies from.
99
106
  profile : str
100
107
  The profile to extract cookies from.
101
- headers : Mapping[str, str]
102
- The headers to use for the requests session. If not specified, a default set will be used.
103
108
  add_headers : Mapping[str, str]
104
109
  Additional headers to add to the requests session.
105
110
  backoff_factor : float
106
111
  The backoff factor to use for the retry mechanism.
112
+ domains : Iterable[str]
113
+ Filter the cookies to only those that match the specified domains.
114
+ headers : Mapping[str, str]
115
+ The headers to use for the requests session. If not specified, a default set will be used.
107
116
  status_forcelist : Collection[int]
108
117
  The status codes to retry on.
109
118
  setup_retry : bool
@@ -117,10 +126,20 @@ def setup_session(browser: str,
117
126
  headers = headers or SHARED_HEADERS
118
127
  add_headers = add_headers or {}
119
128
  session = session or requests.Session()
129
+ session.headers.update(headers)
130
+ session.headers.update(add_headers)
120
131
  if setup_retry:
121
132
  session.mount(
122
133
  'https://',
123
134
  HTTPAdapter(max_retries=Retry(backoff_factor=backoff_factor,
124
135
  status_forcelist=status_forcelist)))
125
- session.headers.update(extract_cookies_from_browser(browser, profile))
136
+ extracted = extract_cookies_from_browser(browser, profile)
137
+ if not domains:
138
+ session.cookies.update(extracted)
139
+ else:
140
+ for domain in (d.lstrip('.') for d in domains):
141
+ for cookie in extracted.get_cookies_for_url(f'https://{domain}'):
142
+ if not isinstance(cookie.value, str):
143
+ continue
144
+ session.cookies.set(cookie.name, cookie.value, domain=domain)
126
145
  return session
File without changes