Skip to content

Instantly share code, notes, and snippets.

View infojunkie's full-sized avatar
🎶

Karim Ratib infojunkie

🎶
View GitHub Profile
@infojunkie
infojunkie / discogs-tag.sh
Last active April 15, 2023 04:22
Discogs artists to flac metatag
#! /bin/bash
#
# Requirements: curl, jq, metaflac
#
# Assumes that the files are already sorted by track number.
#
curl -s https://api.discogs.com/releases/$1 --user-agent "discogs-tag/1.0" | jq -r '.tracklist[].artists | map(.name) | join(", ") | gsub(" \\(\\d+\\)"; "")' > artists
IFS=$'\n' artists=($(<artists)) i=0; for f in *.flac; do metaflac "$f" --remove-tag=ARTIST --set-tag="ARTIST=${artists[$i]}"; ((i=i+1)); done
@infojunkie
infojunkie / fetish.ts
Last active April 8, 2023 07:17
Thinnest wrapper around fetch() Web API to throw an error if not ok
/**
* Fetch wrapper to throw an error if the response is not ok.
* Why indeed? https://github.com/whatwg/fetch/issues/18
*/
export async function fetish(input: RequestInfo | URL, init?: RequestInit | undefined): Promise<Response> {
const response = await fetch(input, init);
if (!response.ok) throw new Error(response.statusText);
return response;
}
@infojunkie
infojunkie / chapters2cue.php
Created February 6, 2023 17:02
Convert ffprobe chapters to cuesheet
#!/usr/bin/env php
<?php
/**
* Convert ffprobe chapters to cuesheet.
*
* This is typically used in a video-to-audio transcoding job:
*
* - ffprobe -show_chapters -print_format json -loglevel -8 video.file > chapters.json
* - ffmpeg -i video.file audio.file
@infojunkie
infojunkie / .bash_aliases
Created January 11, 2023 20:32
git-update updates all repos and prunes the stale branches
alias git-update='find . -mindepth 1 -maxdepth 3 -type d -name ".git" -print -exec git -C {}/.. pull --recurse-submodule \; -exec git -C {}/.. remote prune origin \;'
@infojunkie
infojunkie / tar-diff.sh
Last active September 23, 2022 17:15
Create an archive out of the diff of two archives
#! /bin/bash
set -e
die () {
echo >&2 "$@"
exit 1
}
[ "$#" -eq 2 ] || die "Usage: $(basename -- "$0") /path/to/original.tar.gz /path/to/modified.tar.gz"
[ -f "$1" ] || die "File $1 does not exist"
[ -f "$2" ] || die "File $2 does not exist"
@infojunkie
infojunkie / wc-pdf.sh
Created December 14, 2021 22:52
Count words in a list of PDF files
#!/bin/bash
find "$@" -name '*.pdf' | while read f; do pdftotext "$f" - | wc -w; done | paste -sd+ | bc
@infojunkie
infojunkie / serverless.yml
Last active August 16, 2021 06:48
Upload Zoom files to AWS S3
service: labyrinth-service
provider:
name: aws
iamManagedPolicies:
- "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
iamRoleStatements:
- Effect: Allow
Action:
- lambda:InvokeFunction
@infojunkie
infojunkie / package.json
Last active December 4, 2020 01:20
Running specific tests using mocha from a package.json script
"scripts": {
"test": "mocha --grep /${TEST:-'.*'}/i",
},
@infojunkie
infojunkie / .block
Last active December 18, 2016 00:14
VexFlow test #1
license: gpl-3.0
height: 300
@infojunkie
infojunkie / youtube-album.md
Last active August 24, 2021 04:26
Convert audio track/album to YouTube video

youtube-album

A recipe to prepare audio file(s) for YouTube upload. Video will be a slideshow of images on repeat.

Requires: imagemagick ffmpeg

  1. Convert images to required size. Here I assume .png files and output to png/ folder. See http://www.imagemagick.org/Usage/crop/#extent