Skip to content

Instantly share code, notes, and snippets.

View csparker247's full-sized avatar

Seth P csparker247

View GitHub Profile
@csparker247
csparker247 / macos_color_tags.sh
Created July 26, 2023 15:06
Get list of a file/directory's macOS color tags
# macOS Color Tags
# A shell utility for printing the list of macOS color tags
# assigned to a file or directory.
# Written by: C. Seth Parker
# Usage:
# % source macos_color_tags.sh
# % macos_color_tags foo.txt
# % macos_color_tags bar/
@csparker247
csparker247 / dynamic_lru_cache.py
Created January 19, 2023 21:38
Dynamically sized lru_cached function
import functools
class Foo:
@functools.lru_cache
def get(self, z):
return z
def set_cache_size(self, s):
Foo.get = functools.lru_cache(maxsize=s)(Foo.get.__wrapped__)
@csparker247
csparker247 / grandchild_threads.py
Last active February 7, 2020 00:17
PySide2 Grandchild Threads
import sys
import shiboken2
from PySide2.QtCore import QObject, QThread, Signal, Qt
from PySide2.QtWidgets import QApplication, QPushButton
class Grandchild(QObject):
def __init__(self, parent=None):
super(Grandchild, self).__init__(parent)
@csparker247
csparker247 / audio2flacm4a.sh
Last active August 29, 2015 13:59
Dual output ffmpeg command
#!/bin/sh
#Run from root of a CD volume on OSX
album=$(basename "$PWD")
mkdir -p ~/Desktop/Music/FLAC/"${album}"
mkdir -p ~/Desktop/Music/M4A/"${album}"
for track in *.aiff; do
newname=$(basename "$track" .aiff)
@csparker247
csparker247 / Scale Within Limits
Last active August 29, 2015 13:56
ffmpeg - scale within limits
TARGET_WIDTH="1920"
TARGET_HEIGHT="1080"
TARGET_DAR="16/9"
ffmpeg -i "input.mov" -vf \
"scale=iw*sar:ih,
scale=
'w=if(lt(dar, $TARGET_DAR), trunc(oh*a/2)*2, min($TARGET_WIDTH,ceil(iw/2)*2)):
h=if(gte(dar, $TARGET_DAR), trunc(ow/a/2)*2, min($TARGET_HEIGHT,ceil(ih/2)*2))',
setsar=1" \
@csparker247
csparker247 / download-vids.sh
Created January 17, 2014 22:06
Downloads all webm and mp4 videos found in an html page. Needs better pattern matching...
#!/bin/sh
curl -# -o test.html "$1"
mkdir downloaded-vids
for line in $(cat test.html); do
url=$(echo $line | grep -e .*http.*webm.* -e .*http.*mp4.* | sed 's/src=\(.*\)/\1/' | tr -d \')
if [[ ! -z $url ]]; then
curl -# -o downloaded-vids/$(basename $url) $url
fi
@csparker247
csparker247 / ffmpeg-progress
Last active August 21, 2023 11:59
Outputs ffmpeg progress to console as percentage of work completed.
# Get video duration in frames
duration=$(ffmpeg -i [filename] 2>&1 | sed -n "s/.* Duration: \([^,]*\), start: .*/\1/p")
fps=$(ffmpeg -i [filename] 2>&1 | sed -n "s/.*, \(.*\) tbr.*/\1/p")
hours=$(echo $duration | cut -d":" -f1)
minutes=$(echo $duration | cut -d":" -f2)
seconds=$(echo $duration | cut -d":" -f3)
FRAMES=$(echo "($hours*3600+$minutes*60+$seconds)*$fps" | bc | cut -d"." -f1)
# Start ffmpeg, use awk to flush the buffer and remove carriage returns
ffmpeg -i [filename] [options] [outputfile] 2>&1 | awk '1;{fflush()}' RS='\r\n'>[errorlog] &