Skip to content

Instantly share code, notes, and snippets.

@kowalcj0
kowalcj0 / fixSrtTimeFormat.py
Last active November 5, 2022 11:59
Fix time format in SubRip srt subtitle files
#!/usr/bin/env python3
import re, sys
from pathlib import Path
def fix_srt_time_format(sub_file_name: str):
"""Fix time format in SubRip srt subtitle files.
This script will:
* replace `.` delimiter between seconds and miliseconds with expected `,`
* replace leading `0:` in timestamps with expected `00:`
@kowalcj0
kowalcj0 / fix_gopro_mp4_dates.py
Created June 12, 2022 22:41
Fix create & modify dates for quicktime tags in a mp4 file recorded with GoPRO Hero 5 using pyexifinfo & exiftool
#!/usr/bin/env python3
import glob
import subprocess
from datetime import date, datetime, time, timedelta
from typing import List
# pip install -U pyexifinfo
# https://github.com/guinslym/pyexifinfo
import pyexifinfo as exif
@kowalcj0
kowalcj0 / archive-org-generate-torrent-link.js
Last active January 24, 2022 10:55
Generate torrent links for all items listed on a collection page
@kowalcj0
kowalcj0 / .bashrc
Created November 27, 2021 12:25
Append video resolution and codec to file name [bash function]
function renamevideofiles(){
input_ext="mkv"
dry_mode=
local OPTIND o d
while getopts :d: name; do
case "${name}" in
d)
dry_mode=1
input_ext="${OPTARG}"
;;
@kowalcj0
kowalcj0 / install_endlessh.sh
Created December 15, 2020 23:55
Install endlessh
# get latest version
wget https://github.com/skeeto/endlessh/archive/master.zip
unzip master.zip
cd endlessh-master/
# compile
make
# install
sudo cp endlessh /usr/local/bin/
@kowalcj0
kowalcj0 / dlistmp3.sh
Created November 27, 2019 22:44
Download all songs from a YT playlist in parallel and convert to 192kbps mp3
function dlistmp3() {
youtube-dl -j --flat-playlist "${1}" |\
jq -r '.id' |\
sed 's_^_https://www.youtube.com/watch?v=_' |\
parallel -j4 'youtube-dl -f bestaudio --extract-audio --audio-format mp3 --audio-quality 192K --embed-thumbnail --add-metadata --no-post-overwrites --ignore-errors {}'
}
#!/usr/bin/env python3
import os
import shutil
def what_is_inside(types) -> str:
result = ""
if "mp3" in types and "flac" in types:
result = "both"
if "mp3" in types and not "flac" in types:
@kowalcj0
kowalcj0 / extract_music_urls.py
Created October 26, 2018 23:28
Extract links to music websites from Mastodon's outbox.json and download them with youtube-dl in parallel with covers and metadata
#! /usr/bin/python
"""Extract links to music websites from Mastodon's outbox.json
outbox.json contains all of your toots
"""
import json
from bs4 import BeautifulSoup as Soup
def extract_music_urls():
with open("outbox.json") as f:
@kowalcj0
kowalcj0 / stabilize.sh
Created September 8, 2018 22:40
Stabilise shaky video with ffmpeg and vid.stab
alias stabilize=stabilize
function stabilize() {
type ffmpeg >/dev/null 2>&1 || { echo >&2 "ffmpeg is required but it's not installed."; return 1; }
video="${1}"
filename="${1%.*}"
extension="${1##*.}"
output="${filename}-stabilized.${extension}"
# calculate transformation vectors
ffmpeg -nostdin -hide_banner -i "${video}" -vf vidstabdetect=stepsize=6:shakiness=8:accuracy=15:result=transform_vectors.trf -f null -
@kowalcj0
kowalcj0 / trim.sh
Created September 8, 2018 22:37
Trim videos losslessly with ffmpeg
alias trim=trim
function trim() {
if [ "$#" != "3" ]; then
echo "Please provide all 3 arguments: 'filename start duration'"
return 1
fi
video="${1}"
filename="${1%.*}"
extension="${1##*.}"