PLEX 미디어 서버를 이용하여, 음원 라이브러리를 운영중인데 가끔 MP3 인식 할 때 한글이 깨지는 경우가 있다.

이 경우, 메타 데이터의 한글 캐릭터 셋이 EUC-KR 일 수 있는데 이것을 UTF-8 로 수정해서 해결할 수 있다.

우분투 서버에서는 파이썬 라이브러리를 이용하여 일괄 처리를 하면 된다.

라이브러리 설치

sudo apt-get update
sudo apt-get install python3-pip
pip3 install mutagen

파이썬과 mutagen 을 설치했으면, 준비 완료다.

파이썬 스크립트 작성

import os
from mutagen.easyid3 import EasyID3
from mutagen.id3 import ID3, Encoding, ID3NoHeaderError

def fix_encoding(file_path):
    try:
        audio = EasyID3(file_path)
    except ID3NoHeaderError:
        audio = ID3(file_path)
    
    for key in audio.keys():
        if isinstance(audio[key], list):
            try:
                original_value = audio[key][0]
                decoded_value = original_value.encode('euc-kr').decode('utf-8')
                audio[key] = decoded_value
            except (UnicodeEncodeError, UnicodeDecodeError):
                pass
    
    audio.save(v2_version=3)

def process_directory(directory):
    for root, _, files in os.walk(directory):
        for file in files:
            if file.lower().endswith('.mp3'):
                file_path = os.path.join(root, file)
                print(f"Processing file: {file_path}")
                fix_encoding(file_path)

# 지정할 디렉토리 경로
directory_path = "/path/to/your/music/folder"
process_directory(directory_path)

directory_path 에는 적절하게 음원을 검색할 경로를 지정해준다.

위의 스크립트는 지정된 디렉토리와 그 하위 디렉토리에서 모든 .mp3 파일을 찾고 각 파일의 메타데이터를 점검하여 한글이 깨진 경우 이를 수정한 후 수정된 파일을 저장하는 역할을 한다.

사용방법

위의 스크립트를 파일로 저장하자. 예를 들어 fix_metadata.py로 저장했다면 터미널에서 다음 명령을 실행하여 스크립트를 실행하면 된다.

python3 fix_metadata.py

#MP3 #음원파일 #메타데이터 #python #파이썬

Author: 모요
댓글

댓글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다

*

©2024 MOYO Blog with DAON Consulting Co,LTD.

CONTACT US

We're not around right now. But you can send us an email and we'll get back to you, asap.

보내는 중입니다..

로그인하세요.

계정 내용을 잊으셨나요 ?