yt-dlp-utils 0.0.2__py3-none-any.whl → 0.0.4__py3-none-any.whl

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.

yt_dlp_utils/__init__.py CHANGED
@@ -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'
yt_dlp_utils/constants.py CHANGED
@@ -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',
yt_dlp_utils/lib.py CHANGED
@@ -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
@@ -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
 
@@ -0,0 +1,8 @@
1
+ yt_dlp_utils/__init__.py,sha256=GP6qBU0cuggloj55QKWxpXDVSl4J-mJkXfcG8VTLiZA,250
2
+ yt_dlp_utils/constants.py,sha256=SNzzxIkyJRsVopyLQJtYGlZT_znvYbPFOg6klw5KDdI,746
3
+ yt_dlp_utils/lib.py,sha256=YXCBTVccmLk619Hs5ygkbFZtBDVcAIw7y75JNY1auC4,5283
4
+ yt_dlp_utils/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
+ yt_dlp_utils-0.0.4.dist-info/LICENSE.txt,sha256=1z3v176A2bAtCVZXlb8HZXUf3HpQIjW2GanQd8PaVK4,1087
6
+ yt_dlp_utils-0.0.4.dist-info/METADATA,sha256=7QFfocC5N76B11QL9skbkJQ-mdIvmLgA8goWskGm7q0,3967
7
+ yt_dlp_utils-0.0.4.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
8
+ yt_dlp_utils-0.0.4.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: poetry-core 2.1.2
2
+ Generator: poetry-core 2.1.3
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
@@ -1,8 +0,0 @@
1
- yt_dlp_utils/__init__.py,sha256=8c-6Rvh7SxqgiLTioeHhUh265Dax4XEx6BeV0Dqi-Sg,250
2
- yt_dlp_utils/constants.py,sha256=CXWDlIFPB_Aom_dfa9RwACX8i8DANivmlT0GQxnrYDg,729
3
- yt_dlp_utils/lib.py,sha256=YU2tX7M_71-Ev_OSOYxyVh7s_tca-Dahv-12I_T9nsY,4359
4
- yt_dlp_utils/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
- yt_dlp_utils-0.0.2.dist-info/LICENSE.txt,sha256=1z3v176A2bAtCVZXlb8HZXUf3HpQIjW2GanQd8PaVK4,1087
6
- yt_dlp_utils-0.0.2.dist-info/METADATA,sha256=JSqmG1S4Tmg30MKfQFuV6pX7IpeHM-5pl64kNRoWKgg,3823
7
- yt_dlp_utils-0.0.2.dist-info/WHEEL,sha256=fGIA9gx4Qxk2KDKeNJCbOEwSrmLtjWCwzBz351GyrPQ,88
8
- yt_dlp_utils-0.0.2.dist-info/RECORD,,