Skip to content

Instantly share code, notes, and snippets.

@Perlence
Last active Jun 17, 2016
Embed
What would you like to do?
Set USLT tag from stdin
import argparse
import sys
from mutagen.id3 import USLT
from mutagen.mp3 import MP3
def main():
parser = argparse.ArgumentParser()
parser.add_argument('MP3FILE')
parser.add_argument('--lang', default='rus')
parser.add_argument('--desc', default='')
parser.add_argument('--input-encoding', default='utf-8')
args = parser.parse_args()
# Read lyrics from stdin
text = sys.stdin.read().decode(args.input_encoding)
# In Python 3 it should be::
#
# text = sys.stdin.buffer.read().decode(args.input_encoding)
audio = MP3(args.MP3FILE)
if audio.tags is None:
audio.add_tags()
audio.tags.add(USLT(encoding=1, lang=args.lang, desc=args.desc, text=text))
audio.save(v2_version=3)
if __name__ == '__main__':
main()
@abakum

This comment has been minimized.

Copy link

@abakum abakum commented Jun 17, 2016

Thanks, it works well!
For msys2 I copy it to c:\msys32\mingw32\bin\uslt add first line #!C:/msys32/mingw32/bin/python.exe and run
uslt music.mp3 < lyrics.txt

@abakum

This comment has been minimized.

Copy link

@abakum abakum commented Jun 17, 2016

Thanks, it write now ID3v2.3 tag which windows can read.
For msys2 I:

  1. copy it to
    c:\msys64\mingw64\lib\python2.7\site-packages\mutagen\uslt.py
  2. create c:\msys64\mingw64\bin\uslt with

!/usr/bin/env bash

python -m mutagen.uslt "$@"
3) run from shell of msys2:
uslt music.mp3 < lyrics.txt
4) run from bat file:
c:\msys64\mingw64\bin\python -m mutagen.uslt music.mp3 < lyrics.txt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment