Skip to content

Instantly share code, notes, and snippets.

@kowalcj0
kowalcj0 / .bashrc
Last active July 30, 2023 10:09
Extract all subtitles from a movie using ffprobe & ffmpeg
alias subs=subs
function subs() {
movie="${1}"
filename="${1%.*}"
mappings=`ffprobe -loglevel error -select_streams s -show_entries stream=index:stream_tags=language -of csv=p=0 "${movie}"`
OLDIFS=$IFS
IFS=,
( while read idx lang
do
@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 / 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 / install_MKVToolNix_and_handbrake.sh
Created July 2, 2017 16:08
Run HandBrake & MKVToolNix on a headless FreeBSD jail (FreeNas)
# 1 - Create a jail called `convert` using `pluginjail-10.3` template
# 2 - list all jails
jls
JID IP Address Hostname Path
1 - convert /mnt/volume/jails/convert
# 3 - connect to our jail
jexec 1 sh
@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 / convert_any_text_file_to_utf8_file_like_object.py
Last active November 27, 2021 12:31
Convert any text file into UTF-8 file like object
import chardet # https://pypi.python.org/pypi/chardet
def file_to_utf8(f_name):
"""Convert any file into UTF-8 file like object.
This conversion method is not perfect, because chardet doesn't detect the char set with 100% accuracy.
You'd have to base the decision to do the conversion on the confidence level (raging from 0 to 1) returned by the detect()
detect() returns a dictionary containing the auto-detected character encoding and a confidence level from 0 to 1.
"""
with open(f_name, 'rb') as f:
@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 / .asoundrc
Created June 30, 2017 10:29
Fiio E17 Alsa config file 24bit 94kHz ~/.asoundrc
# to get the name of the card do:
# cat /proc/asound/cards
# ...
# 2 [DACE17 ]: USB-Audio - FiiO USB DAC-E17
# FiiO FiiO USB DAC-E17 at usb-0000:00:14.0-1.4, full speed
# or
# aplay -l
# ...
# card 2: DACE17 [FiiO USB DAC-E17], device 0: USB Audio [USB Audio]
# Subdevices: 1/1
@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 {}'
}