Add hyperlink to the venv; fix noplaylist
- ID
d479bbf- date
2023-11-12 01:03:30+00:00- author
Alex Chan <alex@alexwlchan.net>- parent
163b6a6- message
Add hyperlink to the venv; fix noplaylist- changed files
6 files, 86 additions, 65 deletions
Changed files
images/reborder (1146) → images/reborder (258)
diff --git a/images/reborder b/images/reborder
index eddd8a1..370e5d3 100755
--- a/images/reborder
+++ b/images/reborder
@@ -1,51 +1,9 @@
-#!/Users/alexwlchan/repos/scripts/.venv/bin/python3
-"""
-Adds a white border of consistent width around an image.
+#!/usr/bin/env bash
-I use it when I've taken a screenshot of something on a white background,
-and I want to tidy up the crop quickly.
-"""
+set -o errexit
+set -o nounset
-import argparse
-import itertools
-import os
-import sys
+# https://stackoverflow.com/q/59895/1558022
+SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
-from PIL import Image, ImageChops, ImageOps
-
-
-def parse_args():
- parser = argparse.ArgumentParser()
-
- parser.add_argument("PATH")
- parser.add_argument("BORDER_WIDTH", type=int)
- parser.add_argument("--in-place", action="store_true")
-
- return parser.parse_args()
-
-
-if __name__ == '__main__':
- args = parse_args()
-
- im = Image.open(args.PATH)
-
- bg = Image.new(im.mode, im.size, (255, 255, 255))
-
- diff = ImageChops.difference(im, bg)
- diff = ImageChops.add(diff, diff, 2.0, -100)
- bbox = diff.getbbox()
- if bbox:
- im = im.crop(bbox)
-
- im = ImageOps.expand(im, border=args.BORDER_WIDTH, fill='white')
-
- name, ext = os.path.splitext(args.PATH)
-
- if args.in_place:
- out_path = args.PATH
- else:
- out_path = f'{name}.reborder_{args.BORDER_WIDTH}{ext}'
-
- im.save(out_path)
-
- print(out_path)
+/Users/alexwlchan/repos/scripts/.venv/bin/python3 "$SCRIPT_DIR/reborder.py" "$@"
images/reborder.py (0) → images/reborder.py (1089)
diff --git a/images/reborder.py b/images/reborder.py
new file mode 100755
index 0000000..4be8920
--- /dev/null
+++ b/images/reborder.py
@@ -0,0 +1,49 @@
+#!/usr/bin/env python3
+"""
+Adds a white border of consistent width around an image.
+
+I use it when I've taken a screenshot of something on a white background,
+and I want to tidy up the crop quickly.
+"""
+
+import argparse
+import os
+
+from PIL import Image, ImageChops, ImageOps
+
+
+def parse_args():
+ parser = argparse.ArgumentParser()
+
+ parser.add_argument("PATH")
+ parser.add_argument("BORDER_WIDTH", type=int)
+ parser.add_argument("--in-place", action="store_true")
+
+ return parser.parse_args()
+
+
+if __name__ == "__main__":
+ args = parse_args()
+
+ im = Image.open(args.PATH)
+
+ bg = Image.new(im.mode, im.size, (255, 255, 255))
+
+ diff = ImageChops.difference(im, bg)
+ diff = ImageChops.add(diff, diff, 2.0, -100)
+ bbox = diff.getbbox()
+ if bbox:
+ im = im.crop(bbox)
+
+ im = ImageOps.expand(im, border=args.BORDER_WIDTH, fill="white")
+
+ name, ext = os.path.splitext(args.PATH)
+
+ if args.in_place:
+ out_path = args.PATH
+ else:
+ out_path = f"{name}.reborder_{args.BORDER_WIDTH}{ext}"
+
+ im.save(out_path)
+
+ print(out_path)
requirements.in (30) → requirements.in (40)
diff --git a/requirements.in b/requirements.in
index 77fc521..28a88e3 100644
--- a/requirements.in
+++ b/requirements.in
@@ -1,4 +1,5 @@
black
flake8
+hyperlink
Pillow
pip-tools
requirements.txt (826) → requirements.txt (903)
diff --git a/requirements.txt b/requirements.txt
index 1ee24ee..6be7194 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -14,6 +14,10 @@ click==8.1.7
# pip-tools
flake8==6.1.0
# via -r requirements.in
+hyperlink==21.0.0
+ # via -r requirements.in
+idna==3.4
+ # via hyperlink
mccabe==0.7.0
# via flake8
mypy-extensions==1.0.0
text/noplaylist (511) → text/noplaylist (260)
diff --git a/text/noplaylist b/text/noplaylist
index 1d79930..5b0c13d 100755
--- a/text/noplaylist
+++ b/text/noplaylist
@@ -1,20 +1,9 @@
-#!/usr/bin/env python3
-"""
-This script receives a YouTube URL on stdin, and removes the `list`
-query parameter.
+#!/usr/bin/env bash
-I use this in conjunction with `furl` and `youtube-dl`. Sometimes
-I want to download a single video from YouTube, but youtube-dl tries
-to download an entire playlist. This lets me grab just the first video.
-"""
+set -o errexit
+set -o nounset
-import sys
+# https://stackoverflow.com/q/59895/1558022
+SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
-import hyperlink
-
-
-if __name__ == '__main__':
- url = sys.stdin.read()
- url = hyperlink.URL.from_text(url)
- url = url.remove('list')
- sys.stdout.write(str(url))
+/Users/alexwlchan/repos/scripts/.venv/bin/python3 "$SCRIPT_DIR/noplaylist.py" "$@"
text/noplaylist.py (0) → text/noplaylist.py (511)
diff --git a/text/noplaylist.py b/text/noplaylist.py
new file mode 100755
index 0000000..2178d8d
--- /dev/null
+++ b/text/noplaylist.py
@@ -0,0 +1,20 @@
+#!/usr/bin/env python3
+"""
+This script receives a YouTube URL on stdin, and removes the `list`
+query parameter.
+
+I use this in conjunction with `furl` and `youtube-dl`. Sometimes
+I want to download a single video from YouTube, but youtube-dl tries
+to download an entire playlist. This lets me grab just the first video.
+"""
+
+import sys
+
+import hyperlink
+
+
+if __name__ == "__main__":
+ url = sys.stdin.read()
+ url = hyperlink.URL.from_text(url)
+ url = url.remove("list")
+ sys.stdout.write(str(url))