1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
| import eyed3 from pydub import AudioSegment
def edit_mp3_tags(file_path, title, artist, album, year, genre, lyrics,image_file): audiofile = eyed3.load(file_path)
audiofile.tag.title = title audiofile.tag.artist = artist audiofile.tag.album = album audiofile.tag.release_date = year audiofile.tag.genre = genre
with open(image_file, "rb") as image: image_data = image.read()
audiofile.tag.images.set(3, image_data, "image/jpeg", u"Description")
audiofile.tag.save()
def adjust_audio_dB(audio, target_dB): adjustment = target_dB - audio.dBFS adjusted_audio = audio + adjustment return adjusted_audio
def main(): song_name = "song_name" file_path = "...\\音频\\" + song_name + ".mp3" image_file_path = "...\\图片\\" + song_name + ".jpg"
audio = AudioSegment.from_mp3(file_path)
target_dB = -16.7
adjusted_audio = adjust_audio_dB(audio, target_dB)
adjusted_audio.export(file_path, format="mp3")
title = song_name artist = "artist" album = "live" year = "2013" genre = "Pop" lyrics = "歌词"
edit_mp3_tags(file_path, title, artist, album, year, genre, lyrics, image_file_path)
if __name__ == "__main__": main()
|