728x90
반응형
import eyed3
import os
def get_mp3_tags(file_path):
audio_file = eyed3.load(file_path) # MP3 파일 정보 로드
if audio_file is None:
return "Invalid file or unsupported format"
# 파일 정보 추출
title = audio_file.tag.title
artist = audio_file.tag.artist
album = audio_file.tag.album
genre = audio_file.tag.genre
year = audio_file.tag.getBestDate()
length = audio_file.info.time_secs
file_size = os.path.getsize(file_path) # 파일 용량 계산
# 정보 출력
return {
"Title": title,
"Artist": artist,
"Album": album,
"Genre": genre,
"Year": year.year if year else "Unknown",
"Length (seconds)": length,
"File Size (bytes)": file_size
}
# 예시 파일 경로
file_path = "E:/tmp/musicBank/최신/여행스케치-그녀석들과 여행.mp3"
# 태그 정보 출력
tags = get_mp3_tags(file_path)
for key, value in tags.items():
print(f"{key} : {value}")
폴더내 모든 mp3 파일 정보 읽어서 파일로 저장하기
import eyed3
import os
def get_mp3_tags(file_path):
audio_file = eyed3.load(file_path) # MP3 파일 정보 로드
if audio_file is None:
return "Invalid file or unsupported format"
audio_file.tag.encoding = 'utf-8'
# 파일 정보 추출
title = audio_file.tag.title
artist = audio_file.tag.artist
album = audio_file.tag.album
genre = audio_file.tag.genre
year = audio_file.tag.getBestDate()
length = audio_file.info.time_secs
file_size = os.path.getsize(file_path) # 파일 용량 계산
# 정보 출력
return {
"Title": title,
"Artist": artist,
"Album": album,
"Genre": genre,
"Year": year.year if year else "Unknown",
"Length (seconds)": length,
"File Size (bytes)": file_size
}
path = 'E:/tmp/musicBank/최신'
mp3_files = [f for f in os.listdir(path) if f.endswith('.mp3')]
f = open('mp3_info.csv','w', encoding='UTF-8')
for mp3 in mp3_files:
file_path = path + '/' + mp3
tags = get_mp3_tags(file_path) # 태그 정보 출력
# print(tags)
f.write(file_path + ',')
for i, value in enumerate(tags.values()):
if value == None:
value = ''
# if type(value) == float or type(value) == int or type(value) == Genre:
if type(value) != str:
value = str(value)
# print(f"{i} : {value}")
f.write(value)
if i < len(tags.values())-1:
f.write(',')
f.write('\n')
f.close()
728x90
반응형
'프로그램' 카테고리의 다른 글
[파이썬] 문제 : 분자식을 분해해서 원소질량 합계 구하기 (1) | 2023.12.17 |
---|---|
[파이썬] 문제 : 프로세스, 쓰레드 리스트 (0) | 2023.12.16 |
[파이썬] 문제 : text의 학색 점수 읽어서 합계 및 평균 계산 (0) | 2023.12.14 |
[파이썬] 문제 : 파일에서 특정 문자열이 있는 라인만 읽기 (0) | 2023.12.14 |
[파이썬] 문제 : TV 클래스 만들기 (0) | 2023.12.14 |
댓글