시놀로지 Audio Station에서 파일명으로 보는 방법

image_pdfimage_print
  • audio station 은 앨범별, 디스크, 트랙, 곡명으로 정렬, 재생된다. 이 경우, 멜론 등의 순위에 따른 재생이 어려워 진다.
  • 앨범명, 곡명을 변경하여 순위별 재생을 위해 아래의 작업을 진행한다.
  • 앨범명은 저장된 디렉토리명으로, 디스크는 1번으로 통일, 트랙은 곡명 소팅 순서로 변경한다.
  • 사전 준비사항
    • 패키지 센터에서 Python3 추가
    • PIP 설치
    • mutagen 설치 : python3 -m pip install mutagen
  • python 파일 작성 및 저장
import os
import sys
from mutagen.mp3 import EasyMP3
from mutagen.id3 import ID3, ID3NoHeaderError
import datetime

now = datetime.datetime.now()
print(now)

def changeMP3TagsInDir(dir):
    basename = os.path.basename(dir)
    changedCount = 0
    index = 1
    lst = sorted(os.listdir(dir))
    for file in lst:
        fullpath = os.path.join(dir, file)
        if os.path.isdir(fullpath):
            if file.lower().endswith("eadir"):
                continue
            changeMP3TagsInDir(fullpath)
        else:
            if file.lower().endswith(".mp3"):
                try:
                    tags = EasyMP3(fullpath)
                except ID3NoHeaderError:
                    tags = mutagen.File(fullpath, easy=True)
                    tags.add_tags(ID3=EasyID3)
                except UnicodeDecodeError:
                    pass

                if "album" in tags:
                    album = tags["album"][0]
                else:
                    album = ""

                index += 1

                # print("album = ", album, ", basename = ", basename)
                if album == basename:
                    continue

                tags["tracknumber"] = str(index)
                tags["discnumber"] = '1'
                tags["album"] = basename
                try:
                    tags.save()
                    changedCount += 1
                except:
                    print("could not save file "+file)

    print("MP3 tags change. dir=", dir, ", count=", changedCount)
    if changedCount > 0:
        # 색인 재설정
        # os.system("synoindex -R type_music &")
        # os.system("synoindex -A "+path+" &")
        os.system("synoindex -A '"+dir+"' &")

    return

if __name__ == "__main__":
    path = None
    if len(sys.argv) >= 2 and os.path.exists(sys.argv[1]):
        path = sys.argv[1]
    if path is not None and os.path.exists(path):
        changeMP3TagsInDir(path)
    else:
        print("Error: The path is incorrect (%s)" % path)
  • python 파일 배치 실행 등록
    • 실행명령어
      • export LANG=en_US.utf8
      • export PYTHONIOENCODING=UTF-8
      • python3 {python파일절대경로} “음악파일루트”
    • 제어판 > 작업 스케줄러 > 생성

답글 남기기

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