I have around 200 MP3 Audio files. Some of these MP3 Audio files already have statement/text/information (whatever you want to call it) under “Comments” section of the file. I want to write a Python code using eyed3 or/and tinytag libraries (I don’t mind using more libraries if required) to achieve two things –
- If the comment already exists then I want to keep the existing comment + I want to add my new comment to this.
- If the comment doesn’t exist then I just want to add my new comment to this.
To achieve this I wrote the below Python code but its not working! If there is no comment exists in the MP3 file then this code works to add new comment. But If there is already a comment exists then I’m facing two problems –
P1 – this code is UNABLE to add new comment (statement/text/information) to it. It simply keeps the OLD comment.
P2 – this code replace the existing comment with “<eyed3.id3.tag.CommentsAccessor object at 0x00000196D312CAF0>” or “<eyed3.id3.tag.CommentsAccessor object at 0x00000196D30D0D60>” or “<eyed3.id3.tag.CommentsAccessor object at 0x00000286DB3A4A90>”
So how do I solve this problem? It’s a very simple requirement which Python is unable to do.
My Python Code
import os
from pathlib import Path
import eyed3
from eyed3.id3 import Tag
from tinytag import TinyTag
tag = TinyTag.get('File PathMyAudioFile.mp3')
audiofile = eyed3.load("File PathMyAudioFile.mp3")
edited_valc = 'Title - ' + str(audiofile.tag.title)
edited_valc = edited_valc + ', Artist - ' + str(audiofile.tag.artist)
edited_valc = edited_valc + ', Album - ' + str(audiofile.tag.album)
edited_valc = edited_valc + ', "Genre" - ' + str(audiofile.tag.genre)
edited_valc = edited_valc + ', Publisher - ' + str(audiofile.tag.publisher)
edited_valc = edited_valc + ', Copyright - ' + str(audiofile.tag.copyright)
edited_valc = edited_valc + ', Encoded by - ' + str(audiofile.tag.encoded_by)
edited_valc = edited_valc + ', Date - ' + str(audiofile.tag.getBestDate())
edited_valc = edited_valc + ', Existing Comment - ' + str(audiofile.tag.comments)
audiofile.tag.comments.set(str(edited_valc)
audiofile.tag.save()
I also tried this option but this didn’t work either
import os
from pathlib import Path
import eyed3
from eyed3.id3 import Tag
from tinytag import TinyTag
tag = TinyTag.get('File PathMyAudioFile.mp3')
audiofile = eyed3.load("File PathMyAudioFile.mp3")
edited_valc = 'Title - ' + str(audiofile.tag.title)
edited_valc = edited_valc + ', Artist - ' + str(audiofile.tag.artist)
edited_valc = edited_valc + ', Album - ' + str(audiofile.tag.album)
edited_valc = edited_valc + ', "Genre" - ' + str(audiofile.tag.genre)
edited_valc = edited_valc + ', Publisher - ' + str(audiofile.tag.publisher)
edited_valc = edited_valc + ', Copyright - ' + str(audiofile.tag.copyright)
edited_valc = edited_valc + ', Encoded by - ' + str(audiofile.tag.encoded_by)
edited_valc = edited_valc + ', Date - ' + str(audiofile.tag.getBestDate())
edited_valc = edited_valc + ', Existing Comment - ' + str(audiofile.tag.comments)
audiofile.tag.clear() #Tried to clear the existing comment before adding a new comment which has old + new comment.
audiofile.tag.comments.set(str(edited_valc))
audiofile.tag.save()
Python eyed3 to EDIT AND/OR ADD Comments of MP3 audio file – NOT WORKING
I have around 200 MP3 Audio files. Some of these MP3 Audio files already have statement/text/information (whatever you want to call it) under “Comments” section of the file. I want to write a Python code using eyed3 or/and tinytag libraries (I don’t mind using more libraries if required) to achieve two things –
To achieve this I wrote the below Python code but its not working! If there is no comment exists in the MP3 file then this code works to add new comment. But If there is already a comment exists then I’m facing two problems –
P1 – this code is UNABLE to add new comment (statement/text/information) to it. It simply keeps the OLD comment.
P2 – this code replace the existing comment with “<eyed3.id3.tag.CommentsAccessor object at 0x00000196D312CAF0>” or “<eyed3.id3.tag.CommentsAccessor object at 0x00000196D30D0D60>” or “<eyed3.id3.tag.CommentsAccessor object at 0x00000286DB3A4A90>”
So how do I solve this problem? It’s a very simple requirement which Python is unable to do.
My Python Code
I also tried this option but this didn’t work either
Filed under: Kiến thức lập trình - @ 20:16
Thẻ: pythonaudiocommentsmp3eyed3
« AsyncImage inside Zoomable always filed at first time ⇐ More Pages ⇒ ADO query for test case- suite filtering »