Merge pull request #4 from alexwlchan/add-youtube-stuff
- ID
5f67edc- date
2025-11-29 07:36:03+00:00- author
Alex Chan <alex@alexwlchan.net>- parents
d12e051,6855b1a- message
Merge pull request #4 from alexwlchan/add-youtube-stuff Add a "clean YouTube URL" function and "urls" extra- changed files
Changed files
CHANGELOG.md (302) → CHANGELOG.md (454)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 53d933c..0be58e0 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,10 @@
# CHANGELOG
+## v3 - 2025-11-29
+
+Add the `clean_youtube_url()` function and `urls` extra.
+Rearrange the package structure slightly, to allow optional dependencies.
+
## v2 - 2025-11-28
Add the `is_av1_video()` function for [detecting AV1-encoded videos](https://alexwlchan.net/2025/detecting-av1-videos/).
README.md (1648) → README.md (1588)
diff --git a/README.md b/README.md
index bd785aa..995527e 100644
--- a/README.md
+++ b/README.md
@@ -30,8 +30,6 @@ I'm making this public because it's convenient for me, and you might find useful
## Usage
-All the functions are available in the `chives` namespace.
-
See the docstrings on individual functions for usage descriptions.
## Installation
dev_requirements.in (51) → dev_requirements.in (56)
diff --git a/dev_requirements.in b/dev_requirements.in
index 89cd3ee..fa9d349 100644
--- a/dev_requirements.in
+++ b/dev_requirements.in
@@ -1,4 +1,4 @@
--e file:.[media]
+-e file:.[media,urls]
build
mypy
dev_requirements.txt (1757) → dev_requirements.txt (1829)
diff --git a/dev_requirements.txt b/dev_requirements.txt
index d465a0c..ca4b757 100644
--- a/dev_requirements.txt
+++ b/dev_requirements.txt
@@ -12,10 +12,14 @@ coverage==7.12.0
# via pytest-cov
docutils==0.22.3
# via readme-renderer
+hyperlink==21.0.0
+ # via alexwlchan-chives
id==1.5.0
# via twine
idna==3.11
- # via requests
+ # via
+ # hyperlink
+ # requests
iniconfig==2.3.0
# via pytest
jaraco-classes==3.4.0
pyproject.toml (1257) → pyproject.toml (1278)
diff --git a/pyproject.toml b/pyproject.toml
index 6f6c945..fdee3b2 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -25,6 +25,7 @@ license = "MIT"
[project.optional-dependencies]
media = ["pymediainfo"]
+urls = ["hyperlink"]
[project.urls]
"Homepage" = "https://github.com/alexwlchan/chives"
src/chives/__init__.py (680) → src/chives/__init__.py (390)
diff --git a/src/chives/__init__.py b/src/chives/__init__.py
index a14509d..5d290d7 100644
--- a/src/chives/__init__.py
+++ b/src/chives/__init__.py
@@ -11,20 +11,4 @@ I share across multiple sites.
"""
-from .media import is_av1_video
-from .timestamps import (
- find_all_dates,
- date_matches_format,
- date_matches_any_format,
- reformat_date,
-)
-
-__version__ = "2"
-
-__all__ = [
- "date_matches_any_format",
- "date_matches_format",
- "find_all_dates",
- "is_av1_video",
- "reformat_date",
-]
+__version__ = "3"
src/chives/urls.py (0) → src/chives/urls.py (329)
diff --git a/src/chives/urls.py b/src/chives/urls.py
new file mode 100644
index 0000000..16642e8
--- /dev/null
+++ b/src/chives/urls.py
@@ -0,0 +1,17 @@
+"""Code for manipulating and tidying URLs."""
+
+import hyperlink
+
+
+def clean_youtube_url(url: str) -> str:
+ """
+ Remove any query parameters from a YouTube URL that I don't
+ want to include.
+ """
+ u = hyperlink.parse(url)
+
+ u = u.remove("list")
+ u = u.remove("index")
+ u = u.remove("t")
+
+ return str(u)
tests/test_media.py (439) → tests/test_media.py (445)
diff --git a/tests/test_media.py b/tests/test_media.py
index b624cf5..0dd7b7b 100644
--- a/tests/test_media.py
+++ b/tests/test_media.py
@@ -1,6 +1,6 @@
"""Tests for `chives.media`."""
-from chives import is_av1_video
+from chives.media import is_av1_video
def test_is_av1_video() -> None:
tests/test_timestamps.py (2020) → tests/test_timestamps.py (2031)
diff --git a/tests/test_timestamps.py b/tests/test_timestamps.py
index 8117acf..6b64184 100644
--- a/tests/test_timestamps.py
+++ b/tests/test_timestamps.py
@@ -4,7 +4,7 @@ import json
import pytest
-from chives import date_matches_any_format, find_all_dates, reformat_date
+from chives.timestamps import date_matches_any_format, find_all_dates, reformat_date
def test_find_all_dates() -> None:
tests/test_urls.py (0) → tests/test_urls.py (657)
diff --git a/tests/test_urls.py b/tests/test_urls.py
new file mode 100644
index 0000000..9ceed58
--- /dev/null
+++ b/tests/test_urls.py
@@ -0,0 +1,25 @@
+"""Tests for `chives.urls`."""
+
+import pytest
+
+from chives.urls import clean_youtube_url
+
+
+@pytest.mark.parametrize(
+ "url, cleaned_url",
+ [
+ (
+ "https://www.youtube.com/watch?v=2OHPPSew2nY&list=WL&index=6&t=193s",
+ "https://www.youtube.com/watch?v=2OHPPSew2nY",
+ ),
+ (
+ "https://www.youtube.com/watch?v=2OHPPSew2nY",
+ "https://www.youtube.com/watch?v=2OHPPSew2nY",
+ ),
+ ],
+)
+def test_clean_youtube_url(url: str, cleaned_url: str) -> None:
+ """
+ All the query parameters get stripped from YouTube URLs correctly.
+ """
+ assert clean_youtube_url(url) == cleaned_url