Skip to content

Instantly share code, notes, and snippets.

Avatar

glowinthedark glowinthedark

  • URLError: <urlopen error [Errno 8] nodename nor servname provided, or not known>
  • HTTPError: HTTP Error 403: Forbidden
View GitHub Profile
@glowinthedark
glowinthedark / mutagen-embed-mp3-uslt-subtitles.py
Created Jan 28, 2023
Embed lyrics into MP3 files using mutagen (USLT tag), optionally set other ID3 tags
View mutagen-embed-mp3-uslt-subtitles.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# mirorred from https://code.activestate.com/recipes/577138-embed-lyrics-into-mp3-files-using-mutagen-uslt-tag/
import os
import sys
import codecs
from mutagen.mp3 import MP3
from mutagen.id3 import ID3NoHeaderError
from mutagen.id3 import ID3, TIT2, TALB, TPE1, TPE2, COMM, USLT, TCOM, TCON, TDRC
@glowinthedark
glowinthedark / ffmpeg-embed-hard-srt-subtitles-resize-540p.sh
Last active Jan 2, 2023
FFMPEG: Embed hard srt subtitles into a video; ❗️❗️ffmpeg *MUST* be compiled with `--enable-libfreetype --enable-libfontconfig`
View ffmpeg-embed-hard-srt-subtitles-resize-540p.sh
#!/usr/bin/env bash
if [ "$#" -lt 2 ]; then
printf "Usage:\n $(basename $0) MyVideo.mp4 MySubtitles.srt\n"
else
ffmpeg -i "$1" -vf "subtitles=${2}, scale=540:-1" -acodec copy "${1%.mp4}-sub-540p.mp4"
fi
# FFMPEG custom build options
@glowinthedark
glowinthedark / macos-mount-ext4-partitions.sh
Created Dec 22, 2022
Mount Ext4/ext3/ext2 partitions on MacOS
View macos-mount-ext4-partitions.sh
#!/usr/bin/env bash
for device in $(diskutil list | awk '/Linux/ {print $NF}') ; do
read -p ">>> Found linux device: $device. Mount? y/n <<< " answer
if [[ "$answer" =~ [yY] ]]; then
mount_point="$HOME/mnt/$device"
mkdir -p $mount_point
@glowinthedark
glowinthedark / srt-convert-simplified-traditional-chinese.py
Created Dec 14, 2022
Convert SRT subtitles between Chinese simplified and traditional
View srt-convert-simplified-traditional-chinese.py
#!/usr/bin/env python3
import argparse
import sys
from pathlib import Path
import srt
from opencc import OpenCC
from pypinyin import pinyin
View fairseq_task_load_model.py
from fairseq.models.transformer import TransformerModel
zh2en = TransformerModel.from_pretrained(
'/path/to/checkpoints',
checkpoint_file='checkpoint_best.pt',
data_name_or_path='data-bin/wmt17_zh_en_full',
bpe='subword_nmt',
bpe_codes='data-bin/wmt17_zh_en_full/zh.code'
)
zh2en.translate('你好 世界')
@glowinthedark
glowinthedark / ffmpeg-mp4-extract-acc-audio-copy.sh
Last active Dec 6, 2022
Extract AAC streams from all MP4 files in current directory without recoding (fastest)
View ffmpeg-mp4-extract-acc-audio-copy.sh
find . -type f -iname "*.mp4" -exec sh -c 'ffmpeg -i "${0}" -acodec copy "${0%.*}.aac"' {} \;
View whisper-mock-en.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@glowinthedark
glowinthedark / media_duration_dir.py
Created Nov 20, 2022
Get total duration of media files in the current folder
View media_duration_dir.py
#!/usr/bin/env python3
import datetime
import subprocess
import sys
from pathlib import Path
# USAGE:
# Total duration of MP4 files (default)
# mp4_duration_sum.py
#
View how-to-find-forks-of-deleted-repo.md
@glowinthedark
glowinthedark / whisper-transcribe.bash
Created Nov 14, 2022 — forked from DaniruKun/whisper-transcribe.bash
Transcribe (and translate) any VOD (e.g. from Youtube) using Whisper from OpenAI and embed subtitles!
View whisper-transcribe.bash
#!/usr/bin/env bash
# Small shell script to more easily automatically download and transcribe live stream VODs.
# This uses YT-DLP, ffmpeg and the CPP version of Whisper: https://github.com/ggerganov/whisper.cpp
# Use `./transcribe-vod help` to print help info.
# MIT License
# Copyright (c) 2022 Daniils Petrovs