all: add missing docstrings to satisfy ruff linter
- ID
e79b606- date
2026-04-18 22:07:04+00:00- author
Alex Chan <alex@alexwlchan.net>- parent
b026e89- message
all: add missing docstrings to satisfy ruff linter- changed files
2 files, 31 additions, 13 deletions
Changed files
test_yt-dlp_alexwlchan.py (3421) → test_yt-dlp_alexwlchan.py (3383)
diff --git a/test_yt-dlp_alexwlchan.py b/test_yt-dlp_alexwlchan.py
index 4e717f9..7fbbfad 100644
--- a/test_yt-dlp_alexwlchan.py
+++ b/test_yt-dlp_alexwlchan.py
@@ -1,16 +1,16 @@
-import json
+"""
+Tests for yt-dlp_alexwlchan.
+"""
+
+import importlib
import os
-import subprocess
-from typing import Any
from pymediainfo import MediaInfo
+import pytest
+yt_dlp_alexwlchan = importlib.import_module("yt-dlp_alexwlchan")
-def download_video(url: str) -> Any:
- output = subprocess.check_output(["python3", "yt-dlp_alexwlchan.py", url])
- video_info = json.loads(output)
-
- return video_info
+download_video = yt_dlp_alexwlchan.download_video
def test_youtube_video() -> None:
@@ -40,12 +40,12 @@ def test_youtube_path_is_cleaned_up() -> None:
"""
video = download_video("https://www.youtube.com/shorts/eso8JB7q0a0")
assert (
- video["title"]
- == "3D Printing Everyday for 365 Days 176/365 #stem #3dprinting #3dprint #ideas #useful"
+ video["title"] == "3D Printing Everyday for 365 Days 176/365 "
+ "#stem #3dprinting #3dprint #ideas #useful"
)
assert (
- os.path.basename(video["video_path"])
- == "3D Printing Everyday for 365 Days 176-365 stem 3dprinting 3dprint ideas useful [eso8JB7q0a0].mp4"
+ os.path.basename(video["video_path"]) == "3D Printing Everyday for 365 Days "
+ "176-365 stem 3dprinting 3dprint ideas useful [eso8JB7q0a0].mp4"
)
yt-dlp_alexwlchan.py (8074) → yt-dlp_alexwlchan.py (8504)
diff --git a/yt-dlp_alexwlchan.py b/yt-dlp_alexwlchan.py
index 2da5aa3..cf5ba93 100755
--- a/yt-dlp_alexwlchan.py
+++ b/yt-dlp_alexwlchan.py
@@ -1,4 +1,8 @@
#!/usr/bin/env python3
+"""
+yt-dlp_alexwlchan is a personal wrapper around yt-dlp that downloads a video
+with my preferred settings.
+"""
from datetime import datetime, timezone
import json
@@ -106,6 +110,10 @@ def get_instagram_avatar(tmp_dir: Path, uploader_name: str) -> Path:
class UploaderInfo(TypedDict):
+ """
+ Information about a video's uploader.
+ """
+
id: str
name: str
url: str
@@ -113,6 +121,10 @@ class UploaderInfo(TypedDict):
class VideoInfo(TypedDict):
+ """
+ Information about a downloaded video.
+ """
+
id: str
url: str
title: str
@@ -156,6 +168,9 @@ def cleanup_paths(dir_path: Path) -> None:
def download_video(url: str) -> VideoInfo:
+ """
+ Download a video with yt-dlp and return metadata about the video.
+ """
# Download all the videos to a temp directory; this allows the caller
# to decide exactly where they want the video later.
tmp_dir = Path(tempfile.mkdtemp())
@@ -252,6 +267,9 @@ class PathEncoder(json.JSONEncoder):
"""
def default(self, o: Any) -> Any:
+ """
+ Encode paths as a string; everything else us the default encoder.
+ """
if isinstance(o, Path):
return str(o.absolute())
else:
@@ -260,7 +278,7 @@ class PathEncoder(json.JSONEncoder):
if __name__ == "__main__":
try:
- url = sys.argv[1]
+ url = normalise_url(sys.argv[1])
except IndexError:
sys.exit(f"Usage: {__file__} URL")